From 5bf1dca59b570a3ffead03860301abc5e14e41e0 Mon Sep 17 00:00:00 2001 From: asterix Date: Wed, 23 Mar 2011 15:07:32 +0000 Subject: [PATCH] First implementation of dac module. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4801 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/cfg/cfg_dac.h | 58 ++++++++++++++ bertos/cpu/cortex-m3/drv/dac_sam3.c | 75 +++++++++++++++++++ bertos/drv/dac.h | 70 +++++++++++++++++ .../examples/sam3x-ek_display/cfg/cfg_dac.h | 58 ++++++++++++++ 4 files changed, 261 insertions(+) create mode 100644 bertos/cfg/cfg_dac.h create mode 100644 bertos/cpu/cortex-m3/drv/dac_sam3.c create mode 100644 bertos/drv/dac.h create mode 100644 boards/sam3x-ek/examples/sam3x-ek_display/cfg/cfg_dac.h diff --git a/bertos/cfg/cfg_dac.h b/bertos/cfg/cfg_dac.h new file mode 100644 index 00000000..8eff7bc3 --- /dev/null +++ b/bertos/cfg/cfg_dac.h @@ -0,0 +1,58 @@ +/** + * \file + * + * + * \brief Configuration file for DAC module. + * + * + * \author Daniele Basile + */ + +#ifndef CFG_DAC_H +#define CFG_DAC_H + +/** + * Module logging level. + * + * $WIZ$ type = "enum" + * $WIZ$ value_list = "log_level" + */ +#define DAC_LOG_LEVEL LOG_LVL_WARN + +/** + * Module logging format. + * + * $WIZ$ type = "enum" + * $WIZ$ value_list = "log_format" + */ +#define DAC_LOG_FORMAT LOG_FMT_TERSE + +#endif /* CFG_DAC_H */ diff --git a/bertos/cpu/cortex-m3/drv/dac_sam3.c b/bertos/cpu/cortex-m3/drv/dac_sam3.c new file mode 100644 index 00000000..e4e7e9a9 --- /dev/null +++ b/bertos/cpu/cortex-m3/drv/dac_sam3.c @@ -0,0 +1,75 @@ +/** + * \file + * + * + * \brief DAC hardware-specific implementation + * + * \author Daniele Basile + */ + + +#include "cfg/cfg_dac.h" + +#include +#include + +// Define log settings for cfg/log.h. +#define LOG_LEVEL DAC_LOG_LEVEL +#define LOG_FORMAT DAC_LOG_FORMAT +#include + +#include +#include + +int dac_write(int ch, buf, len) +{ + return 0; +} + +void dac_init(void) +{ + /* Clock ADC peripheral */ + pmc_periphEnable(DACC_ID); + + DACC_CR |= BV(DACC_SWRST); + DACC_MR = 0; + + /* Refresh period */ + DACC_MR |= (16 << DACC_REFRESH_SHIFT) & DACC_REFRESH_MASK; + /* Select channel */ + DACC_MR |= (DACC_CH1 << DACC_USER_SEL_SHIFT) & DACC_USER_SEL_MASK; + /* Start up */ + DACC_MR |= (DACC_MR_STARTUP_0 << DACC_STARTUP_SHIFT) & DACC_STARTUP_MASK; + + kprintf("mr: %08lx\n", DACC_MR); + /* Register and enable irq for adc. */ + sysirq_setHandler(INT_DACC, dac); +} diff --git a/bertos/drv/dac.h b/bertos/drv/dac.h new file mode 100644 index 00000000..e745ec11 --- /dev/null +++ b/bertos/drv/dac.h @@ -0,0 +1,70 @@ +/** + * \file + * + * + * \defgroup dac Generic DAC driver + * \ingroup drivers + * \{ + * \brief Digital to Analog Converter driver (DAC). + * + * Configuration file: cfg_dac.h + * + * \author Daniele Basile + * + * $WIZ$ module_name = "dac" + * $WIZ$ module_configuration = "bertos/cfg/cfg_dac.h" + * $WIZ$ module_supports = "sam3x" + */ + + +#ifndef DRV_DAC_H +#define DRV_DAC_H + +#include +#include +#include + +int dac_write(int ch, void *buf, size_t len); + +INLINE int dac_putHalfWord(int ch, uint16_t sample) +{ + return dac_write(ch, &sample, sizeof(uint16_t)); +} + +INLINE int dac_putWord(int ch, uint32_t sample) +{ + return dac_write(ch, &sample, sizeof(uint32_t)); +} + +void dac_init(void); + +/** \} */ //defgroup dac +#endif /* DRV_DAC_H */ diff --git a/boards/sam3x-ek/examples/sam3x-ek_display/cfg/cfg_dac.h b/boards/sam3x-ek/examples/sam3x-ek_display/cfg/cfg_dac.h new file mode 100644 index 00000000..8eff7bc3 --- /dev/null +++ b/boards/sam3x-ek/examples/sam3x-ek_display/cfg/cfg_dac.h @@ -0,0 +1,58 @@ +/** + * \file + * + * + * \brief Configuration file for DAC module. + * + * + * \author Daniele Basile + */ + +#ifndef CFG_DAC_H +#define CFG_DAC_H + +/** + * Module logging level. + * + * $WIZ$ type = "enum" + * $WIZ$ value_list = "log_level" + */ +#define DAC_LOG_LEVEL LOG_LVL_WARN + +/** + * Module logging format. + * + * $WIZ$ type = "enum" + * $WIZ$ value_list = "log_format" + */ +#define DAC_LOG_FORMAT LOG_FMT_TERSE + +#endif /* CFG_DAC_H */ -- 2.25.1