From 7d2e3002667be4b097f907559535e705a24f875e Mon Sep 17 00:00:00 2001 From: r-studio Date: Tue, 15 Dec 2009 08:48:39 +0000 Subject: [PATCH] added D/A converdet interface and clean implementation --- tos/chips/m16c62p/dac/HplM16c62pDac.nc | 35 +++++++++++++++++++++ tos/chips/m16c62p/dac/HplM16c62pDacC.nc | 17 ++++++++++ tos/chips/m16c62p/dac/HplM16c62pDacP.nc | 41 +++++++++++++++++++++++++ tos/platforms/mulle/.platform | 1 + 4 files changed, 94 insertions(+) create mode 100755 tos/chips/m16c62p/dac/HplM16c62pDac.nc create mode 100755 tos/chips/m16c62p/dac/HplM16c62pDacC.nc create mode 100755 tos/chips/m16c62p/dac/HplM16c62pDacP.nc diff --git a/tos/chips/m16c62p/dac/HplM16c62pDac.nc b/tos/chips/m16c62p/dac/HplM16c62pDac.nc new file mode 100755 index 00000000..02a9e0ad --- /dev/null +++ b/tos/chips/m16c62p/dac/HplM16c62pDac.nc @@ -0,0 +1,35 @@ +/** + * HPL interface to the M16c62p D/A converers. + * + * @author Henrik Makitaavola + */ + +interface HplM16c62pDac { + /** + * Sets the D/A value. + * @param value The new D/A value + */ + async command void setValue(uint8_t value); + + /** + * Reads the current D/A value. + * @return D/A value + */ + async command uint8_t getValue(); + + /** + * Enables the D/A converter. + */ + async command void enable(); + + /** + * Disables the D/A converter. + */ + async command void disable(); + + /** + * Checks the state of the D/A converter. + * @return TRUE if the D/A converter is enabled. + */ + async command bool isEnabled(); +} diff --git a/tos/chips/m16c62p/dac/HplM16c62pDacC.nc b/tos/chips/m16c62p/dac/HplM16c62pDacC.nc new file mode 100755 index 00000000..31b39616 --- /dev/null +++ b/tos/chips/m16c62p/dac/HplM16c62pDacC.nc @@ -0,0 +1,17 @@ +/** + * HPL for the M16c62p D/A conversion susbsystem. + * + * @author Henrik Makitaavola + */ + +configuration HplM16c62pDacC { + provides interface HplM16c62pDac as Dac0; + provides interface HplM16c62pDac as Dac1; +} +implementation { + components new HplM16c62pDacP(&DA0, 0) as Dac0_, + new HplM16c62pDacP(&DA1, 1) as Dac1_; + + Dac0 = Dac0_; + Dac1 = Dac1_; +} diff --git a/tos/chips/m16c62p/dac/HplM16c62pDacP.nc b/tos/chips/m16c62p/dac/HplM16c62pDacP.nc new file mode 100755 index 00000000..c99b1104 --- /dev/null +++ b/tos/chips/m16c62p/dac/HplM16c62pDacP.nc @@ -0,0 +1,41 @@ +/** + * HPL for the M16c62p A/D conversion susbsystem. + * + * @author Fan Zhang + * + */ + +generic module HplM16c62pDacP(uint16_t da_addr, + uint8_t da_num) +{ + provides interface HplM16c62pDac; +} +implementation +{ +#define da (*TCAST(volatile uint8_t* ONE, da_addr)) + + async command void HplM16c62pDac.setValue(uint8_t value) + { + da = value; + } + + async command uint8_t HplM16c62pDac.getValue() + { + return da; + } + + async command void HplM16c62pDac.enable() + { + SET_BIT(DACON.BYTE, da_num); + } + + async command void HplM16c62pDac.disable() + { + CLR_BIT(DACON.BYTE, da_num); + } + + async command bool HplM16c62pDac.isEnabled() + { + return (READ_BIT(DACON.BYTE, da_num) ? true : false); + } +} diff --git a/tos/platforms/mulle/.platform b/tos/platforms/mulle/.platform index f8aba77e..b912ac0c 100755 --- a/tos/platforms/mulle/.platform +++ b/tos/platforms/mulle/.platform @@ -21,6 +21,7 @@ push( @includes, qw( %T/chips/m16c62p %T/chips/m16c62p/control %T/chips/m16c62p/adc + %T/chips/m16c62p/dac %T/chips/m16c62p/pins %T/chips/m16c62p/timer %T/chips/m16c62p/uart -- 2.39.2