New Version with OS5

Committer:
tgrosch
Date:
Sun Oct 25 00:58:24 2020 +0000
Revision:
0:62b846b3988a
Child:
3:0eb6a9927171
First successful compile.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tgrosch 0:62b846b3988a 1 /*!
tgrosch 0:62b846b3988a 2 * \file hostController.h
tgrosch 0:62b846b3988a 3 * \author Karthik Rajagopal <krthik@ti.com>
tgrosch 0:62b846b3988a 4 * \version 0.9.1
tgrosch 0:62b846b3988a 5 *
tgrosch 0:62b846b3988a 6 * \section COPYRIGHT
tgrosch 0:62b846b3988a 7 * TEXAS INSTRUMENTS TEXT FILE LICENSE
tgrosch 0:62b846b3988a 8 * Copyright (c) 2018 Texas Instruments Incorporated
tgrosch 0:62b846b3988a 9 * All rights reserved not granted herein.
tgrosch 0:62b846b3988a 10 * Limited License.
tgrosch 0:62b846b3988a 11 * Texas Instruments Incorporated grants a world-wide, royalty-free, non-exclusive license under copyrights and patents it now or hereafter owns or controls to make, have made, use, import, offer to sell and sell ("Utilize") this software subject to the terms herein. With respect to the foregoing patent license, such license is granted solely to the extent that any such patent is necessary to Utilize the software alone. The patent license shall not apply to any combinations which include this software, other than combinations with devices manufactured by or for TI ("TI Devices"). No hardware patent is licensed hereunder.
tgrosch 0:62b846b3988a 12 * Redistributions must preserve existing copyright notices and reproduce this license (including the above copyright notice and the disclaimer and (if applicable) source code license limitations below) in the documentation and/or other materials provided with the distribution
tgrosch 0:62b846b3988a 13 * Redistribution and use in binary form, without modification, are permitted provided that the following conditions are met:
tgrosch 0:62b846b3988a 14 * * No reverse engineering, decompilation, or disassembly of this software is permitted with respect to any software provided in binary form.
tgrosch 0:62b846b3988a 15 * * any redistribution and use are licensed by TI for use only with TI Devices.
tgrosch 0:62b846b3988a 16 * * Nothing shall obligate TI to provide you with source code for the software licensed and provided to you in object code.
tgrosch 0:62b846b3988a 17 * If software source code is provided to you, modification and redistribution of the source code are permitted provided that the following conditions are met:
tgrosch 0:62b846b3988a 18 * * any redistribution and use of the source code, including any resulting derivative works, are licensed by TI for use only with TI Devices.
tgrosch 0:62b846b3988a 19 * * any redistribution and use of any object code compiled from the source code and any resulting derivative works, are licensed by TI for use only with TI Devices.
tgrosch 0:62b846b3988a 20 * Neither the name of Texas Instruments Incorporated nor the names of its suppliers may be used to endorse or promote products derived from this software without specific prior written permission.
tgrosch 0:62b846b3988a 21 * DISCLAIMER.
tgrosch 0:62b846b3988a 22 * THIS SOFTWARE IS PROVIDED BY TI AND TI'S LICENSORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TI AND TI'S LICENSORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
tgrosch 0:62b846b3988a 23 *
tgrosch 0:62b846b3988a 24 * \section DESCRIPTION
tgrosch 0:62b846b3988a 25 * This file contains the hostController class. This file contains a general template for a host controller
tgrosch 0:62b846b3988a 26 */
tgrosch 0:62b846b3988a 27 #ifndef HOSTCONTROLLER_H_
tgrosch 0:62b846b3988a 28 #define HOSTCONTROLLER_H_
tgrosch 0:62b846b3988a 29
tgrosch 0:62b846b3988a 30 #include "i2cHandler.h"
tgrosch 0:62b846b3988a 31 //#include "definitions.h"
tgrosch 0:62b846b3988a 32
tgrosch 0:62b846b3988a 33 //#ifdef TIMSP430F5529_LAUNCHPAD_CALIBRATION_TOOL
tgrosch 0:62b846b3988a 34 //#include "MSP430/i2cHandler.h"
tgrosch 0:62b846b3988a 35 //#include "MSP430/flashHandler.h"
tgrosch 0:62b846b3988a 36 //#include "MSP430/MSPConnections.h"
tgrosch 0:62b846b3988a 37 //extern "C"
tgrosch 0:62b846b3988a 38 //{
tgrosch 0:62b846b3988a 39 //#include "MSP430/hal.h"
tgrosch 0:62b846b3988a 40 //#include "MSP430/USB_config/descriptors.h"
tgrosch 0:62b846b3988a 41 //#include "MSP430/USB_API/USB_Common/device.h"
tgrosch 0:62b846b3988a 42 //#include "MSP430/USB_API/USB_Common/usb.h" // USB-specific functions
tgrosch 0:62b846b3988a 43 //#include "MSP430/USB_API/USB_CDC_API/UsbCdc.h"
tgrosch 0:62b846b3988a 44 //#include "MSP430/USB_app/usbConstructs.h"
tgrosch 0:62b846b3988a 45 //}
tgrosch 0:62b846b3988a 46 //#include <stdlib.h> //Added to support abs function
tgrosch 0:62b846b3988a 47 //#endif
tgrosch 0:62b846b3988a 48
tgrosch 0:62b846b3988a 49 //#include <stdint.h>
tgrosch 0:62b846b3988a 50
tgrosch 0:62b846b3988a 51 //#ifdef OPT3101_USE_SERIALLIB
tgrosch 0:62b846b3988a 52 //#include "serialLib/serial.h"
tgrosch 0:62b846b3988a 53 //#ifdef _WIN32
tgrosch 0:62b846b3988a 54 //#include <windows.h>
tgrosch 0:62b846b3988a 55 //#else
tgrosch 0:62b846b3988a 56 //#include <unistd.h>
tgrosch 0:62b846b3988a 57 //#endif /*_WIN32 */
tgrosch 0:62b846b3988a 58 //#endif /* for OPT3101_USE_SERIALLIB */
tgrosch 0:62b846b3988a 59
tgrosch 0:62b846b3988a 60 //#ifdef OPT3101_USE_STDIOLIB
tgrosch 0:62b846b3988a 61 //#include <stdio.h>
tgrosch 0:62b846b3988a 62 /*! \def filename length
tgrosch 0:62b846b3988a 63 This sets memory allocation length for file naming strings
tgrosch 0:62b846b3988a 64 */
tgrosch 0:62b846b3988a 65 //#define FILENAME_LENGTH 50
tgrosch 0:62b846b3988a 66 //const char filePath[] = { "C:/temp/" };
tgrosch 0:62b846b3988a 67 //#endif
tgrosch 0:62b846b3988a 68
tgrosch 0:62b846b3988a 69 //#ifdef OPT3101_USE_SERIALLIB
tgrosch 0:62b846b3988a 70 /** \brief Serial Command Port declaration
tgrosch 0:62b846b3988a 71 This global variable declaration with name OPT3101commandPort of class serial::Serial is used by class like OPT3101::deviceRegister for I2C read and writes.
tgrosch 0:62b846b3988a 72 */
tgrosch 0:62b846b3988a 73 //serial::Serial OPT3101commandPort("COM4", 9600, serial::Timeout::simpleTimeout(1000));
tgrosch 0:62b846b3988a 74 //#if defined(linux) || defined(_WIN32)
tgrosch 0:62b846b3988a 75 //extern serial::Serial OPT3101I2CCommandPort;
tgrosch 0:62b846b3988a 76 //#endif
tgrosch 0:62b846b3988a 77
tgrosch 0:62b846b3988a 78 //#endif // SERIAL LIB
tgrosch 0:62b846b3988a 79
tgrosch 0:62b846b3988a 80 class hostController;
tgrosch 0:62b846b3988a 81
tgrosch 0:62b846b3988a 82
tgrosch 0:62b846b3988a 83 //#ifdef OPT3101_USE_STDIOLIB
tgrosch 0:62b846b3988a 84 /** \brief filePath
tgrosch 0:62b846b3988a 85 This global variable to declare a path to all calibration files storage
tgrosch 0:62b846b3988a 86 */
tgrosch 0:62b846b3988a 87 //extern const char filePath[];
tgrosch 0:62b846b3988a 88 //#endif
tgrosch 0:62b846b3988a 89
tgrosch 0:62b846b3988a 90 /** \brief hostController declaration
tgrosch 0:62b846b3988a 91 This global variable declaration with name host of class hostController is used by various different classes like OPT3101::deviceRegister , OPT3101::registers and OPT3101::device to specify specific instructions to the host like wait, sleep, I2C reads and writes
tgrosch 0:62b846b3988a 92 */
tgrosch 0:62b846b3988a 93 extern hostController host;
tgrosch 0:62b846b3988a 94 typedef unsigned char uint8_t;
tgrosch 0:62b846b3988a 95 typedef unsigned int uint32_t;
tgrosch 0:62b846b3988a 96 typedef unsigned short uint16_t;
tgrosch 0:62b846b3988a 97 /*! \class hostController
tgrosch 0:62b846b3988a 98 \brief Generic implementation for host
tgrosch 0:62b846b3988a 99
tgrosch 0:62b846b3988a 100 As part of OPT3101SDK there are several host specific functions that need to be performed. Examples of such functions are writing or reading from I2C ports, sending reset pulse to OPT3101 device<br>
tgrosch 0:62b846b3988a 101 These implementations are very specific to the host on which the SDK is ported and run. <br>
tgrosch 0:62b846b3988a 102 This abstract class provides a template with self explanatory method names which the users can override and implement their own functions. <br>
tgrosch 0:62b846b3988a 103 Example code is provided for OPT3101EVM with implementations for a windows 10 PC.
tgrosch 0:62b846b3988a 104 */
tgrosch 0:62b846b3988a 105 class hostController {
tgrosch 0:62b846b3988a 106 public:
tgrosch 0:62b846b3988a 107 /*!
tgrosch 0:62b846b3988a 108 * \brief constructor mostly used to initialize the host
tgrosch 0:62b846b3988a 109 *
tgrosch 0:62b846b3988a 110 * Method to mostly initialize host. Especially for MSP like hosts.
tgrosch 0:62b846b3988a 111 * \return Nothing
tgrosch 0:62b846b3988a 112 */
tgrosch 0:62b846b3988a 113 hostController(void);
tgrosch 0:62b846b3988a 114 /*!
tgrosch 0:62b846b3988a 115 * \brief method to read data from I2C port
tgrosch 0:62b846b3988a 116 *
tgrosch 0:62b846b3988a 117 * \param[in] address; address is the I2C register address
tgrosch 0:62b846b3988a 118 * \return value; value read from I2C port for the address
tgrosch 0:62b846b3988a 119 */
tgrosch 0:62b846b3988a 120 uint32_t readI2C(uint8_t address);
tgrosch 0:62b846b3988a 121 /*!
tgrosch 0:62b846b3988a 122 * \brief method to write data from I2C port
tgrosch 0:62b846b3988a 123 *
tgrosch 0:62b846b3988a 124 * \param[in] address; address is the I2C register address
tgrosch 0:62b846b3988a 125 * \param[in] data; data to write to I2C register
tgrosch 0:62b846b3988a 126 * \return Nothing
tgrosch 0:62b846b3988a 127 */
tgrosch 0:62b846b3988a 128 void writeI2C(uint8_t address, uint32_t data);
tgrosch 0:62b846b3988a 129 /*!
tgrosch 0:62b846b3988a 130 * \brief send reset pulse to OPT3101 device
tgrosch 0:62b846b3988a 131 * Method used to send reset pulse to OPT3101 device
tgrosch 0:62b846b3988a 132 * \return Nothing
tgrosch 0:62b846b3988a 133 */
tgrosch 0:62b846b3988a 134 void resetDevice();
tgrosch 0:62b846b3988a 135 /*!
tgrosch 0:62b846b3988a 136 * \brief sleep host
tgrosch 0:62b846b3988a 137 * Method used to sleep or make host wait for a particular amount of time specified in milliSeconds
tgrosch 0:62b846b3988a 138 * \param[in] timeInMilliSeconds; Time for which the host needs to sleep specified in milliSeconds
tgrosch 0:62b846b3988a 139 * \return Nothing
tgrosch 0:62b846b3988a 140 */
tgrosch 0:62b846b3988a 141 void sleep(uint32_t timeInMilliSeconds);
tgrosch 0:62b846b3988a 142 /*!
tgrosch 0:62b846b3988a 143 * \brief sleep host
tgrosch 0:62b846b3988a 144 * Method used to sleep or make host wait for a particular amount of time specified in number of data ready pulses from OPT3101
tgrosch 0:62b846b3988a 145 * \param[in] dataReadyCounts; Time for which the host needs to sleep specified data ready pulses from OPT3101
tgrosch 0:62b846b3988a 146 * \return Nothing
tgrosch 0:62b846b3988a 147 */
tgrosch 0:62b846b3988a 148 void sleepDataReadyCounts(uint16_t dataReadyCounts);
tgrosch 0:62b846b3988a 149 /*!
tgrosch 0:62b846b3988a 150 * \brief pause host
tgrosch 0:62b846b3988a 151 * Method used to make host wait for user input or interrupt. Useful for debug
tgrosch 0:62b846b3988a 152 * \return Nothing
tgrosch 0:62b846b3988a 153 */
tgrosch 0:62b846b3988a 154 void pause();
tgrosch 0:62b846b3988a 155 /*!
tgrosch 0:62b846b3988a 156 * \brief initialize host
tgrosch 0:62b846b3988a 157 * Method to initialize host. Especially for MSP like hosts.
tgrosch 0:62b846b3988a 158 * \return Nothing
tgrosch 0:62b846b3988a 159 */
tgrosch 0:62b846b3988a 160 void initialize();
tgrosch 0:62b846b3988a 161 /*!
tgrosch 0:62b846b3988a 162 * \brief print message
tgrosch 0:62b846b3988a 163 * Method to print message on host to user
tgrosch 0:62b846b3988a 164 * \return Nothing
tgrosch 0:62b846b3988a 165 */
tgrosch 0:62b846b3988a 166 void printf(const char *fmt, ...);
tgrosch 0:62b846b3988a 167 /*!
tgrosch 0:62b846b3988a 168 * \brief print Sets color for terminal
tgrosch 0:62b846b3988a 169 * Method sets colors for terminals
tgrosch 0:62b846b3988a 170 * \return Nothing
tgrosch 0:62b846b3988a 171 */
tgrosch 0:62b846b3988a 172 void printfSetColor(uint8_t color=0xFF);
tgrosch 0:62b846b3988a 173
tgrosch 0:62b846b3988a 174
tgrosch 0:62b846b3988a 175 //#ifdef TIMSP430F5529_LAUNCHPAD_CALIBRATION_TOOL
tgrosch 0:62b846b3988a 176 I2C::i2cHandler i2c;
tgrosch 0:62b846b3988a 177 // STORAGE::flashHandler flash;
tgrosch 0:62b846b3988a 178 // LAUNCHPAD::MSPConnections gpio;
tgrosch 0:62b846b3988a 179 //#endif
tgrosch 0:62b846b3988a 180
tgrosch 0:62b846b3988a 181 };
tgrosch 0:62b846b3988a 182
tgrosch 0:62b846b3988a 183
tgrosch 0:62b846b3988a 184 #endif /* HOSTCONTROLLER_H_ */
tgrosch 0:62b846b3988a 185