MHVLib  20111011
An efficiency oriented runtime library for AVR microcontrollers
A:/eclipse/mhvlib/MHV_SoftwareHBridge.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2011, Make, Hack, Void Inc
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *  * Redistributions of source code must retain the above copyright
00008  *    notice, this list of conditions and the following disclaimer.
00009  *  * Redistributions in binary form must reproduce the above copyright
00010  *    notice, this list of conditions and the following disclaimer in the
00011  *    documentation and/or other materials provided with the distribution.
00012  *  * Neither the name of the Make, Hack, Void nor the
00013  *    names of its contributors may be used to endorse or promote products
00014  *    derived from this software without specific prior written permission.
00015  *
00016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00017  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019  * DISCLAIMED. IN NO EVENT SHALL MAKE, HACK, VOID BE LIABLE FOR ANY
00020  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00021  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00022  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00023  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00025  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  */
00027 
00028 #ifndef MHV_SOFTWAREHBRIDGE_H_
00029 #define MHV_SOFTWAREHBRIDGE_H_
00030 
00031 #ifdef MHV_TIMER16_1
00032 
00033 #include <inttypes.h>
00034 #include <MHV_io.h>
00035 #include <MHV_Timer16.h>
00036 
00037 enum mhv_SoftwareHBridge_direction {
00038         MHV_SOFTWAREHBRIDGE_DIR_COAST,
00039         MHV_SOFTWAREHBRIDGE_DIR_FORWARD,
00040         MHV_SOFTWAREHBRIDGE_DIR_BACKWARD,
00041         MHV_SOFTWAREHBRIDGE_DIR_BRAKE
00042 };
00043 typedef enum mhv_SoftwareHBridge_direction MHV_SOFTWAREHBRIDGE_DIRECTION;
00044 
00045 enum mhv_SoftwareHBridge_type {
00046         MHV_SOFTWAREHBRIDGE_TYPE_PULLUP,
00047         MHV_SOFTWAREHBRIDGE_TYPE_DIRECT
00048 };
00049 typedef enum mhv_SoftwareHBridge_type MHV_SOFTWAREHBRIDGE_TYPE;
00050 
00051 class MHV_SoftwareHBridge {
00052 protected:
00053         MHV_SOFTWAREHBRIDGE_TYPE        _type;
00054         MHV_Timer16                                     *_timer;
00055         uint8_t                                         _timerChannel;
00056 
00057         volatile uint8_t                        *_dir1Top;
00058         volatile uint8_t                        *_out1Top;
00059         uint8_t                                         _pin1Top;
00060         volatile uint8_t                        *_out1Bottom;
00061         uint8_t                                         _pin1Bottom;
00062         volatile uint8_t                        *_dir2Top;
00063         volatile uint8_t                        *_out2Top;
00064         uint8_t                                         _pin2Top;
00065         volatile uint8_t                        *_out2Bottom;
00066         uint8_t                                         _pin2Bottom;
00067 
00068         MHV_SOFTWAREHBRIDGE_DIRECTION _direction;
00069 
00070 public:
00071         MHV_SoftwareHBridge(MHV_SOFTWAREHBRIDGE_TYPE type, MHV_Timer16 *timer, uint8_t timerChannel,
00072                         volatile uint8_t *dir1Top, volatile uint8_t *out1Top, volatile uint8_t *in1Top, uint8_t pin1Top, int8_t int1Top,
00073                         volatile uint8_t *dir1Bottom, volatile uint8_t *out1Bottom, volatile uint8_t *in1Bottom, uint8_t pin1Bottom, int8_t int1Bottom,
00074                         volatile uint8_t *dir2Top, volatile uint8_t *out2Top, volatile uint8_t *in2Top, uint8_t pin2Top, int8_t int2Top,
00075                         volatile uint8_t *dir2Bottom, volatile uint8_t *out2Bottom, volatile uint8_t *in2Bottom, uint8_t pin2Bottom, int8_t int2Bottom);
00076         void reset();
00077         void update();
00078         void set(MHV_SOFTWAREHBRIDGE_DIRECTION direction, uint16_t magnitude);
00079         void set(MHV_SOFTWAREHBRIDGE_DIRECTION direction);
00080 };
00081 
00082 #endif // MHV_TIMER16_1
00083 
00084 #endif /* MHV_SOFTWAREHBRIDGE_H_ */