Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: HelloWorld_PLC01A1
CLT01_38S.cpp
00001 /** 00002 ****************************************************************************** 00003 * @file CLT01_38S_class.cpp 00004 * @author System Lab Noida 00005 * @version V1.0.0 00006 * @date 08-July-2015 00007 * @brief PLC_CLT01-38SQ7 00008 * This file provides firmware functions for how to manage I/O from CLT01-38SQ7 00009 ============================================================================== 00010 00011 00012 ****************************************************************************** 00013 * @attention 00014 * 00015 * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> 00016 * 00017 * Redistribution and use in source and binary forms, with or without modification, 00018 * are permitted provided that the following conditions are met: 00019 * 1. Redistributions of source code must retain the above copyright notice, 00020 * this list of conditions and the following disclaimer. 00021 * 2. Redistributions in binary form must reproduce the above copyright notice, 00022 * this list of conditions and the following disclaimer in the documentation 00023 * and/or other materials provided with the distribution. 00024 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00025 * may be used to endorse or promote products derived from this software 00026 * without specific prior written permission. 00027 * 00028 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00029 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00030 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00031 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00032 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00033 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00034 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00035 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00036 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00037 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00038 * 00039 ****************************************************************************** 00040 */ 00041 00042 /* Includes ------------------------------------------------------------------*/ 00043 #include "plc.h" 00044 00045 #include "CLT01_38S.h" 00046 00047 /** @addtogroup Drivers Drivers 00048 * @{ 00049 * @brief Demo Driver Layer 00050 */ 00051 00052 /** @addtogroup BSP BSP 00053 * @{ 00054 */ 00055 00056 /** @addtogroup Components Components 00057 * @{ 00058 */ 00059 00060 /** @defgroup CLT01_38S CLT01_38S 00061 * @{ 00062 * @brief Digital Input Driver Layer 00063 */ 00064 00065 /** @defgroup CLT01_38S_Private_variables CLT01 38S Private variables 00066 * @{ 00067 * @brief Digital Input Private variables 00068 */ 00069 00070 /* Number of components */ 00071 uint8_t CLT01_38S::number_of_plc_input_components = 0; 00072 00073 00074 /** @defgroup CLT01_38S_Exported_Functions CLT01 38S Exported Functions 00075 * @{ 00076 * @brief Digital Input exported Function 00077 */ 00078 00079 /********************************************************** 00080 * @brief Starts the CLT01_38S library 00081 * @param init Initialization structure. 00082 * @retval COMPONENT_OK in case of success. 00083 **********************************************************/ 00084 status_t CLT01_38S::CLT01_38S_Init(void *init) 00085 { 00086 OTA_Buffer = 0x00; 00087 CLT_PARITY_Buffer = 0x00; 00088 UVA_Buffer = 0x00; 00089 CLT_INPUT_STATUS_Buffer = 0x00; 00090 FLAG_CLT_READ = 0; 00091 00092 /* Unselect the CLT chip at startup to avoid FAULT */ 00093 ssel = 1; 00094 00095 return COMPONENT_OK; 00096 } 00097 00098 /********************************************************** 00099 * @brief Read id 00100 * @param id pointer to the identifier to be read. 00101 * @retval COMPONENT_OK in case of success. 00102 **********************************************************/ 00103 status_t CLT01_38S::CLT01_38S_ReadID(uint8_t *id) 00104 { 00105 *id = plc_input_component_instance; 00106 00107 return COMPONENT_OK; 00108 } 00109 00110 /********************************************************** 00111 * @brief CLT Read Status 00112 * @param None 00113 * @retval Status 00114 **********************************************************/ 00115 uint8_t CLT01_38S::CLT01_38S_GetReadStatus(void) 00116 { 00117 return FLAG_CLT_READ; 00118 } 00119 00120 /********************************************************** 00121 * @brief Set CLT Read Status 00122 * @param Status 00123 * @retval None 00124 **********************************************************/ 00125 void CLT01_38S::CLT01_38S_SetReadStatus(uint8_t status) 00126 { 00127 FLAG_CLT_READ = status; 00128 } 00129 00130 /********************************************************** 00131 * @brief INPUT status 00132 * @param None 00133 * @retval Channels status corresponding to 8 inputs 00134 **********************************************************/ 00135 uint8_t CLT01_38S::CLT01_38S_GetInputData(void) 00136 { 00137 CLT_INPUT_STATUS_Buffer = spi_rx_buff[1]; 00138 00139 return CLT_INPUT_STATUS_Buffer; 00140 } 00141 00142 /********************************************************** 00143 * @brief CLT Over_Temprature_Alarm 00144 * @param None 00145 * @retval Overtemperature bit, COMPONENT_ERROR in case of alarm 00146 **********************************************************/ 00147 status_t CLT01_38S::CLT01_38S_OverTempAlarm(void) 00148 { 00149 OTA_Buffer = spi_rx_buff[0]; 00150 OTA_Buffer = OTA_Buffer & (0x40); 00151 00152 if(OTA_Buffer == 0x40) { 00153 return COMPONENT_OK; 00154 } else { 00155 return COMPONENT_ERROR; 00156 } 00157 } 00158 00159 /********************************************************** 00160 * @brief CLT Parity_Check_bits 00161 * @param None 00162 * @retval Parity bits for diagnosing inconsistency in data transmission 00163 **********************************************************/ 00164 uint8_t CLT01_38S::CLT01_38S_CheckParity(void) 00165 { 00166 CLT_PARITY_Buffer = spi_rx_buff[0]; 00167 CLT_PARITY_Buffer = CLT_PARITY_Buffer & (0x3C); 00168 CLT_PARITY_Buffer = CLT_PARITY_Buffer >> 2; 00169 return CLT_PARITY_Buffer; 00170 } 00171 00172 /********************************************************** 00173 * @brief CLT Under_Voltage_Alarm_bit 00174 * @param None 00175 * @retval Under voltage alarm bit, COMPONENT_ERROR in case of alarm 00176 **********************************************************/ 00177 status_t CLT01_38S::CLT01_38S_UnderVoltAlarm(void) 00178 { 00179 UVA_Buffer = spi_rx_buff[0]; 00180 UVA_Buffer = UVA_Buffer & (0x80); 00181 00182 if(UVA_Buffer == 0x80) { 00183 return COMPONENT_OK; 00184 } else{ 00185 return COMPONENT_ERROR; 00186 } 00187 } 00188 00189 /********************************************************** 00190 * @brief Get input information from input channels component 00191 * @param rxBuff 00192 * @retval None 00193 **********************************************************/ 00194 void CLT01_38S::CLT01_38S_DigInpArray_GetInput(uint8_t *inputArray) 00195 { 00196 if(CLT01_38S_SpiReadBytes(spi_tx_buff, spi_rx_buff) != 0) { 00197 /* Aborting the program */ 00198 exit(EXIT_FAILURE); 00199 } 00200 inputArray[0] = spi_rx_buff[0]; 00201 inputArray[1] = spi_rx_buff[1]; 00202 } 00203 00204 /** 00205 * @} //end CLT01_38S Exported Functions 00206 */ 00207 00208 /** 00209 * @} //end CLT01_38S Device Driver 00210 */ 00211 /** 00212 * @} //end Components 00213 */ 00214 /** 00215 * @} //close group BSP 00216 */ 00217 00218 /** 00219 * @} //close group Drivers 00220 */ 00221 00222 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Fri Jul 15 2022 00:11:30 by
