From 107743ef422de7a4c926a20ff87eee1515eb1987 Mon Sep 17 00:00:00 2001 From: asterix Date: Tue, 20 May 2008 16:54:52 +0000 Subject: [PATCH] Add boilerplate for hw peripherals. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1312 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/hw/hw_buzzer.h | 22 +-- bertos/hw/hw_buzzerled.h | 47 ++++++ bertos/hw/hw_cpu.h | 56 +++++++ bertos/hw/hw_dataflash.c | 31 +++- bertos/hw/hw_dataflash.h | 25 ++++ bertos/hw/hw_dc_motor.h | 134 +++++++++++++++++ bertos/hw/hw_kbd.h | 20 +-- bertos/hw/hw_lcd.h | 77 +++++----- bertos/hw/hw_mcp41.c | 22 ++- bertos/hw/hw_mcp41.h | 25 ++-- bertos/hw/hw_ntc.h | 136 +++++++++++++++++ bertos/hw/hw_phase.c | 46 ++++++ bertos/hw/hw_phase.h | 63 ++++++++ bertos/hw/hw_sensor.h | 79 ++++++++++ bertos/hw/hw_ser.h | 47 ++++++ bertos/hw/hw_spi.h | 114 +++++++++++++++ bertos/hw/hw_stepper.h | 307 +++++++++++++++++++++++++++++++++++++++ bertos/hw/hw_thermo.h | 181 +++++++++++++++++++++++ bertos/hw/kbd_map.h | 12 +- bertos/hw/mcp41_map.h | 5 +- bertos/hw/ntc_map.h | 61 ++++++++ bertos/hw/phase_map.h | 58 ++++++++ bertos/hw/pwm_map.h | 54 +++++++ bertos/hw/thermo_map.h | 70 +++++++++ 24 files changed, 1577 insertions(+), 115 deletions(-) create mode 100644 bertos/hw/hw_buzzerled.h create mode 100644 bertos/hw/hw_cpu.h create mode 100644 bertos/hw/hw_dc_motor.h create mode 100644 bertos/hw/hw_ntc.h create mode 100644 bertos/hw/hw_phase.c create mode 100644 bertos/hw/hw_phase.h create mode 100644 bertos/hw/hw_sensor.h create mode 100644 bertos/hw/hw_ser.h create mode 100644 bertos/hw/hw_spi.h create mode 100644 bertos/hw/hw_stepper.h create mode 100644 bertos/hw/hw_thermo.h create mode 100644 bertos/hw/ntc_map.h create mode 100644 bertos/hw/phase_map.h create mode 100644 bertos/hw/pwm_map.h create mode 100644 bertos/hw/thermo_map.h diff --git a/bertos/hw/hw_buzzer.h b/bertos/hw/hw_buzzer.h index d4ec5f74..f6e790b8 100644 --- a/bertos/hw/hw_buzzer.h +++ b/bertos/hw/hw_buzzer.h @@ -38,23 +38,15 @@ * \author Francesco Sacchi */ -/*#* - *#* $Log$ - *#* Revision 1.2 2006/07/19 12:56:27 bernie - *#* Convert to new Doxygen style. - *#* - *#* Revision 1.1 2006/02/10 12:31:03 bernie - *#* Add templates for hw definitions. - *#* - *#*/ - #ifndef HW_BUZZER_H #define HW_BUZZER_H -#define BUZZER_BIT BV(1) -#define IS_BUZZER_ON 0 -#define BUZZER_HW_INIT do { } while (0) -#define BUZZER_ON do { } while (0) -#define BUZZER_OFF do { } while (0) +#warning TODO:This is example implemetantion, you must implement it! + +#define BUZZER_BIT 1 +#define IS_BUZZER_ON 0 +#define BUZZER_HW_INIT do { /* Implement me! */ } while (0) +#define BUZZER_ON do { /* Implement me! */ } while (0) +#define BUZZER_OFF do { /* Implement me! */ } while (0) #endif /* HW_BUZZER_H */ diff --git a/bertos/hw/hw_buzzerled.h b/bertos/hw/hw_buzzerled.h new file mode 100644 index 00000000..326a53db --- /dev/null +++ b/bertos/hw/hw_buzzerled.h @@ -0,0 +1,47 @@ +/** + * \file + * + * + * \brief Buzzerled hardware-specific definitions + * + * \version $Id$ + * + * \author Daniele Basile + */ + + +#ifndef HW_BUZZERLED_H +#define HW_BUZZERLED_H + +#warning TODO:This is example implemetantion, you must implement it! + + +#endif /* HW_BUZZERLED_H */ diff --git a/bertos/hw/hw_cpu.h b/bertos/hw/hw_cpu.h new file mode 100644 index 00000000..b2a63eeb --- /dev/null +++ b/bertos/hw/hw_cpu.h @@ -0,0 +1,56 @@ +/** + * \file + * + * + * \brief Hardware-specific definitions + * + * \version $Id$ + * + * \author Bernardo Innocenti + */ + +#ifndef HW_CPU_H +#define HW_CPU_H + +#warning TODO:This is example implemetantion, you must implement it! + +/// CPU Clock frequency +#define CLOCK_FREQ (10000000UL /* Implement me! */) + + +/* Timer IRQ strobe */ +//#if CONFIG_TIMER_STROBE +// #define TIMER_STROBE_ON /* Implement me! */ +// #define TIMER_STROBE_OFF /* Implement me! */ +// #define TIMER_STROBE_INIT /* Implement me! */ +//#endif /* CONFIG_TIMER_STROBE */ + +#endif /* HW_CPU_H */ diff --git a/bertos/hw/hw_dataflash.c b/bertos/hw/hw_dataflash.c index 739e5870..4d6f130e 100644 --- a/bertos/hw/hw_dataflash.c +++ b/bertos/hw/hw_dataflash.c @@ -1,6 +1,31 @@ /** * \file * @@ -17,8 +42,7 @@ #include #include -#include - +#warning TODO:This is example implemetantion, you must implement it! MOD_DEFINE(hw_dataflash); @@ -32,7 +56,6 @@ MOD_DEFINE(hw_dataflash); */ void dataflash_hw_init(void) { - #warning The data flash init pins function is not implemented! //Disable CS line (remove if not needed) dataflash_hw_setCS(false); @@ -58,7 +81,6 @@ void dataflash_hw_init(void) */ void dataflash_hw_setCS(bool enable) { - #warning The data flash setCS function is not implemented! if (enable) { /* @@ -86,7 +108,6 @@ void dataflash_hw_setCS(bool enable) */ void dataflash_hw_setReset(bool enable) { - #warning The data flash setReset function is not implemented! if (enable) { /* diff --git a/bertos/hw/hw_dataflash.h b/bertos/hw/hw_dataflash.h index a0c697a0..5254446b 100644 --- a/bertos/hw/hw_dataflash.h +++ b/bertos/hw/hw_dataflash.h @@ -1,6 +1,31 @@ /** * \file * diff --git a/bertos/hw/hw_dc_motor.h b/bertos/hw/hw_dc_motor.h new file mode 100644 index 00000000..77a6e245 --- /dev/null +++ b/bertos/hw/hw_dc_motor.h @@ -0,0 +1,134 @@ +/** + * \file + * + * + * \brief DC motor hardware-specific definitions + * + * \version $Id$ + * + * \author Daniele Basile + */ + +#ifndef HW_DC_MOTOR_H +#define HW_DC_MOTOR_H + +#warning TODO:This is example implemetantion, you must implement it! + +//DC motor 0 +#define DC_MOTOR0_EN_PIN /* Implement me! */ +#define DC_MOTOR0_DIR_PIN /* Implement me! */ +#define DC_MOTOR0_CLEAR /* Implement me! */ +#define DC_MOTOR0_SET /* Implement me! */ + +/* Add other motor here */ + + +#define DC_MOTOR_PIN_INIT_MACRO(port, index) \ + do { \ + /* put here code to init pins */ \ + } while (0) + + +#define DC_MOTOR_SET_ENABLE(index) do { /* Implement me! */ } while (0) +#define DC_MOTOR_SET_DISABLE(index) do { /* Implement me! */ } while (0) +#define DC_MOTOR_DIR_CW_MACRO(index) do { /* Implement me! */ } while (0) +#define DC_MOTOR_DIR_CCW_MACRO(index) do { /* Implement me! */ } while (0) + + +#define DC_MOTOR_ENABLE(index) \ + do { \ + switch (index) \ + { \ + case 0:\ + DC_MOTOR_SET_ENABLE(0); \ + break; \ + /* Add other motor here */ \ + } \ + } while(0) + +#define DC_MOTOR_DISABLE(index) \ + do { \ + switch (index) \ + { \ + case 0:\ + DC_MOTOR_SET_DISABLE(0); \ + break; \ + /* Add other motor here */ \ + } \ + } while(0) + + +#define DC_MOTOR_DIR_CW(index) \ + do { \ + switch (index) \ + { \ + case 0:\ + DC_MOTOR_DIR_CW_MACRO(0); \ + break; \ + /* Add other motor here */ \ + } \ + } while(0) + + #define DC_MOTOR_DIR_CCW(index) \ + do { \ + switch (index) \ + { \ + case 0:\ + DC_MOTOR_DIR_CCW_MACRO(0); \ + break; \ + /* Add other motor here */ \ + } \ + } while(0) + + + +#define DC_MOTOR_SET_DIR(index, dir) \ + do { \ + if (dir) \ + DC_MOTOR_DIR_CW(index); \ + else \ + DC_MOTOR_DIR_CCW(index); \ + } while (0) + +#define DC_MOTOR_INIT(index) \ + do { \ + switch (index) \ + { \ + case 0: \ + DC_MOTOR_PIN_INIT_MACRO(A, 0); \ + break; \ + case 1: \ + DC_MOTOR_PIN_INIT_MACRO(A, 1); \ + break; \ + } \ + } while (0) + +#endif /* HW_DC_MOTOR_H */ diff --git a/bertos/hw/hw_kbd.h b/bertos/hw/hw_kbd.h index 7e82cb05..af163843 100644 --- a/bertos/hw/hw_kbd.h +++ b/bertos/hw/hw_kbd.h @@ -39,32 +39,20 @@ * \author Stefano Fedrigo */ -/*#* - *#* $Log$ - *#* Revision 1.4 2006/07/19 12:56:27 bernie - *#* Convert to new Doxygen style. - *#* - *#* Revision 1.3 2006/03/22 09:51:27 bernie - *#* Wrap C++ stuff. - *#* - *#* Revision 1.2 2006/02/15 09:13:42 bernie - *#* Add keyboard emulator. - *#* - *#* Revision 1.1 2006/02/10 12:31:03 bernie - *#* Add templates for hw definitions. - *#* - *#*/ - #ifndef HW_KBD_H #define HW_KBD_H #include "kbd_map.h" + #include +#warning TODO:This is example implemetantion, you must implement it! + #define K_RPT_MASK (K_UP | K_DOWN | K_OK | K_CANCEL) #define KBD_HW_INIT \ do { \ + /* Put here code to init hw */ \ } while (0) EXTERN_C int emul_kbdReadCols(void); diff --git a/bertos/hw/hw_lcd.h b/bertos/hw/hw_lcd.h index b7cf5f89..87e00efb 100644 --- a/bertos/hw/hw_lcd.h +++ b/bertos/hw/hw_lcd.h @@ -31,58 +31,50 @@ * * --> * + * \brief LCD low-level hardware macros + * * \version $Id$ * * \author Bernardo Innocenti * \author Stefano Fedrigo * - * \brief LCD low-level hardware macros */ #ifndef HW_LCD_H #define HW_LCD_H #include -//#include + +#include /* BV() */ +#include #include #include #include -#include /* BV() */ -#include - -#include -#include -#include +#warning TODO: This is example implementation, you must implement it! /** * \name LCD I/O pins/ports * @{ */ -#define LCD_RS BV(PG3) -#define LCD_RW BV(PG0) -#define LCD_E BV(PG2) -#define LCD_DB0 BV(PA0) -#define LCD_DB1 BV(PA1) -#define LCD_DB2 BV(PA2) -#define LCD_DB3 BV(PA3) -#define LCD_DB4 BV(PA4) -#define LCD_DB5 BV(PA5) -#define LCD_DB6 BV(PA6) -#define LCD_DB7 BV(PA7) +#define LCD_RS /* Implement me! */ +#define LCD_RW /* Implement me! */ +#define LCD_E /* Implement me! */ +#define LCD_DB0 /* Implement me! */ +#define LCD_DB1 /* Implement me! */ +#define LCD_DB2 /* Implement me! */ +#define LCD_DB3 /* Implement me! */ +#define LCD_DB4 /* Implement me! */ +#define LCD_DB5 /* Implement me! */ +#define LCD_DB6 /* Implement me! */ +#define LCD_DB7 /* Implement me! */ /*@}*/ /** * \name DB high nibble (DB[4-7]) * @{ */ -#define LCD_PORT PORTG -#define LCD_DB_PORT PORTA -#define LCD_PIN PING -#define LCD_DB_PIN PINA -#define LCD_DDR DDRG -#define LCD_DB_DDR DDRA #if CONFIG_LCD_4BIT #define LCD_MASK (LCD_DB7 | LCD_DB6 | LCD_DB5 | LCD_DB4) @@ -97,29 +89,29 @@ * \name LCD bus control macros * @{ */ -#define LCD_CLR_RS (LCD_PORT &= ~LCD_RS) -#define LCD_SET_RS (LCD_PORT |= LCD_RS) -#define LCD_CLR_RD (LCD_PORT &= ~LCD_RW) -#define LCD_SET_RD (LCD_PORT |= LCD_RW) -#define LCD_CLR_E (LCD_PORT &= ~LCD_E) -#define LCD_SET_E (LCD_PORT |= LCD_E) +#define LCD_CLR_RS /* Implement me! */ +#define LCD_SET_RS /* Implement me! */ +#define LCD_CLR_RD /* Implement me! */ +#define LCD_SET_RD /* Implement me! */ +#define LCD_CLR_E /* Implement me! */ +#define LCD_SET_E /* Implement me! */ #if CONFIG_LCD_4BIT - #define LCD_WRITE_H(x) (LCD_DB_PORT = (LCD_DB_PORT & ~LCD_MASK) | (((x) >> (4 - LCD_SHIFT)) & LCD_MASK)) - #define LCD_WRITE_L(x) (LCD_DB_PORT = (LCD_DB_PORT & ~LCD_MASK) | (((x) << LCD_SHIFT) & LCD_MASK)) - #define LCD_READ_H ((LCD_DB_PIN & LCD_MASK) >> (4 - LCD_SHIFT)) - #define LCD_READ_L ((LCD_DB_PIN & LCD_MASK) >> LCD_SHIFT) + #define LCD_WRITE_H(x) /* Implement me! */ + #define LCD_WRITE_L(x) /* Implement me! */ + #define LCD_READ_H /* Implement me! */ + #define LCD_READ_L /* Implement me! */ #else - #define LCD_WRITE(x) (LCD_DB_PORT = (x)) - #define LCD_READ (LCD_DB_PIN) + #define LCD_WRITE(x) /* Implement me! */ + #define LCD_READ /* Implement me! */ #endif /*@}*/ /** Set data bus direction to output (write to display) */ -#define LCD_DB_OUT (LCD_DB_DDR |= LCD_MASK) +#define LCD_DB_OUT /* Implement me! */ /** Set data bus direction to input (read from display) */ -#define LCD_DB_IN (LCD_DB_DDR &= ~LCD_MASK) +#define LCD_DB_IN /* Implement me! */ /** Delay for write (Enable pulse width, 220ns) */ #define LCD_DELAY_WRITE \ @@ -146,8 +138,11 @@ INLINE void lcd_bus_init(void) cpuflags_t flags; IRQ_SAVE_DISABLE(flags); - LCD_PORT = (LCD_PORT & ~(LCD_E | LCD_RW)) | LCD_RS; - LCD_DDR |= LCD_RS | LCD_RW | LCD_E; + /* + * Here set bus pin! + * to init a lcd device. + * + */ /* * Data bus is in output state most of the time: diff --git a/bertos/hw/hw_mcp41.c b/bertos/hw/hw_mcp41.c index 88cd4ea0..35865439 100644 --- a/bertos/hw/hw_mcp41.c +++ b/bertos/hw/hw_mcp41.c @@ -29,27 +29,25 @@ * Copyright 2006 Develer S.r.l. (http://www.develer.com/) * --> * - * \version $Id$ - * * \brief MCP41 hardware-specific definitions * * \version $Id$ * \author Francesco Sacchi */ -#include +#include "hw_mcp41.h" #include #include -#include +#warning TODO: This is example implementation, you must implement it! +const uint16_t mcp41_ports[MCP41_CNT] = +{ + 0, /* add here mcp41 ports */ +}; +const uint8_t mcp41_pins [MCP41_CNT] = +{ + 0, /* add here mcp41 ports */ +}; -const uint16_t mcp41_ports[MCP41_CNT] = { - _SFR_IO_ADDR(PORTB), /** Led pot */ - _SFR_IO_ADDR(PORTB), /** Photometer pot */ - }; -const uint8_t mcp41_pins [MCP41_CNT] = { - BV(PB7), - BV(PB6), - }; diff --git a/bertos/hw/hw_mcp41.h b/bertos/hw/hw_mcp41.h index 8dd6297e..1289d60d 100644 --- a/bertos/hw/hw_mcp41.h +++ b/bertos/hw/hw_mcp41.h @@ -29,8 +29,6 @@ * Copyright 2005 Develer S.r.l. (http://www.develer.com/) * --> * - * \version $Id$ - * * \brief MCP41 hardware-specific definitions * * \version $Id$ @@ -40,32 +38,29 @@ #ifndef HW_MCP41_H #define HW_MCP41_H -#include +#include "mcp41_map.h" + #include -#include -#include -extern const uint16_t mcp41_ports[MCP41_CNT]; -extern const uint8_t mcp41_pins[MCP41_CNT]; -/** - * Set MCP41 port associated with \a dev to output. - */ +#warning TODO: This is example implementation, you must implement it! + + INLINE void SET_MCP41_DDR(Mcp41Dev dev) { - /* DDR port is 1 address before PORT */ - ATOMIC(_SFR_IO8(mcp41_ports[dev] - 1) |= mcp41_pins[dev]); + /* Implement me! */ + //Warning: this funtions is like avr target name, + //fix it to comply for all target. } INLINE void MCP41_ON(Mcp41Dev i) { - ATOMIC(_SFR_IO8(mcp41_ports[i]) &= ~mcp41_pins[i]); + /* Implement me! */ } INLINE void MCP41_OFF(Mcp41Dev i) { - ATOMIC(_SFR_IO8(mcp41_ports[i]) |= mcp41_pins[i]); + /* Implement me! */ } - #endif /* HW_MCP41_H */ diff --git a/bertos/hw/hw_ntc.h b/bertos/hw/hw_ntc.h new file mode 100644 index 00000000..ffab815d --- /dev/null +++ b/bertos/hw/hw_ntc.h @@ -0,0 +1,136 @@ +/** + * \file + * + * + * \brief NTC hardware-specific definition + * + * \version $Id$ + * \author Francesco Sacchi + * + * A NTC acts as a variable resistor, whose resistance changes as a + * function of the temperature it measures. To sample it correctly, it is + * usually parallelized and serialized with two fixed resistor. The following diagram shows + * what is the exact disposition of the components, as handled by this + * library: + * + *
+ *                 o Vref
+ *                 |
+ *                 |                               o Vref
+ *                 |                               |
+ *               -----                             |
+ *              |     |                        ---------
+ *              | Rser|                       |         |
+ *              |     |                       |         |
+ *               -----     -----              |   ADC   |
+ *                 | Vp   |     |             |         |
+ *      -----------|------| Amp |-------------|         |
+ *     |           |      |     |      Vadc   |         |
+ *   -----       -----     -----               ---------
+ *  |     |     |     |
+ *  | NTC |     | Rpar|
+ *  |     |     |     |
+ *   -----       -----
+ *     |           |
+ *     |           |
+ *   -----       -----
+ *    ---         ---
+ *
+ * Amp is an amplifier that amplify of AMP times the signal. + * If we indicate Rp as the parallel of NTC with Rpar, ADCBITS as the bits of the ad converter + * and ADCVAL as the result from the adc convertion (Not Vadc but just the value read + * from the adc register), after various calculation, the expression of Rp is: + * + *
+ *
+ *            ADCVAL * Rser
+ * Rp = ------------------------
+ *         ADCBITS
+ *	2         * AMP - ADCVAL
+ *
+ * + * And after that NTC obvisiously is: + *
+ *        Rpar * Rp
+ * NTC = ----------
+ *        Rpar - Rp
+ *
+ * + * + * The function ntc_hw_read() compute the resistence using these formulas above. + */ + +#ifndef HW_NTC_H +#define HW_NTC_H + +#include "ntc_map.h" + +#include + +#include +#include + +#warning TODO:This is example implemetantion, you must implement it! + +extern const res_t NTC_RSER[NTC_CNT]; +extern const res_t NTC_RPAR[NTC_CNT]; +extern const amp_t NTC_AMP[NTC_CNT]; +extern const NtcHwInfo* NTC_INFO[NTC_CNT]; + + +/*! + * Read the resistence of ntc device \a dev. + * Return the result in res_t type. + */ +INLINE res_t ntc_hw_read(NtcDev dev) +{ + ASSERT(dev < NTC_CNT); + // See above for formula explanation. + adcread_t adcval = adc_read((uint16_t)dev); + float rp = (adcval * NTC_RSER[dev] ) / ((1 << adc_bits()) * NTC_AMP[dev] - adcval); + + //kprintf("Rp[%f], Rntc[%f]\n", rp/100, ((NTC_RPAR[dev] * rp) / (NTC_RPAR[dev] - rp)) / 100.0); + + return ( (NTC_RPAR[dev] * rp) / (NTC_RPAR[dev] - rp) ); +} + + +/*! + * Return the info (aka the table) associated with ntc device \a dev. + */ +INLINE const NtcHwInfo* ntc_hw_getInfo(NtcDev dev) +{ + return NTC_INFO[dev]; +} + +#define NTC_HW_INIT do { /* Implement me! */ } while(0) + +#endif /* HW_NTC_H */ diff --git a/bertos/hw/hw_phase.c b/bertos/hw/hw_phase.c new file mode 100644 index 00000000..887c96ff --- /dev/null +++ b/bertos/hw/hw_phase.c @@ -0,0 +1,46 @@ +/** + * \file + * + * + * \brief Phase control hardware-specific definitions + * + * \version $Id$ + * \author Francesco Sacchi + */ + +#ifndef HW_PHASE_H +#define HW_PHASE_H + +#include "hw_phase.h" + +#warning TODO:This is example implemetantion, you must implement it! + +#endif /* HW_PHASE_H */ diff --git a/bertos/hw/hw_phase.h b/bertos/hw/hw_phase.h new file mode 100644 index 00000000..2577dc88 --- /dev/null +++ b/bertos/hw/hw_phase.h @@ -0,0 +1,63 @@ +/** + * \file + * + * + * \brief Phase control hardware-specific definitions + * + * \version $Id$ + * + * \author Francesco Sacchi + */ + +#ifndef HW_PHASE_H +#define HW_PHASE_H + +#include "phase_map.h" + +#include + +#warning TODO:This is example implemetantion, you must implement it! + +#define PHASE_HW_INIT do { /* Implement me! */ }while (0) + +INLINE void TRIAC_OFF(TriacDev i) +{ + /* Implement me! */ +} + + +INLINE void TRIAC_ON(TriacDev i) +{ + /* Implement me! */ +} + + +#endif /* HW_PHASE_H */ diff --git a/bertos/hw/hw_sensor.h b/bertos/hw/hw_sensor.h new file mode 100644 index 00000000..1342f754 --- /dev/null +++ b/bertos/hw/hw_sensor.h @@ -0,0 +1,79 @@ +/** + * \file + * + * + * \brief Sensor hardware-specific definitions + * + * \version $Id$ + * + * \author Daniele Basile + */ + +#ifndef HW_SENSOR_H +#define HW_SENSOR_H + +#warning TODO:This is example implemetantion, you must implement it! + +#define NUM_HOME_SENSORS 1 + + +INLINE bool hw_home_sensor_read(int sensor) +{ + /* Implement me! */ + + return 0; +} + +INLINE void hw_home_sensor_set_inverted(int sensor, bool inverted) +{ + /* Implement me! */ +} + +INLINE bool hw_level_sensor_read(int sensor) +{ + /* Implement me! */ + + return 0; +} + +INLINE void hw_level_sensor_set_inverted(int sensor, bool inverted) +{ + /* Implement me! */ +} + +INLINE bool bld_hw_sensor_read(int sensor) +{ + /* Implement me! */ + + return 0; +} + +#endif /* HW_SENSOR_H */ diff --git a/bertos/hw/hw_ser.h b/bertos/hw/hw_ser.h new file mode 100644 index 00000000..62df8718 --- /dev/null +++ b/bertos/hw/hw_ser.h @@ -0,0 +1,47 @@ +/** + * \file + * + * + * \brief Serial hardware-specific definitions + * + * \version $Id$ + * + * \author Daniele Basile + */ + + +#ifndef HW_SER_H +#define HW_SER_H + +#warning TODO:This is example implemetantion, you must implement it! + + +#endif /* HW_SER_H */ diff --git a/bertos/hw/hw_spi.h b/bertos/hw/hw_spi.h new file mode 100644 index 00000000..8963ef29 --- /dev/null +++ b/bertos/hw/hw_spi.h @@ -0,0 +1,114 @@ +/** + * \file + * + * + * \brief Hardware macro definition. + * + * + * \version $Id$ + * \author Daniele Basile + */ + +#ifndef HW_SPI_H +#define HW_SPI_H + +#warning TODO:This is an example implentation, you must implement it! + +#include + +/** + * SPI pin definition. + * + * \note CS is assert when level + * is low. + * + * \{ + */ +#define CS /* pin */ ///Connect to CS pin of Flash memory. +#define SCK /* pin */ ///Connect to SCK pin of Flash memory. +#define MOSI /* pin */ ///Connect to SI pin of Flash memory. +#define MISO /* pin */ ///Connect to SO pin of Flash memory. +#define SPI_PORT /* pin */ ///Micro pin PORT register. +#define SPI_PIN /* pin */ ///Micro pin PIN register. +#define SPI_DDR /* pin */ ///Micro pin DDR register. +/*\}*/ + +/** + * Pin logic level. + * + * \{ + */ +#define MOSI_LOW() do { /* Implement me! */ } while(0) +#define MOSI_HIGH() do { /* Implement me! */ } while(0) +#define MISO_HIGH() do { /* Implement me! */ } while(0) +#define SCK_LOW() do { /* Implement me! */ } while(0) +#define SCK_HIGH() do { /* Implement me! */ } while(0) +#define CS_LOW() do { /* Implement me! */ } while(0) +#define CS_HIGH() do { /* Implement me! */ } while(0) +/*\}*/ + +/** + * SPI pin commands. + * + * \{ + */ +#define CS_ENABLE() CS_LOW() +#define CS_DISABLE() CS_HIGH() +#define SS_ACTIVE() CS_LOW() +#define SS_INACTIVE() CS_HIGH() +#define SCK_INACTIVE() SCK_LOW() +#define SCK_ACTIVE() SCK_HIGH() +#define CS_OUT() do { /* Implement me! */ } while(0) +#define MOSI_IN() do { /* Implement me! */ } while(0) +#define MOSI_OUT() do { /* Implement me! */ } while(0) +#define IS_MISO_HIGH() (false /* Implement me! */ ) +#define MISO_IN() do { /* Implement me! */ } while(0) +#define MISO_OUT() do { /* Implement me! */ } while(0) +#define SCK_OUT() do { /* Implement me! */ } while(0) + +#define SCK_PULSE()\ + do {\ + SCK_HIGH();\ + SCK_LOW();\ + } while (0) +/*\}*/ + + +#define SPI_HW_INIT() \ + CS_DISABLE();\ + MOSI_LOW();\ + SCK_LOW();\ + MISO_IN();\ + MOSI_OUT();\ + SCK_OUT();\ + CS_OUT(); + +#endif /* HW_SPI_H */ + diff --git a/bertos/hw/hw_stepper.h b/bertos/hw/hw_stepper.h new file mode 100644 index 00000000..77038cd8 --- /dev/null +++ b/bertos/hw/hw_stepper.h @@ -0,0 +1,307 @@ +/** + * \file + * + * + * \brief Stepper hardware-specific definitions + * + * \version $Id$ + * + * \author Daniele Basile + */ + + +#ifndef HW_STEPPER_H +#define HW_STEPPER_H + +#include "hw_cpu.h" + +#include + +#include + +#warning TODO:This is an example implentation, you must implement it! + +#define STEPPER_STROBE_INIT \ +do { \ + /* put init code for strobe */ \ +} while (0) + + +#define STEPPER_STROBE_ON do { /* Implement me! */ } while(0) +#define STEPPER_STROBE_OFF do { /* Implement me! */ } while(0) + +/** + * CPU clock frequency is divided by 2^STEPPER_PRESCALER_LOG2 to + * obtain stepper clock. + */ +#define STEPPER_PRESCALER_LOG2 1 + +/** + * Stepper timer clock frequency. + */ +#define STEPPER_CLOCK ((CLOCK_FREQ) >> STEPPER_PRESCALER_LOG2) + +/** + * us delay to reset a stepper motor. + * This is the time neccessary to reset + * the stepper controll chip. (see datasheet for more detail). + */ +#define STEPPER_RESET_DELAY 1 + +/* + * Pins define for each stepper + */ +#define STEPPER_1_CW_CCW_PIN 0 +#define STEPPER_1_HALF_FULL_PIN 0 +#define STEPPER_1_CONTROL_PIN 0 +#define STEPPER_1_ENABLE_PIN 0 +#define STEPPER_1_RESET_PIN 0 + +/* put here other stepper motor */ + +#define STEPPER_1_SET do { /* Implement me! */ } while(0) +/* add here the set for other stepper motor */ + +#define STEPPER_1_CLEAR do { /* Implement me! */ } while(0) +/* add here the clear for other stepper motor */ + +/* + * Generic macro definition + */ + +/* + * Stepper init macro + */ +#define STEPPER_PIN_INIT_MACRO(port, index) do { \ + /* Add here init pin code */ \ + } while (0) + +/* + * Stepper commands macros + */ +#define STEPPER_SET_CW(index) do { /* Implement me! */ } while (0) +#define STEPPER_SET_CCW(index) do { /* Implement me! */ } while (0) +#define STEPPER_SET_HALF(index) do { /* Implement me! */ } while (0) +#define STEPPER_SET_FULL(index) do { /* Implement me! */ } while (0) +#define STEPPER_SET_CONTROL_LOW(index) do { /* Implement me! */ } while (0) +#define STEPPER_SET_CONTROL_HIGHT(index) do { /* Implement me! */ } while (0) +#define STEPPER_SET_ENABLE(index) do { /* Implement me! */ } while (0) +#define STEPPER_SET_DISABLE(index) do { /* Implement me! */ } while (0) +#define STEPPER_SET_RESET_ENABLE(index) do { /* Implement me! */ } while (0) +#define STEPPER_SET_RESET_DISABLE(index) do { /* Implement me! */ } while (0) + + +/* + * Reset stepper macro + */ + +#define STEPPER_RESET_MACRO(index) do { \ + STEPPER_SET_RESET_ENABLE(index); \ + timer_udelay(STEPPER_RESET_DELAY); \ + STEPPER_SET_RESET_DISABLE(index); \ + } while (0) + +/* + * Set half or full step macro + */ +#define STEPPER_SET_STEP_MODE_MACRO(index, flag) do { \ + if (flag) \ + STEPPER_SET_HALF(index); \ + else \ + STEPPER_SET_FULL(index); \ + } while (0) + +/* + * Set control status macro + */ +#warning This macro is not implemented (see below) + +#define STEPPER_SET_CONTROL_BIT_MACRO(index, flag) do { \ + /* if (flag) */ \ + /* WARNING This macros not implemented */ \ + /* else */ \ + /* WARNING This macros not implemented */ \ + } while (0) + +/* + * Set current power macro + */ +#warning This macro is not implemented (see below) + +#define STEPPER_SET_POWER_CURRENT_MACRO(index, flag) do { \ + /* if (flag) */ \ + /* WARNING This macrois not implemented */ \ + /* else */ \ + /* WARNING This macrois not implemented */ \ + } while (0) + +/* + * Set rotation of stepper motor + * - dir = 1: positive rotation + * - dir = 0: no motor moviment + * - dir = -1: negative rotation + * + */ +#define STEPPER_SET_DIRECTION_MACRO(index, dir) do { \ + switch (dir) \ + { \ + case 1: \ + STEPPER_SET_CW(index); \ + break; \ + case -1: \ + STEPPER_SET_CCW(index); \ + break; \ + case 0: \ + break; \ + } \ + } while (0) + + +/* + * Define macros for manage low level of stepper. + */ + +#define STEPPER_INIT() do { \ + STEPPER_PIN_INIT_MACRO(A, 1); \ + /* Add here code for other stepper motor */ \ + } while (0) + + +/* + * Enable select stepper motor + */ +#define STEPPER_ENABLE(index) do { \ + switch (index) \ + { \ + case 1: \ + STEPPER_SET_ENABLE(1); \ + break; \ + /* Add here code for other stepper motor */ \ + } \ + } while (0) + +/* + * Enable all stepper connect to micro + */ +#define STEPPER_ENABLE_ALL() do { \ + STEPPER_SET_ENABLE(1); \ + /* Add here code for other stepper motor */ \ + } while (0) + +/* + * Disable select stepper motor + */ +#define STEPPER_DISABLE(index) do { \ + switch (index) \ + { \ + case 1: \ + STEPPER_SET_DISABLE(1); \ + break; \ + /* Add here code for other stepper motor */ \ + } \ + } while (0) + +/* + * Disable all stepper connect to micro + */ +#define STEPPER_DISABLE_ALL() do { \ + STEPPER_SET_DISABLE(1); \ + /* Add here code for other stepper motor */ \ + } while (0) + +/* + * Reset selected stepper motor + */ +#define STEPPER_RESET(index) do { \ + switch (index) \ + { \ + case 1: \ + STEPPER_RESET_MACRO(1); \ + break; \ + /* Add here code for other stepper motor */ \ + } \ + } while (0) + +/* + * Reset all stepper motor + */ +#define STEPPER_RESET_ALL() do { \ + STEPPER_RESET_MACRO(1) \ + /* Add here code for other stepper motor */ \ + } while (0) + +// Set half/full step macros +#define STEPPER_SET_HALF_STEP(index, flag) do { \ + switch (index) \ + { \ + case 1: \ + STEPPER_SET_STEP_MODE_MACRO(1, flag); \ + break; \ + /* Add here code for other stepper motor */ \ + } \ + } while (0) + + +// Control status +#define STEPPER_SET_CONTROL_BIT(index, flag) do { \ + switch (index) \ + { \ + case 1: \ + STEPPER_SET_CONTROL_BIT_MACRO(1, flag); \ + break; \ + /* Add here code for other stepper motor */ \ + } \ + } while (0) + + +// Set stepper power current +#define STEPPER_SET_POWER_CURRENT(index, flag) do { \ + switch (index) \ + { \ + case 1: \ + STEPPER_SET_POWER_CURRENT_MACRO(1, flag); \ + break; \ + /* Add here code for other stepper motor */ \ + } \ + } while (0) + +// Set rotation dirction of stepper motor +#define STEPPER_SET_DIRECTION(index, dir) do { \ + switch (index) \ + { \ + case 1: \ + STEPPER_SET_DIRECTION_MACRO(1, dir); \ + break; \ + /* Add here code for other stepper motor */ \ + } \ + } while (0) + +#endif /* HW_STEPPER_H */ diff --git a/bertos/hw/hw_thermo.h b/bertos/hw/hw_thermo.h new file mode 100644 index 00000000..bcac93a5 --- /dev/null +++ b/bertos/hw/hw_thermo.h @@ -0,0 +1,181 @@ +/** + * \file + * + * + * \brief thermo hardware-specific control functions. + * + * \version $Id$ + * \author Francesco Sacchi + * + */ + +#ifndef HW_THERMO_H +#define HW_THERMO_H + +#include "thermo_map.h" +#include "ntc_map.h" + +#include +#include + +#include +#include + +#warning TODO:This is an example implentation, you must implement it! + +/*! + * This function should return the temperature set tolerance. + */ +INLINE deg_t thermo_hw_tolerance(ThermoDev dev) +{ + ASSERT(dev < THERMO_CNT); + + switch (dev) + { + case THERMO_TEST: + /* Put here convertion function to temperature size */ + break; + + /* Put here your thermo device */ + + default: + ASSERT(0); + } + + return 0; +} + + +/*! + * This function should return the timeout for reaching the + * target temperature. + */ +INLINE ticks_t thermo_hw_timeout(ThermoDev dev) +{ + ASSERT(dev < THERMO_CNT); + + switch (dev) + { + case THERMO_TEST: + /* return ms_to_ticks(60000); */ + break; + + /* Put here a time out for select thermo device */ + + default: + ASSERT(0); + } + + return 0; +} + + + +/*! + * Read the temperature of the hw device \a dev. + */ +INLINE deg_t thermo_hw_read(ThermoDev dev) +{ + return ntc_read(dev); +} + + +/*! + * Turns off a specific device. + * This function is usefull to handle errors. + */ +INLINE void thermo_hw_off(ThermoDev dev) +{ + ASSERT(dev < THERMO_CNT); + + switch (dev) + { + case THERMO_TEST: + phase_setPower(TRIAC_TEST, 0); + break; + + /* Put here a thermo device to turn off */ + + default: + ASSERT(0); + } + +} + + +/*! + * Based on the current temperature \a cur_temp and the target temperature \a target, this function turns on and off specific + * triac channel and handles the freezer alarm. + * It may use also PID control for thermo-regolations. + */ +INLINE void thermo_hw_set(ThermoDev dev, deg_t target, deg_t cur_temp) +{ + ASSERT(dev < THERMO_CNT); + + deg_t dist = target - cur_temp; + //kprintf("dev[%d], dist[%d]\n", dev, dist); + + switch(dev) + { + case THERMO_TEST: + if (dist > 0) + { + /* phase_setPower(TRIAC_TEST, dist * PID_TEST_K); */ + } + else + { + /* phase_setPower(TRIAC_TEST, 0); */ + } + break; + + /* Put here an other thermo device */ + + default: + ASSERT(0); + } +} + + +#define THERMO_HW_INIT _thermo_hw_init() + +/*! + * Init hw associated with thermo-control. + */ +INLINE void _thermo_hw_init(void) +{ + ASSERT(phase_initialized); + ASSERT(ntc_initialized); + + phase_setPower(TRIAC_TEST, 0); + + /* Add here the other thermo device */ +} + +#endif /* HW_THERMO_H */ diff --git a/bertos/hw/kbd_map.h b/bertos/hw/kbd_map.h index f54bbc02..d09eb2b7 100644 --- a/bertos/hw/kbd_map.h +++ b/bertos/hw/kbd_map.h @@ -39,21 +39,13 @@ * \author Stefano Fedrigo */ -/*#* - *#* $Log$ - *#* Revision 1.2 2006/07/19 12:56:27 bernie - *#* Convert to new Doxygen style. - *#* - *#* Revision 1.1 2006/02/10 12:31:03 bernie - *#* Add templates for hw definitions. - *#* - *#*/ - #ifndef HW_KBD_MAP_H #define HW_KBD_MAP_H #include +#warning TODO:This is an example implentation, you must implement it! + /** * Type for keyboard mask. diff --git a/bertos/hw/mcp41_map.h b/bertos/hw/mcp41_map.h index 5e083128..1cd1449e 100644 --- a/bertos/hw/mcp41_map.h +++ b/bertos/hw/mcp41_map.h @@ -40,13 +40,16 @@ #ifndef MCP41_MAP_H #define MCP41_MAP_H +#warning TODO:This is an example implentation, you must implement it! + /** \name Enum for mcp41 pot evices. * \{ */ typedef enum Mcp41Dev { MCP41_LED, - MCP41_PHOTO_GAIN, + + /* put here other mcp41 device */ MCP41_CNT, } Mcp41Dev; diff --git a/bertos/hw/ntc_map.h b/bertos/hw/ntc_map.h new file mode 100644 index 00000000..505f1c31 --- /dev/null +++ b/bertos/hw/ntc_map.h @@ -0,0 +1,61 @@ +/** + * \file + * + * + * \brief NTC map definitions. + * + * \version $Id$ + * + * \author Giovanni Bajo + * \author Francesco Sacchi + */ + +#ifndef NTC_MAP_H +#define NTC_MAP_H + +#include + +#warning TODO:This is an example implentation, you must implement it! + +/*! \name Enum for ntc devices. + * \{ + */ +typedef enum NtcDev +{ + NTC_TEST, + + /* Put here your thermo device */ + + NTC_CNT +} NtcDev; +/* \} */ + +#endif /* NTC_MAP_H */ diff --git a/bertos/hw/phase_map.h b/bertos/hw/phase_map.h new file mode 100644 index 00000000..fb9bcc29 --- /dev/null +++ b/bertos/hw/phase_map.h @@ -0,0 +1,58 @@ +/** + * \file + * + * + * \brief Triac map definitions. + * + * \version $Id$ + * + * \author Francesco Sacchi + */ + +#ifndef PHASE_MAP_H +#define PHASE_MAP_H + +#warning TODO:This is an example implentation, you must implement it! + +/*! \name Enum for triac devices. + * \{ + */ +typedef enum TriacDev +{ + TRIAC_TEST, + + /* Put here other triac device */ + + TRIAC_CNT +} TriacDev; +/* \} */ + +#endif /* PHASE_MAP_H */ diff --git a/bertos/hw/pwm_map.h b/bertos/hw/pwm_map.h new file mode 100644 index 00000000..da0c2c97 --- /dev/null +++ b/bertos/hw/pwm_map.h @@ -0,0 +1,54 @@ +/** + * \file + * + * + * + * \brief PWM map device. + * + * \version $Id$ + * + * \author Daniele Basile + */ + +#ifndef HW_PWM_MAP_H +#define HW_PWM_MAP_H + +#warning TODO:This is an example implentation, you must implement it! + +typedef enum +{ + PWM_CH0 = 0, + +/* add other PWM channel */ + + PWM_CNT +} PwmDev; + +#endif /* HW_PWM_MAP_H */ diff --git a/bertos/hw/thermo_map.h b/bertos/hw/thermo_map.h new file mode 100644 index 00000000..4376076a --- /dev/null +++ b/bertos/hw/thermo_map.h @@ -0,0 +1,70 @@ +/** + * \file + * + * + * \brief Thermo regulation control map definitions. + * + * \version $Id$ + * + * \author Francesco Sacchi + */ + +#ifndef THERMO_MAP_H +#define THERMO_MAP_H + +#include +#include + +#warning TODO:This is an example implentation, you must implement it! + +typedef uint8_t thermostatus_t; + +#define THERMO_OFF 0 +#define THERMO_HEATING BV(0) +#define THERMO_FREEZING BV(1) +#define THERMO_TGT_REACH BV(2) +#define THERMOERRF_NTCSHORT BV(3) +#define THERMOERRF_NTCOPEN BV(4) +#define THERMOERRF_TIMEOUT BV(5) +#define THERMO_ACTIVE BV(6) + +#define THERMO_ERRMASK (THERMOERRF_NTCSHORT | THERMOERRF_NTCOPEN | THERMOERRF_TIMEOUT) + +typedef enum ThermoDev +{ + THERMO_TEST, + + /* Put here your thermo device */ + + THERMO_CNT, +} ThermoDev; + +#endif /* THERMO_MAP_H */ -- 2.25.1