Maxim Integrated / OneWire

Dependents:   MAXREFDES131_Qt_Demo MAX32630FTHR_iButton_uSD_Logger MAX32630FTHR_DS18B20_uSD_Logger MAXREFDES130_131_Demo ... more

Files at this revision

API Documentation at this revision

Comitter:
j3
Date:
Tue Mar 15 01:38:17 2016 +0000
Parent:
13:d1bdb03703de
Child:
15:f6cb0d906fb6
Commit message:
added OWInitMaster() to interface in order to encapsulate master specific functions

Changed in this revision

OneWire_Masters/DS2480B/ds2480b.cpp Show annotated file Show diff for this revision Revisions of this file
OneWire_Masters/DS2480B/ds2480b.h Show annotated file Show diff for this revision Revisions of this file
OneWire_Masters/DS248x/ds248x.cpp Show annotated file Show diff for this revision Revisions of this file
OneWire_Masters/DS248x/ds248x.h Show annotated file Show diff for this revision Revisions of this file
OneWire_Masters/GPIO/owgpio.cpp Show annotated file Show diff for this revision Revisions of this file
OneWire_Masters/GPIO/owgpio.h Show annotated file Show diff for this revision Revisions of this file
OneWire_Masters/OneWireInterface.h Show annotated file Show diff for this revision Revisions of this file
--- a/OneWire_Masters/DS2480B/ds2480b.cpp	Tue Mar 08 18:00:40 2016 -0800
+++ b/OneWire_Masters/DS2480B/ds2480b.cpp	Tue Mar 15 01:38:17 2016 +0000
@@ -74,6 +74,15 @@
 
 
 //*********************************************************************
+bool Ds2480b::OWInitMaster()
+{
+    bool rtn_val = false;
+    
+    return(rtn_val);
+}
+
+
+//*********************************************************************
 bool Ds2480b::OWReset()
 {
     bool rtn_val = false;
--- a/OneWire_Masters/DS2480B/ds2480b.h	Tue Mar 08 18:00:40 2016 -0800
+++ b/OneWire_Masters/DS2480B/ds2480b.h	Tue Mar 15 01:38:17 2016 +0000
@@ -101,6 +101,8 @@
     
     
     /***** OW API ****************************************************/
+    virtual bool OWInitMaster();
+    
     virtual bool OWReset();
     
     virtual void OWWriteBit(uint8_t sendbit);
--- a/OneWire_Masters/DS248x/ds248x.cpp	Tue Mar 08 18:00:40 2016 -0800
+++ b/OneWire_Masters/DS248x/ds248x.cpp	Tue Mar 15 01:38:17 2016 +0000
@@ -73,6 +73,13 @@
 
 
 //*********************************************************************
+bool Ds248x::OWInitMaster()
+{
+    return(detect());
+}
+
+
+//*********************************************************************
 bool Ds248x::detect(void)
 {
     bool rtn_val = false;
--- a/OneWire_Masters/DS248x/ds248x.h	Tue Mar 08 18:00:40 2016 -0800
+++ b/OneWire_Masters/DS248x/ds248x.h	Tue Mar 15 01:38:17 2016 +0000
@@ -273,6 +273,8 @@
     
     
     /***** OW API ****************************************************/
+    virtual bool OWInitMaster();
+    
     virtual bool OWReset();
     
     virtual void OWWriteBit(uint8_t sendbit);
--- a/OneWire_Masters/GPIO/owgpio.cpp	Tue Mar 08 18:00:40 2016 -0800
+++ b/OneWire_Masters/GPIO/owgpio.cpp	Tue Mar 15 01:38:17 2016 +0000
@@ -55,18 +55,42 @@
 #include "clkman_regs.h"
 
 
+//counts instances of this class being created
+uint32_t OwGpio::ow_instance_cnt = 0;
+
+
 //*********************************************************************
 OwGpio::OwGpio(PinName ow_gpio, PinName ext_spu)
 :_ext_spu(ext_spu, 1), _ow_speed(SPEED_STANDARD), _ow_level(LEVEL_NORMAL),
 _ow_port(PINNAME_TO_PORT(ow_gpio)), _ow_pin(PINNAME_TO_PIN(ow_gpio))
 {
-    init_ow_gpio(ow_gpio);
+    _ow_instance = OwGpio::ow_instance_cnt++;
 }
 
 
 //*********************************************************************
 OwGpio::~OwGpio()
 {
+    release_ow_gpio();
+
+    if(_ow_instance == OwGpio::ow_instance_cnt)
+    {
+        release_ow_timer();
+    }
+    
+    OwGpio::ow_instance_cnt--;
+}
+
+
+//*********************************************************************
+bool OwGpio::OWInitMaster()
+{
+    bool rtn_val = true;
+    
+    init_ow_gpio(_ow_port, _ow_pin);
+    init_ow_timer();
+    
+    return(rtn_val);
 }
 
 
@@ -751,17 +775,12 @@
 
 
 //*********************************************************************
-void OwGpio::init_ow_gpio(PinName ow_gpio)
+void OwGpio::init_ow_gpio(uint32_t ow_port, uint32_t ow_pin)
 {
     if (MXC_CLKMAN->clk_ctrl_1_gpio == MXC_E_CLKMAN_CLK_SCALE_DISABLED) 
     {
         MXC_CLKMAN->clk_ctrl_1_gpio = MXC_E_CLKMAN_CLK_SCALE_ENABLED;
     }
-    
-    MBED_ASSERT(ow_gpio != (PinName)NC);
-
-    uint32_t ow_port = PINNAME_TO_PORT(ow_gpio);
-    uint32_t ow_pin = PINNAME_TO_PIN(ow_gpio);
 
     /* Set function */
     MXC_GPIO->func_sel[ow_port] &= ~(0xF << (4 * ow_pin));
@@ -802,4 +821,17 @@
         MXC_TMR3->ctrl |= MXC_F_TMR_CTRL_ENABLE0;
     }
 }
+
+
+//*********************************************************************
+void OwGpio::release_ow_timer(void)
+{
+}
+
+
+//*********************************************************************
+void OwGpio::release_ow_gpio()
+{
+}
+
 #endif/* TARGET_MAX32600*/
--- a/OneWire_Masters/GPIO/owgpio.h	Tue Mar 08 18:00:40 2016 -0800
+++ b/OneWire_Masters/GPIO/owgpio.h	Tue Mar 15 01:38:17 2016 +0000
@@ -87,6 +87,10 @@
     static const uint16_t TSLOT_OVD = 10;
     
     
+    //counts instances of this class being created
+    static uint32_t ow_instance_cnt;
+    
+    
     /**********************************************************//**
     * @brief Owgpio constructor
     * 
@@ -119,21 +123,9 @@
     virtual ~OwGpio();
     
     
-    /**********************************************************//**
-    * @brief initializes 16-bit counter_0 of TMR3 on MAX32600MBED 
-    * 
-    * @details 
-    *
-    * On Entry:
-    *
-    * On Exit:
-    *
-    * @return 
-    **************************************************************/
-    static void init_ow_timer(void);
+    /***** OW API ****************************************************/
+    virtual bool OWInitMaster();
     
-    
-    /***** OW API ****************************************************/
     virtual bool OWReset();
     
     virtual void OWWriteBit(uint8_t sendbit);
@@ -190,7 +182,14 @@
     
     private:
     
-    void init_ow_gpio(PinName ow_gpio);
+    static void init_ow_timer(void);
+    static void release_ow_timer(void);
+    
+    void init_ow_gpio(uint32_t ow_port, uint32_t ow_pin);
+    void release_ow_gpio();
+    
+    //specific instance of this class
+    uint32_t _ow_instance;
     
     DigitalOut _ext_spu;
     OW_SPEED _ow_speed;
--- a/OneWire_Masters/OneWireInterface.h	Tue Mar 08 18:00:40 2016 -0800
+++ b/OneWire_Masters/OneWireInterface.h	Tue Mar 15 01:38:17 2016 +0000
@@ -95,11 +95,31 @@
         LEVEL_STRONG = 0x02
     };
     
+    enum OW_ERROR_CODE
+    {
+    };
+    
     //http://www.learncpp.com/cpp-tutorial/811-static-member-variables/
     //all objects of this class type share 'ROMnumberLen' and 
     //const makes it read only.  
     static const size_t ROMnumberLen = 8;
-        
+    
+    
+    /**********************************************************//**
+    * @brief OWInitMaster()
+    * 
+    * @details Initiializes particular master being instaniated.
+    *  Added to interface to provide a common 'init' function between
+    *  all masters
+    *
+    * On Entry:
+    *
+    * On Exit:
+    *    @return TRUE(1):  Success
+    *            FALSE(0): Fail
+    **************************************************************/
+    virtual bool OWInitMaster() = 0;
+    
     
     /**********************************************************//**
     * @brief OWReset()