Добавлены библиотеки adc, modbus (его надо проверить)
В библиотеке adc пока только сделана заготовка для считывания выброса, надо доделать: Пока в main крутиться тест: формирование импульса ножкой светодиодом и считыание АЦП. Считывается этот импульс и определяется его пик (максимальное значение) и в районе этого пика беруться значения для расчета его амплитуды Modbus добавлен но не проверен
This commit is contained in:
		
							parent
							
								
									580bac9f52
								
							
						
					
					
						commit
						a2043006cc
					
				
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							@ -65,7 +65,7 @@
 | 
			
		||||
/*#define HAL_SPI_MODULE_ENABLED   */
 | 
			
		||||
/*#define HAL_SRAM_MODULE_ENABLED   */
 | 
			
		||||
#define HAL_TIM_MODULE_ENABLED
 | 
			
		||||
/*#define HAL_UART_MODULE_ENABLED   */
 | 
			
		||||
#define HAL_UART_MODULE_ENABLED
 | 
			
		||||
/*#define HAL_USART_MODULE_ENABLED   */
 | 
			
		||||
/*#define HAL_WWDG_MODULE_ENABLED   */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -56,7 +56,9 @@ void DebugMon_Handler(void);
 | 
			
		||||
void PendSV_Handler(void);
 | 
			
		||||
void SysTick_Handler(void);
 | 
			
		||||
void DMA1_Channel1_IRQHandler(void);
 | 
			
		||||
void TIM2_IRQHandler(void);
 | 
			
		||||
void TIM3_IRQHandler(void);
 | 
			
		||||
void USART1_IRQHandler(void);
 | 
			
		||||
/* USER CODE BEGIN EFP */
 | 
			
		||||
 | 
			
		||||
/* USER CODE END EFP */
 | 
			
		||||
 | 
			
		||||
@ -32,12 +32,15 @@ extern "C" {
 | 
			
		||||
 | 
			
		||||
/* USER CODE END Includes */
 | 
			
		||||
 | 
			
		||||
extern TIM_HandleTypeDef htim2;
 | 
			
		||||
 | 
			
		||||
extern TIM_HandleTypeDef htim3;
 | 
			
		||||
 | 
			
		||||
/* USER CODE BEGIN Private defines */
 | 
			
		||||
 | 
			
		||||
/* USER CODE END Private defines */
 | 
			
		||||
 | 
			
		||||
void MX_TIM2_Init(void);
 | 
			
		||||
void MX_TIM3_Init(void);
 | 
			
		||||
 | 
			
		||||
/* USER CODE BEGIN Prototypes */
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										52
									
								
								diode_tester/Core/Inc/usart.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								diode_tester/Core/Inc/usart.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,52 @@
 | 
			
		||||
/* USER CODE BEGIN Header */
 | 
			
		||||
/**
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  * @file    usart.h
 | 
			
		||||
  * @brief   This file contains all the function prototypes for
 | 
			
		||||
  *          the usart.c file
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  * @attention
 | 
			
		||||
  *
 | 
			
		||||
  * Copyright (c) 2024 STMicroelectronics.
 | 
			
		||||
  * All rights reserved.
 | 
			
		||||
  *
 | 
			
		||||
  * This software is licensed under terms that can be found in the LICENSE file
 | 
			
		||||
  * in the root directory of this software component.
 | 
			
		||||
  * If no LICENSE file comes with this software, it is provided AS-IS.
 | 
			
		||||
  *
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  */
 | 
			
		||||
/* USER CODE END Header */
 | 
			
		||||
/* Define to prevent recursive inclusion -------------------------------------*/
 | 
			
		||||
#ifndef __USART_H__
 | 
			
		||||
#define __USART_H__
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
extern "C" {
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/* Includes ------------------------------------------------------------------*/
 | 
			
		||||
#include "main.h"
 | 
			
		||||
 | 
			
		||||
/* USER CODE BEGIN Includes */
 | 
			
		||||
 | 
			
		||||
/* USER CODE END Includes */
 | 
			
		||||
 | 
			
		||||
extern UART_HandleTypeDef huart1;
 | 
			
		||||
 | 
			
		||||
/* USER CODE BEGIN Private defines */
 | 
			
		||||
 | 
			
		||||
/* USER CODE END Private defines */
 | 
			
		||||
 | 
			
		||||
void MX_USART1_UART_Init(void);
 | 
			
		||||
 | 
			
		||||
/* USER CODE BEGIN Prototypes */
 | 
			
		||||
 | 
			
		||||
/* USER CODE END Prototypes */
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#endif /* __USART_H__ */
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										116
									
								
								diode_tester/Core/Interfaces/crc_algs.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										116
									
								
								diode_tester/Core/Interfaces/crc_algs.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,116 @@
 | 
			
		||||
#include "crc_algs.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
uint32_t CRC_calc;
 | 
			
		||||
uint32_t CRC_ref;
 | 
			
		||||
 | 
			
		||||
//uint16_t CRC_calc;
 | 
			
		||||
//uint16_t CRC_ref;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// left this global for debug
 | 
			
		||||
uint8_t uchCRCHi = 0xFF;  
 | 
			
		||||
uint8_t uchCRCLo = 0xFF; 
 | 
			
		||||
unsigned uIndex;    
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
uint32_t crc32(uint8_t *data, uint32_t data_size)
 | 
			
		||||
{
 | 
			
		||||
	static const unsigned int crc32_table[] =
 | 
			
		||||
{
 | 
			
		||||
	0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, 
 | 
			
		||||
	0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 
 | 
			
		||||
	0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 
 | 
			
		||||
	0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, 
 | 
			
		||||
	0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, 
 | 
			
		||||
	0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, 
 | 
			
		||||
	0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F, 
 | 
			
		||||
	0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, 
 | 
			
		||||
	0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, 
 | 
			
		||||
	0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, 
 | 
			
		||||
	0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 
 | 
			
		||||
	0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, 
 | 
			
		||||
	0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, 
 | 
			
		||||
	0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, 
 | 
			
		||||
	0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F, 
 | 
			
		||||
	0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, 
 | 
			
		||||
	0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, 
 | 
			
		||||
	0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, 
 | 
			
		||||
	0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, 
 | 
			
		||||
	0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, 
 | 
			
		||||
	0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, 
 | 
			
		||||
	0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79, 
 | 
			
		||||
	0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, 
 | 
			
		||||
	0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, 
 | 
			
		||||
	0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, 
 | 
			
		||||
	0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, 
 | 
			
		||||
	0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, 
 | 
			
		||||
	0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, 
 | 
			
		||||
	0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, 
 | 
			
		||||
	0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, 
 | 
			
		||||
	0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, 
 | 
			
		||||
	0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D
 | 
			
		||||
};  
 | 
			
		||||
unsigned int crc = 0xFFFFFFFF;
 | 
			
		||||
  while (data_size--)
 | 
			
		||||
    {
 | 
			
		||||
      crc = (crc >> 8) ^ crc32_table[(crc ^ *data) & 255];
 | 
			
		||||
      data++;
 | 
			
		||||
    }
 | 
			
		||||
  return crc^0xFFFFFFFF;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
uint16_t crc16(uint8_t *data, uint32_t data_size)
 | 
			
		||||
{	
 | 
			
		||||
	/*Table of CRC values for high order byte*/
 | 
			
		||||
	static unsigned char auchCRCHi[]=
 | 
			
		||||
	{
 | 
			
		||||
			0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,
 | 
			
		||||
			0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,
 | 
			
		||||
			0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,
 | 
			
		||||
			0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,
 | 
			
		||||
			0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,
 | 
			
		||||
			0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,
 | 
			
		||||
			0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,
 | 
			
		||||
			0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,
 | 
			
		||||
			0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,
 | 
			
		||||
			0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,
 | 
			
		||||
			0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,
 | 
			
		||||
			0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,
 | 
			
		||||
			0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,
 | 
			
		||||
			0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,
 | 
			
		||||
			0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,
 | 
			
		||||
			0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,
 | 
			
		||||
	};
 | 
			
		||||
	/*Table of CRC values for low order byte*/
 | 
			
		||||
	static char auchCRCLo[] =
 | 
			
		||||
	{
 | 
			
		||||
					0x00,0xC0,0xC1,0x01,0xC3,0x03,0x02,0xC2,0xC6,0x06,0x07,0xC7,0x05,0xC5,0xC4,0x04,
 | 
			
		||||
					0xCC,0x0C,0x0D,0xCD,0x0F,0xCF,0xCE,0x0E,0x0A,0xCA,0xCB,0x0B,0xC9,0x09,0x08,0xC8,
 | 
			
		||||
					0xD8,0x18,0x19,0xD9,0x1B,0xDB,0xDA,0x1A,0x1E,0xDE,0xDF,0x1F,0xDD,0x1D,0x1C,0xDC,
 | 
			
		||||
					0x14,0xD4,0xD5,0x15,0xD7,0x17,0x16,0xD6,0xD2,0x12,0x13,0xD3,0x11,0xD1,0xD0,0x10,
 | 
			
		||||
					0xF0,0x30,0x31,0xF1,0x33,0xF3,0xF2,0x32,0x36,0xF6,0xF7,0x37,0xF5,0x35,0x34,0xF4,
 | 
			
		||||
					0x3C,0xFC,0xFD,0x3D,0xFF,0x3F,0x3E,0xFE,0xFA,0x3A,0x3B,0xFB,0x39,0xF9,0xF8,0x38,
 | 
			
		||||
					0x28,0xE8,0xE9,0x29,0xEB,0x2B,0x2A,0xEA,0xEE,0x2E,0x2F,0xEF,0x2D,0xED,0xEC,0x2C,
 | 
			
		||||
					0xE4,0x24,0x25,0xE5,0x27,0xE7,0xE6,0x26,0x22,0xE2,0xE3,0x23,0xE1,0x21,0x20,0xE0,
 | 
			
		||||
					0xA0,0x60,0x61,0xA1,0x63,0xA3,0xA2,0x62,0x66,0xA6,0xA7,0x67,0xA5,0x65,0x64,0xA4,
 | 
			
		||||
					0x6C,0xAC,0xAD,0x6D,0xAF,0x6F,0x6E,0xAE,0xAA,0x6A,0x6B,0xAB,0x69,0xA9,0xA8,0x68,
 | 
			
		||||
					0x78,0xB8,0xB9,0x79,0xBB,0x7B,0x7A,0xBA,0xBE,0x7E,0x7F,0xBF,0x7D,0xBD,0xBC,0x7C,
 | 
			
		||||
					0xB4,0x74,0x75,0xB5,0x77,0xB7,0xB6,0x76,0x72,0xB2,0xB3,0x73,0xB1,0x71,0x70,0xB0,
 | 
			
		||||
					0x50,0x90,0x91,0x51,0x93,0x53,0x52,0x92,0x96,0x56,0x57,0x97,0x55,0x95,0x94,0x54,
 | 
			
		||||
					0x9C,0x5C,0x5D,0x9D,0x5F,0x9F,0x9E,0x5E,0x5A,0x9A,0x9B,0x5B,0x99,0x59,0x58,0x98,
 | 
			
		||||
					0x88,0x48,0x49,0x89,0x4B,0x8B,0x8A,0x4A,0x4E,0x8E,0x8F,0x4F,0x8D,0x4D,0x4C,0x8C,
 | 
			
		||||
					0x44,0x84,0x85,0x45,0x87,0x47,0x46,0x86,0x82,0x42,0x43,0x83,0x41,0x81,0x80,0x40,
 | 
			
		||||
			};
 | 
			
		||||
	uchCRCHi = 0xFF;  
 | 
			
		||||
  uchCRCLo = 0xFF;   
 | 
			
		||||
    /* CRC Generation Function */
 | 
			
		||||
  while( data_size--) /* pass through message buffer */
 | 
			
		||||
  {
 | 
			
		||||
    uIndex = uchCRCHi ^ *data++; /* calculate the CRC */
 | 
			
		||||
    uchCRCHi = uchCRCLo ^ auchCRCHi[uIndex];
 | 
			
		||||
		uchCRCLo = auchCRCLo[uIndex];
 | 
			
		||||
  }
 | 
			
		||||
	return uchCRCHi | uchCRCLo<<8;
 | 
			
		||||
} 
 | 
			
		||||
							
								
								
									
										9
									
								
								diode_tester/Core/Interfaces/crc_algs.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								diode_tester/Core/Interfaces/crc_algs.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,9 @@
 | 
			
		||||
#include "mylibs_include.h"
 | 
			
		||||
 | 
			
		||||
// extern here to use in bootloader.c
 | 
			
		||||
extern uint32_t CRC_calc;
 | 
			
		||||
extern uint32_t CRC_ref;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
uint16_t crc16(uint8_t *data, uint32_t data_size);
 | 
			
		||||
uint32_t crc32(uint8_t *data, uint32_t data_size);
 | 
			
		||||
							
								
								
									
										125
									
								
								diode_tester/Core/Interfaces/interface_config.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										125
									
								
								diode_tester/Core/Interfaces/interface_config.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,125 @@
 | 
			
		||||
/**
 | 
			
		||||
**************************************************************************
 | 
			
		||||
* @file interface_config.h
 | 
			
		||||
* @brief Конфигурации для интерфейсов
 | 
			
		||||
**************************************************************************
 | 
			
		||||
  * @defgroup    INTERFACE_CONFIGS     Configs for interfaces
 | 
			
		||||
  * @brief       Конфигурации для интерфейсов
 | 
			
		||||
  * @details     
 | 
			
		||||
	@{
 | 
			
		||||
*************************************************************************/
 | 
			
		||||
#ifndef _INTERFACE_CONFIG_H_
 | 
			
		||||
#define _INTERFACE_CONFIG_H_
 | 
			
		||||
 | 
			
		||||
/** 
 | 
			
		||||
	* @addtogroup 		MODBUS_CONFIG   Конфигурации для модбас
 | 
			
		||||
	* @ingroup        INTERFACE_CONFIGS
 | 
			
		||||
	* @ingroup        MODBUS
 | 
			
		||||
	@{
 | 
			
		||||
	*/
 | 
			
		||||
 | 
			
		||||
#define MODBUS_UART_NUMB 							3							///< Номер используемого UART, по нему выставляется дефайн USED_MB_UART = USARTx
 | 
			
		||||
#define MODBUS_SPEED									115200			  ///< Скорость UART для модбас
 | 
			
		||||
#define MODBUS_GPIOX									GPIOB					///< Порт для UART RX/TX
 | 
			
		||||
#define MODBUS_GPIO_PIN_RX						GPIO_PIN_11		///< Пин для UART RX
 | 
			
		||||
#define MODBUS_GPIO_PIN_TX						GPIO_PIN_10		///< Пин для UART TX
 | 
			
		||||
 | 
			
		||||
#define MODBUS_TIM_NUMB 							7							///< number of used tim, accord to this define sets define USED_MB_TIM = TIMx 
 | 
			
		||||
#define MODBUS_TIM_AHB_FREQ						72						///< TIM AHB Bus Freq
 | 
			
		||||
 | 
			
		||||
// defines for modbus behaviour 
 | 
			
		||||
#define MODBUS_DEVICE_ID 							1			///< девайс текущего устройства
 | 
			
		||||
#define MODBUS_MAX_TIMEOUT 						5000 	///< максимальнйы тайтаут MB is ms
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#define RS_UART_Init                  MX_USART1_UART_Init
 | 
			
		||||
#define RS_UART_DeInit                HAL_UART_MspDeInit
 | 
			
		||||
#define RS_TIM_Init                   MX_TIM2_Init
 | 
			
		||||
#define RS_TIM_DeInit                 HAL_TIM_Base_MspDeInit
 | 
			
		||||
#define rs_huart                      huart1
 | 
			
		||||
#define rs_htim                       htim2
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/////////////////////////////////////////////////////////////////////
 | 
			
		||||
/////////////////////////---CALC DEFINES---//////////////////////////
 | 
			
		||||
 | 
			
		||||
/* set USART_TypeDef for choosen numb of usart */
 | 
			
		||||
#if (MODBUS_UART_NUMB == 1) 
 | 
			
		||||
	#define USED_MODBUS_UART					USART1 
 | 
			
		||||
	#define USE_USART1
 | 
			
		||||
#elif (MODBUS_UART_NUMB == 2)
 | 
			
		||||
	#define USED_MODBUS_UART					USART2 
 | 
			
		||||
	#define USE_USART2
 | 
			
		||||
#elif (MODBUS_UART_NUMB == 3)
 | 
			
		||||
	#define USED_MODBUS_UART					USART3 
 | 
			
		||||
	#define USE_USART3
 | 
			
		||||
#elif (MODBUS_UART_NUMB == 4)
 | 
			
		||||
	#define USED_MODBUS_UART					UART4 
 | 
			
		||||
	#define USE_UART4
 | 
			
		||||
#elif (MODBUS_UART_NUMB == 5)
 | 
			
		||||
	#define USED_MODBUS_UART					UART5
 | 
			
		||||
	#define USE_UART6
 | 
			
		||||
#elif (MODBUS_UART_NUMB == 6)
 | 
			
		||||
	#define USED_MODBUS_UART					USART6 
 | 
			
		||||
	#define USE_USART6
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if (MODBUS_TIM_NUMB == 1) 
 | 
			
		||||
	#define USED_MODBUS_TIM					TIM1 
 | 
			
		||||
	#define USE_TIM1
 | 
			
		||||
#elif (MODBUS_TIM_NUMB == 2)
 | 
			
		||||
	#define USED_MODBUS_TIM					TIM2 
 | 
			
		||||
	#define USE_TIM2
 | 
			
		||||
#elif (MODBUS_TIM_NUMB == 3)
 | 
			
		||||
	#define USED_MODBUS_TIM					TIM3 
 | 
			
		||||
	#define USE_TIM3
 | 
			
		||||
#elif (MODBUS_TIM_NUMB == 4)
 | 
			
		||||
	#define USED_MODBUS_TIM					TIM4 
 | 
			
		||||
	#define USE_TIM4
 | 
			
		||||
#elif (MODBUS_TIM_NUMB == 5)
 | 
			
		||||
	#define USED_MODBUS_TIM					TIM5
 | 
			
		||||
	#define USE_TIM5
 | 
			
		||||
#elif (MODBUS_TIM_NUMB == 6)
 | 
			
		||||
	#define USED_MODBUS_TIM					TIM6 
 | 
			
		||||
	#define USE_TIM6
 | 
			
		||||
#elif (MODBUS_TIM_NUMB == 7)
 | 
			
		||||
	#define USED_MODBUS_TIM					TIM7 
 | 
			
		||||
	#define USE_TIM7
 | 
			
		||||
#elif (MODBUS_TIM_NUMB == 8)
 | 
			
		||||
	#define USED_MODBUS_TIM					TIM8
 | 
			
		||||
	#define USE_TIM8 
 | 
			
		||||
#elif (MODBUS_TIM_NUMB == 9)
 | 
			
		||||
	#define USED_MODBUS_TIM					TIM9 
 | 
			
		||||
	#define USE_TIM9
 | 
			
		||||
#elif (MODBUS_TIM_NUMB == 10)
 | 
			
		||||
	#define USED_MODBUS_TIM					TIM10 
 | 
			
		||||
	#define USE_TIM10
 | 
			
		||||
#elif (MODBUS_TIM_NUMB == 11)
 | 
			
		||||
	#define USED_MODBUS_TIM					TIM11
 | 
			
		||||
	#define USE_TIM11
 | 
			
		||||
#elif (MODBUS_TIM_NUMB == 12)
 | 
			
		||||
	#define USED_MODBUS_TIM					TIM12 
 | 
			
		||||
	#define USE_TIM12
 | 
			
		||||
#elif (MODBUS_TIM_NUMB == 13)
 | 
			
		||||
	#define USED_MODBUS_TIM					TIM13 
 | 
			
		||||
	#define USE_TIM13
 | 
			
		||||
#elif (MODBUS_TIM_NUMB == 14)
 | 
			
		||||
	#define USED_MODBUS_TIM					TIM14 
 | 
			
		||||
	#define USE_TIM14
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/** MODBUS_CONFIG
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  
 | 
			
		||||
  
 | 
			
		||||
/** INTERFACE_CONFIGS
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
#endif //_INTERFACE_CONFIG_H_
 | 
			
		||||
							
								
								
									
										938
									
								
								diode_tester/Core/Interfaces/modbus.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										938
									
								
								diode_tester/Core/Interfaces/modbus.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,938 @@
 | 
			
		||||
/** 
 | 
			
		||||
**************************************************************************
 | 
			
		||||
* @file 	modbus.c
 | 
			
		||||
* @brief 	Модуль для реализации MODBUS.
 | 
			
		||||
**************************************************************************	
 | 
			
		||||
* @par Функции и дефайны
 | 
			
		||||
*
 | 
			
		||||
* Defines: data access
 | 
			
		||||
* 	- MB_Set_Coil_Local()						 			- Выставление коила по локальному адресу относительно начала массива
 | 
			
		||||
* 	- MB_Reset_Coil_Local()					 			- Сброс коила по локальному адресу относительно начала массива
 | 
			
		||||
* 	- MB_Toogle_Coil_Local()							- Переключение коила по локальному адресу относительно начала массива
 | 
			
		||||
* 	- MB_Read_Coil_Local()					 			- Чтение коила по локальному адресу относительно начала массива
 | 
			
		||||
*
 | 
			
		||||
* Functions: data access
 | 
			
		||||
* 	- MB_Write_Coil_Global()					 		- Запись 0/1 в один коил по глобальному адресу
 | 
			
		||||
* 	- MB_Read_Coil_Global()						 		- Чтение одного коила по глобальному адресу
 | 
			
		||||
* 
 | 
			
		||||
* Functions: process message
 | 
			
		||||
* 	- MB_DefineRegistersAddress() 		 		- Определение "начального" адреса регистров
 | 
			
		||||
* 	- MB_DefineCoilsAddress()					 		- Определение "начального" адреса коилов
 | 
			
		||||
* 	- MB_Check_Address_For_Arr() 			 		- Определение	принадлежит ли адресс Addr конкретному массиву
 | 
			
		||||
* 	- Обработка команд модбас
 | 
			
		||||
* 		- MB_Read_Coils(), 
 | 
			
		||||
*			- MB_Read_Hold_Regs(),
 | 
			
		||||
*			- MB_Write_Single_Coil()
 | 
			
		||||
*			- MB_Write_Miltuple_Coils()
 | 
			
		||||
*			- MB_Write_Miltuple_Regs()					
 | 
			
		||||
* 
 | 
			
		||||
* Functions: RS functions
 | 
			
		||||
* 	-	RS_Parse_Message() / RS_Collect_Message()	- Заполнение структуры сообщения и буфера
 | 
			
		||||
* 	-	RS_Response()  									 		- Ответ на комманду
 | 
			
		||||
* 	- RS_Define_Size_of_RX_Message()	 		- Определение размера принимаемых данных
 | 
			
		||||
* 	-	RS_Init()												 		- Инициализация периферии и modbus handler
 | 
			
		||||
* 
 | 
			
		||||
* Functions: initialization
 | 
			
		||||
* 	- MODBUS_FirstInit()									- Инициализация modbus
 | 
			
		||||
* 	
 | 
			
		||||
**************************************************************************	
 | 
			
		||||
* @par Данные для модбас
 | 
			
		||||
*
 | 
			
		||||
* Holding/Input Registers
 | 
			
		||||
* 	- Регистры представляют собой 16-битные числа (слова). В обработке комманд 
 | 
			
		||||
* 	находится адресс "начального" регистра и записывается в указатель. Доступ к 
 | 
			
		||||
* 	остальным регистрам осуществляется через указатель.	Таким образом, сами 
 | 
			
		||||
* 	регистры могут представлять собой как массив так и структуру.
 | 
			
		||||
* 
 | 
			
		||||
* Coils
 | 
			
		||||
*		- Коилы представляют собой биты, упакованные в 16-битные регистры. В обработке 
 | 
			
		||||
* 	комманд находится адресс "начального" регистра запрашиваемого коила. Доступ к 
 | 
			
		||||
* 	остальным коилам осуществляется через маску и указатель. Таким образом, сами 
 | 
			
		||||
* 	коилы могут представлять собой как массив так и структуру.
 | 
			
		||||
*
 | 
			
		||||
@verbatim
 | 
			
		||||
EXAMPLE: INIT SLAVE RECEIVE
 | 
			
		||||
  //--------------Настройка модбас--------------//		
 | 
			
		||||
  // set up UART for modbus
 | 
			
		||||
  modbus1_suart.huart.Instance = USED_MODBUS_UART;
 | 
			
		||||
  modbus1_suart.huart.Init.BaudRate = PROJSET.MB_SPEED;	
 | 
			
		||||
  modbus1_suart.GPIOx = GPIOB;
 | 
			
		||||
  modbus1_suart.GPIO_PIN_RX = GPIO_PIN_11;
 | 
			
		||||
  modbus1_suart.GPIO_PIN_TX = GPIO_PIN_10;
 | 
			
		||||
  
 | 
			
		||||
  // set up timeout TIM for modbus
 | 
			
		||||
  modbus1_stim.htim.Instance = TIM7;
 | 
			
		||||
  modbus1_stim.sTimAHBFreqMHz = 84;
 | 
			
		||||
  modbus1_stim.sTimMode = TIM_IT_CONF;
 | 
			
		||||
  
 | 
			
		||||
  // set up modbus: MB_RX_Size_NotConst and Timeout enable
 | 
			
		||||
  hmodbus1.ID = 1;
 | 
			
		||||
  hmodbus1.sRS_Timeout = 5000;
 | 
			
		||||
  hmodbus1.sRS_Mode = SLAVE_ALWAYS_WAIT;
 | 
			
		||||
  hmodbus1.sRS_RX_Size_Mode = RS_RX_Size_NotConst;
 | 
			
		||||
  
 | 
			
		||||
  // INIT
 | 
			
		||||
  hmodbus1.RS_STATUS = RS_Init(&hmodbus1, &modbus1_suart, &modbus1_stim, 0);	
 | 
			
		||||
  
 | 
			
		||||
  //----------------Прием модбас----------------//
 | 
			
		||||
  RS_MsgTypeDef MODBUS_MSG;
 | 
			
		||||
  RS_Receive_IT(&hmodbus1, &MODBUS_MSG);
 | 
			
		||||
@endverbatim
 | 
			
		||||
*************************************************************************/
 | 
			
		||||
 | 
			
		||||
#include "rs_message.h"
 | 
			
		||||
uint32_t dbg_temp, dbg_temp2, dbg_temp3; // for debug
 | 
			
		||||
/* MODBUS HANDLES */
 | 
			
		||||
#ifdef INCLUDE_GENERAL_PERIPH_LIBS
 | 
			
		||||
UART_SettingsTypeDef modbus1_suart;
 | 
			
		||||
TIM_SettingsTypeDef modbus1_stim;
 | 
			
		||||
#else
 | 
			
		||||
extern UART_HandleTypeDef rs_huart;
 | 
			
		||||
extern TIM_HandleTypeDef rs_htim;
 | 
			
		||||
#endif
 | 
			
		||||
RS_HandleTypeDef hmodbus1;
 | 
			
		||||
 | 
			
		||||
/* DEFINE REGISTERS/COILS */
 | 
			
		||||
MB_DataStructureTypeDef MB_DATA;
 | 
			
		||||
RS_MsgTypeDef MODBUS_MSG;
 | 
			
		||||
 | 
			
		||||
uint32_t  delay_scide = 1;
 | 
			
		||||
uint32_t  numb_scide = 10;
 | 
			
		||||
//-------------------------------------------------------------------
 | 
			
		||||
//-----------------------------FOR USER------------------------------
 | 
			
		||||
/** 
 | 
			
		||||
	* @brief 		First set up of MODBUS.
 | 
			
		||||
	* @details 	Первый инит модбас. Заполняет структуры и инициализирует таймер и юарт для общения по модбас.
 | 
			
		||||
	* 					Скважность ШИМ меняется по закону синусоиды, каждый канал генерирует свой полупериод синуса (от -1 до 0 И от 0 до 1)
 | 
			
		||||
	* 					ШИМ генерируется на одном канале.
 | 
			
		||||
	* @note			This called from main
 | 
			
		||||
	*/
 | 
			
		||||
void MODBUS_FirstInit(void)
 | 
			
		||||
{
 | 
			
		||||
	//-----------SETUP MODBUS-------------
 | 
			
		||||
	// set up UART for modbus
 | 
			
		||||
#ifdef INCLUDE_GENERAL_PERIPH_LIBS
 | 
			
		||||
	modbus1_suart.huart.Instance = USED_MODBUS_UART;
 | 
			
		||||
	modbus1_suart.huart.Init.BaudRate = MODBUS_SPEED;	
 | 
			
		||||
	modbus1_suart.GPIOx = MODBUS_GPIOX;
 | 
			
		||||
	modbus1_suart.GPIO_PIN_RX = MODBUS_GPIO_PIN_RX;
 | 
			
		||||
	modbus1_suart.GPIO_PIN_TX = MODBUS_GPIO_PIN_TX;
 | 
			
		||||
	
 | 
			
		||||
	// set up timeout TIM for modbus
 | 
			
		||||
	modbus1_stim.htim.Instance = USED_MODBUS_TIM;
 | 
			
		||||
	modbus1_stim.sTimAHBFreqMHz = MODBUS_TIM_AHB_FREQ;
 | 
			
		||||
	modbus1_stim.sTimMode = TIM_IT_CONF;
 | 
			
		||||
	
 | 
			
		||||
#endif
 | 
			
		||||
	// set up modbus: MB_RX_Size_NotConst and Timeout enable
 | 
			
		||||
	hmodbus1.ID = MODBUS_DEVICE_ID;
 | 
			
		||||
	hmodbus1.sRS_Timeout = MODBUS_MAX_TIMEOUT;
 | 
			
		||||
	hmodbus1.sRS_Mode = SLAVE_ALWAYS_WAIT;
 | 
			
		||||
	hmodbus1.sRS_RX_Size_Mode = RS_RX_Size_NotConst;
 | 
			
		||||
	
 | 
			
		||||
	// INIT
 | 
			
		||||
#ifdef INCLUDE_GENERAL_PERIPH_LIBS
 | 
			
		||||
	hmodbus1.RS_STATUS = RS_Init(&hmodbus1, &modbus1_suart, &modbus1_stim, 0);	
 | 
			
		||||
#else
 | 
			
		||||
  hmodbus1.RS_STATUS = RS_Init(&hmodbus1, &rs_huart, &rs_htim, 0);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
	RS_EnableReceive();
 | 
			
		||||
}
 | 
			
		||||
/** 
 | 
			
		||||
	* @brief 		Set or Reset Coil at its global address.
 | 
			
		||||
	* @param 		Addr 					- адрес коила.
 | 
			
		||||
	* @param 		WriteVal 			- Что записать в коил: 0 или 1.
 | 
			
		||||
	* @return 	ExceptionCode	- Код исключения если коила по адресу не существует, и NO_ERRORS если все ок.
 | 
			
		||||
	*
 | 
			
		||||
  * @details 	Позволяет обратиться к любому коилу по его глобальному адрессу.
 | 
			
		||||
							Вне зависимости от того как коилы размещены в памяти.
 | 
			
		||||
	*/
 | 
			
		||||
MB_ExceptionTypeDef MB_Write_Coil_Global(uint16_t Addr, MB_CoilsOpTypeDef WriteVal)
 | 
			
		||||
{
 | 
			
		||||
	//---------CHECK FOR ERRORS----------
 | 
			
		||||
	MB_ExceptionTypeDef Exception = NO_ERRORS;
 | 
			
		||||
	uint16_t *coils;
 | 
			
		||||
	uint16_t start_shift = 0; // shift in coils register
 | 
			
		||||
	
 | 
			
		||||
	//------------WRITE COIL-------------
 | 
			
		||||
	Exception = MB_DefineCoilsAddress(&coils, Addr, 1, &start_shift, 1);
 | 
			
		||||
	if(Exception == NO_ERRORS)
 | 
			
		||||
	{
 | 
			
		||||
		switch(WriteVal)
 | 
			
		||||
		{
 | 
			
		||||
			case SET_COIL:
 | 
			
		||||
				*coils |= (1<<start_shift);				
 | 
			
		||||
				break;
 | 
			
		||||
				
 | 
			
		||||
			case RESET_COIL:
 | 
			
		||||
				*coils &= ~(1<<start_shift);					
 | 
			
		||||
				break;
 | 
			
		||||
				
 | 
			
		||||
			case TOOGLE_COIL:
 | 
			
		||||
				*coils ^= (1<<start_shift);						
 | 
			
		||||
				break;
 | 
			
		||||
			
 | 
			
		||||
		}		
 | 
			
		||||
	}
 | 
			
		||||
	return Exception;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/** 
 | 
			
		||||
	* @brief 		Read Coil at its global address.
 | 
			
		||||
	* @param 		Addr 					- адрес коила.
 | 
			
		||||
	* @param 		Exception 		- Указатель на переменную для кода исключения, в случа неудачи при чтении.
 | 
			
		||||
	* @return 	uint16_t			- Возвращает весь регистр с маской на запрошенном коиле.
 | 
			
		||||
	*
 | 
			
		||||
  * @details 	Позволяет обратиться к любому коилу по его глобальному адрессу.
 | 
			
		||||
							Вне зависимости от того как коилы размещены в памяти.
 | 
			
		||||
	*/
 | 
			
		||||
uint16_t MB_Read_Coil_Global(uint16_t Addr, MB_ExceptionTypeDef *Exception)
 | 
			
		||||
{
 | 
			
		||||
	//---------CHECK FOR ERRORS----------
 | 
			
		||||
	MB_ExceptionTypeDef Exception_tmp;
 | 
			
		||||
	if(Exception == NULL)							// if exception is not given to func fill it
 | 
			
		||||
		Exception = &Exception_tmp;
 | 
			
		||||
		
 | 
			
		||||
	uint16_t *coils;
 | 
			
		||||
	uint16_t start_shift = 0; // shift in coils register
 | 
			
		||||
	
 | 
			
		||||
	//------------READ COIL--------------
 | 
			
		||||
	*Exception = MB_DefineCoilsAddress(&coils, Addr, 1, &start_shift, 0);	
 | 
			
		||||
	if(*Exception == NO_ERRORS)
 | 
			
		||||
	{
 | 
			
		||||
		return ((*coils)&(1<<start_shift));
 | 
			
		||||
	}
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
		return 0;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//-------------------------------------------------------------------
 | 
			
		||||
//----------------FUNCTIONS FOR PROCESSING MESSAGE-------------------
 | 
			
		||||
/** 
 | 
			
		||||
	* @brief 		Check is address valid for certain array.
 | 
			
		||||
	* @param 		Addr 					- начальный адресс.
 | 
			
		||||
	* @param 		Qnt 					- количество запрашиваемых элементов.
 | 
			
		||||
	* @param 		R_ARR_ADDR 		- начальный адресс массива R_ARR.
 | 
			
		||||
	* @param 		R_ARR_NUMB 		- количество элементов в массиве R_ARR.
 | 
			
		||||
	* @return 	ExceptionCode	- ILLEGAL DATA ADRESS если адресс недействителен, и NO_ERRORS если все ок.
 | 
			
		||||
	*
 | 
			
		||||
	* @details 	Позволяет определить, принадлежит ли адресс Addr массиву R_ARR:
 | 
			
		||||
	*						Если адресс Addr находится в диапазоне адрессов массива R_ARR, то возвращаем NO_ERROR.
 | 
			
		||||
	*						Если адресс Addr находится за пределами адрессов массива R_ARR - ILLEGAL_DATA_ADDRESSю.
 | 
			
		||||
	*/
 | 
			
		||||
MB_ExceptionTypeDef MB_Check_Address_For_Arr(uint16_t Addr, uint16_t Qnt, uint16_t R_ARR_ADDR, uint16_t R_ARR_NUMB)
 | 
			
		||||
{
 | 
			
		||||
	// if address from this array
 | 
			
		||||
	if(Addr >= R_ARR_ADDR) 
 | 
			
		||||
	{		
 | 
			
		||||
		// if quantity too big return error
 | 
			
		||||
		if ((Addr - R_ARR_ADDR) + Qnt > R_ARR_NUMB) 
 | 
			
		||||
		{
 | 
			
		||||
			return ILLEGAL_DATA_ADDRESS;	// return exception code
 | 
			
		||||
		}
 | 
			
		||||
		// if all ok - return no errors
 | 
			
		||||
		return NO_ERRORS;
 | 
			
		||||
	}
 | 
			
		||||
	// if address isnt from this array return error
 | 
			
		||||
	else 
 | 
			
		||||
		return ILLEGAL_DATA_ADDRESS;	// return exception code		
 | 
			
		||||
}
 | 
			
		||||
/** 
 | 
			
		||||
	* @brief 		Define Address Origin for Input/Holding Registers
 | 
			
		||||
	* @param 		pRegs 				- указатель на указатель регистров.
 | 
			
		||||
	* @param 		Addr 					- адрес начального регистра.
 | 
			
		||||
	* @param 		Qnt 					- количество запрашиваемых регистров.
 | 
			
		||||
	* @param 		WriteFlag 		- флаг регистр нужны для чтения или записи.
 | 
			
		||||
	* @return 	ExceptionCode	- Код исключения если есть, и NO_ERRORS если нет.
 | 
			
		||||
	*
 | 
			
		||||
  * @details 	Определение адреса начального регистра.
 | 
			
		||||
	* @note 		WriteFlag пока не используется.
 | 
			
		||||
	*/
 | 
			
		||||
MB_ExceptionTypeDef MB_DefineRegistersAddress(uint16_t **pRegs, uint16_t Addr, uint16_t Qnt, uint8_t RegisterType)
 | 
			
		||||
{	
 | 
			
		||||
	/* check quantity error */
 | 
			
		||||
	if (Qnt > 125)	
 | 
			
		||||
	{		
 | 
			
		||||
			return ILLEGAL_DATA_VALUE;	// return exception code
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	if(RegisterType == RegisterType_Holding)
 | 
			
		||||
	{
 | 
			
		||||
		// Устаки для напряжений ТЭ: предупреждения аварии
 | 
			
		||||
		if(MB_Check_Address_For_Arr(Addr, Qnt, R_SETPOINTS_ADDR, R_SETPOINTS_QNT) == NO_ERRORS)
 | 
			
		||||
		{
 | 
			
		||||
			*pRegs = MB_Set_Register_Ptr(&MB_DATA.HoldRegs, Addr);	// начало регистров хранения/входных
 | 
			
		||||
		}
 | 
			
		||||
		// Устаки для настройки МЗКТЭ: запрет опроса и настройки общения (MODBUS/UART)
 | 
			
		||||
		else if(MB_Check_Address_For_Arr(Addr, Qnt, R_SETTINGS_ADDR, R_SETTINGS_QNT) == NO_ERRORS)
 | 
			
		||||
		{
 | 
			
		||||
			*pRegs = MB_Set_Register_Ptr(&MB_DATA.HoldRegs, Addr);	// начало регистров хранения/входных
 | 
			
		||||
		}
 | 
			
		||||
		// if address doesnt match any array - return illegal data address response
 | 
			
		||||
		else	
 | 
			
		||||
		{
 | 
			
		||||
			return ILLEGAL_DATA_ADDRESS;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	else if(RegisterType == RegisterType_Input)
 | 
			
		||||
	{
 | 
			
		||||
		// Напряжения на ТЭ
 | 
			
		||||
		if(MB_Check_Address_For_Arr(Addr, Qnt, R_TE_VOLTAGE_ADDR, R_TE_VOLTAGE_QNT) == NO_ERRORS)
 | 
			
		||||
		{
 | 
			
		||||
			*pRegs = MB_Set_Register_Ptr(&MB_DATA.InRegs, Addr);	// начало регистров хранения/входных
 | 
			
		||||
		}
 | 
			
		||||
		// Статус регистр МЗКТЭ
 | 
			
		||||
		else if(MB_Check_Address_For_Arr(Addr, Qnt, R_STATUS_REG_ADDR, R_STATUS_REG_QNT) == NO_ERRORS)
 | 
			
		||||
		{
 | 
			
		||||
			*pRegs = MB_Set_Register_Ptr(&MB_DATA.InRegs, Addr);	// начало регистров хранения/входных
 | 
			
		||||
		}
 | 
			
		||||
		// if address doesnt match any array - return illegal data address response
 | 
			
		||||
		else	
 | 
			
		||||
		{
 | 
			
		||||
			return ILLEGAL_DATA_ADDRESS;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
			return ILLEGAL_FUNCTION;
 | 
			
		||||
	}
 | 
			
		||||
	// if found requeried array return no err
 | 
			
		||||
	return NO_ERRORS; // return no errors
 | 
			
		||||
}
 | 
			
		||||
/** 
 | 
			
		||||
	* @brief 		Define Address Origin for coils
 | 
			
		||||
	* @param 		pCoils 				- указатель на указатель коилов.
 | 
			
		||||
	* @param 		Addr 					- адресс начального коила.
 | 
			
		||||
	* @param 		Qnt 					- количество запрашиваемых коилов.
 | 
			
		||||
	* @param 		start_shift 	- указатель на переменную содержащую сдвиг внутри регистра для начального коила.
 | 
			
		||||
	* @param 		WriteFlag 		- флаг коилы нужны для чтения или записи.
 | 
			
		||||
	* @return 	ExceptionCode	- Код исключения если есть, и NO_ERRORS если нет.
 | 
			
		||||
	*
 | 
			
		||||
  * @details	Определение адреса начального регистра запрашиваемых коилов.
 | 
			
		||||
	* @note 		WriteFlag используется для определния регистров GPIO: ODR или IDR.
 | 
			
		||||
	*/
 | 
			
		||||
MB_ExceptionTypeDef MB_DefineCoilsAddress(uint16_t **pCoils, uint16_t Addr, uint16_t Qnt, uint16_t *start_shift, uint8_t WriteFlag)
 | 
			
		||||
{	
 | 
			
		||||
	/* check quantity error */
 | 
			
		||||
	if (Qnt > 2000)	
 | 
			
		||||
	{
 | 
			
		||||
		return ILLEGAL_DATA_VALUE;	// return exception code
 | 
			
		||||
	}
 | 
			
		||||
		
 | 
			
		||||
	// peripheral control coils
 | 
			
		||||
	if(MB_Check_Address_For_Arr(Addr, Qnt, C_TE_EXCLUDE_ADDR, C_TE_EXCLUDE_QNT) == NO_ERRORS)
 | 
			
		||||
	{
 | 
			
		||||
		*pCoils = MB_Set_Coil_Reg_Ptr(&MB_DATA.Coils, Addr-C_TE_EXCLUDE_ADDR);
 | 
			
		||||
	}
 | 
			
		||||
	// if address doesnt match any array - return illegal data address response
 | 
			
		||||
	else	
 | 
			
		||||
	{
 | 
			
		||||
		return ILLEGAL_DATA_ADDRESS;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	*start_shift = Addr % 16;	// set shift to requested coil
 | 
			
		||||
	// if found requeried array return no err
 | 
			
		||||
	return NO_ERRORS;	// return no errors
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/** 
 | 
			
		||||
	* @brief 		Proccess command Read Coils (01 - 0x01).
 | 
			
		||||
	* @param 		modbus_msg 				- указатель на структуру собщения modbus.
 | 
			
		||||
	* @return 	fMessageHandled		- статус о результате обработки комманды.
 | 
			
		||||
	* @details 	Обработка команды Read Coils.
 | 
			
		||||
	*/
 | 
			
		||||
uint8_t MB_Read_Coils(RS_MsgTypeDef *modbus_msg)
 | 
			
		||||
{
 | 
			
		||||
	//---------CHECK FOR ERRORS----------
 | 
			
		||||
	uint16_t *coils;
 | 
			
		||||
	uint16_t start_shift = 0; // shift in coils register
 | 
			
		||||
	
 | 
			
		||||
	modbus_msg->Except_Code = MB_DefineCoilsAddress(&coils, modbus_msg->Addr, modbus_msg->Qnt, &start_shift, 0);
 | 
			
		||||
	if(modbus_msg->Except_Code != NO_ERRORS)
 | 
			
		||||
		return 0;
 | 
			
		||||
	
 | 
			
		||||
	//-----------READING COIL------------
 | 
			
		||||
	// setup output message data size	
 | 
			
		||||
	modbus_msg->ByteCnt = Divide_Up(modbus_msg->Qnt, 8);
 | 
			
		||||
	// create mask for coils
 | 
			
		||||
	uint16_t mask_for_coils = 0;	// mask for coils that've been chosen
 | 
			
		||||
	uint16_t setted_coils = 0;		// value of setted coils
 | 
			
		||||
	uint16_t temp_reg = 0;				// temp register for saving coils that hasnt been chosen
 | 
			
		||||
	uint16_t coil_cnt = 0;				// counter for processed coils
 | 
			
		||||
 | 
			
		||||
	// cycle until all registers with requered coils would be processed
 | 
			
		||||
	int shift = start_shift; 	// set shift to first coil in first register
 | 
			
		||||
	int ind = 0;							// index for coils registers and data
 | 
			
		||||
	for(; ind <= Divide_Up(start_shift + modbus_msg->Qnt, 16); ind++)
 | 
			
		||||
	{ 
 | 
			
		||||
		//----SET MASK FOR COILS REGISTER----
 | 
			
		||||
		mask_for_coils = 0;
 | 
			
		||||
		for(; shift < 0x10; shift++)
 | 
			
		||||
		{
 | 
			
		||||
			mask_for_coils |= 1<<(shift); // choose certain coil
 | 
			
		||||
			if(++coil_cnt >= modbus_msg->Qnt)
 | 
			
		||||
				break;
 | 
			
		||||
		}
 | 
			
		||||
		shift = 0; // set shift to zero for the next step
 | 
			
		||||
	
 | 
			
		||||
		//-----------READ COILS--------------
 | 
			
		||||
		modbus_msg->DATA[ind] = (*(coils+ind)&mask_for_coils) >> start_shift;
 | 
			
		||||
		if(ind > 0)
 | 
			
		||||
			modbus_msg->DATA[ind-1] |= ((*(coils+ind)&mask_for_coils) << 16) >> start_shift;
 | 
			
		||||
			
 | 
			
		||||
	}
 | 
			
		||||
	// т.к. DATA 16-битная, для 8-битной передачи, надо поменять местами верхний и нижний байты
 | 
			
		||||
	for(; ind >= 0; --ind)	
 | 
			
		||||
		modbus_msg->DATA[ind] = ByteSwap16(modbus_msg->DATA[ind]);
 | 
			
		||||
	
 | 
			
		||||
	return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
	* @brief 		Proccess command Read Holding Registers (03 - 0x03).
 | 
			
		||||
	* @param 		modbus_msg 				- указатель на структуру собщения modbus.
 | 
			
		||||
	* @return 	fMessageHandled		- статус о результате обработки комманды.
 | 
			
		||||
	* @details 	Обработка команды Read Holding Registers.
 | 
			
		||||
	*/
 | 
			
		||||
uint8_t MB_Read_Hold_Regs(RS_MsgTypeDef *modbus_msg)
 | 
			
		||||
{
 | 
			
		||||
	//---------CHECK FOR ERRORS----------	
 | 
			
		||||
	// get origin address for data
 | 
			
		||||
	uint16_t *pHoldRegs; 			
 | 
			
		||||
	modbus_msg->Except_Code = MB_DefineRegistersAddress(&pHoldRegs, modbus_msg->Addr, modbus_msg->Qnt, RegisterType_Holding);	// определение адреса регистров
 | 
			
		||||
	if(modbus_msg->Except_Code != NO_ERRORS)
 | 
			
		||||
		return 0;
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
	//-----------READING REGS------------
 | 
			
		||||
	// setup output message data size	
 | 
			
		||||
	modbus_msg->ByteCnt = modbus_msg->Qnt*2; // *2 because we transmit 8 bits, not 16 bits
 | 
			
		||||
	// read data
 | 
			
		||||
	int i;
 | 
			
		||||
	for (i = 0; i<modbus_msg->Qnt; i++)
 | 
			
		||||
	{
 | 
			
		||||
		modbus_msg->DATA[i]	= *(pHoldRegs++);
 | 
			
		||||
	}	
 | 
			
		||||
	return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
	* @brief 		Proccess command Read Input Registers (04 - 0x04).
 | 
			
		||||
	* @param 		modbus_msg 				- указатель на структуру собщения modbus.
 | 
			
		||||
	* @return 	fMessageHandled		- статус о результате обработки комманды.
 | 
			
		||||
	* @details 	Обработка команды Read Input Registers.
 | 
			
		||||
	*/
 | 
			
		||||
uint8_t MB_Read_Input_Regs(RS_MsgTypeDef *modbus_msg)
 | 
			
		||||
{
 | 
			
		||||
	//---------CHECK FOR ERRORS----------	
 | 
			
		||||
	// get origin address for data
 | 
			
		||||
	uint16_t *pInRegs; 			
 | 
			
		||||
	modbus_msg->Except_Code = MB_DefineRegistersAddress(&pInRegs, modbus_msg->Addr, modbus_msg->Qnt, RegisterType_Input);	// определение адреса регистров
 | 
			
		||||
	if(modbus_msg->Except_Code != NO_ERRORS)
 | 
			
		||||
		return 0;
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
	//-----------READING REGS------------
 | 
			
		||||
	// setup output message data size	
 | 
			
		||||
	modbus_msg->ByteCnt = modbus_msg->Qnt*2; // *2 because we transmit 8 bits, not 16 bits
 | 
			
		||||
	// read data
 | 
			
		||||
	int i;
 | 
			
		||||
	for (i = 0; i<modbus_msg->Qnt; i++)
 | 
			
		||||
	{
 | 
			
		||||
    if(*((int16_t *)pInRegs) > 0)
 | 
			
		||||
      modbus_msg->DATA[i]	= (*pInRegs++);
 | 
			
		||||
    else
 | 
			
		||||
      modbus_msg->DATA[i]	= (*pInRegs++);
 | 
			
		||||
	}	
 | 
			
		||||
	return 1;
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
	* @brief 		Proccess command Write Single Coils (05 - 0x05).
 | 
			
		||||
	* @param 		modbus_msg 				- указатель на структуру собщения modbus.
 | 
			
		||||
	* @return 	fMessageHandled		- статус о результате обработки комманды.
 | 
			
		||||
	* @details 	Обработка команды Write Single Coils.
 | 
			
		||||
	*/
 | 
			
		||||
uint8_t MB_Write_Single_Coil(RS_MsgTypeDef *modbus_msg)
 | 
			
		||||
{
 | 
			
		||||
	//---------CHECK FOR ERRORS----------
 | 
			
		||||
	if ((modbus_msg->Qnt != 0x0000) && (modbus_msg->Qnt != 0xFF00))
 | 
			
		||||
	{
 | 
			
		||||
		modbus_msg->Except_Code = ILLEGAL_DATA_VALUE;
 | 
			
		||||
		return 0;
 | 
			
		||||
	}		
 | 
			
		||||
	// define position of coil
 | 
			
		||||
	uint16_t *coils;
 | 
			
		||||
	uint16_t start_shift = 0; // shift in coils register
 | 
			
		||||
	modbus_msg->Except_Code = MB_DefineCoilsAddress(&coils, modbus_msg->Addr, 0, &start_shift, 1);
 | 
			
		||||
	if(modbus_msg->Except_Code != NO_ERRORS)
 | 
			
		||||
		return 0;
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
	//----------WRITTING COIL------------
 | 
			
		||||
	if(modbus_msg->Qnt == 0xFF00)
 | 
			
		||||
		*(coils) |= 1<<start_shift; // write flags corresponding to received data
 | 
			
		||||
	else
 | 
			
		||||
		*(coils) &= ~(1<<start_shift); // write flags corresponding to received data
 | 
			
		||||
	
 | 
			
		||||
	return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
	* @brief 		Proccess command Write Single Register (06 - 0x06).
 | 
			
		||||
	* @param 		modbus_msg 				- указатель на структуру собщения modbus.
 | 
			
		||||
	* @return 	fMessageHandled		- статус о результате обработки комманды.
 | 
			
		||||
	* @details 	Обработка команды Write Single Register.
 | 
			
		||||
	*/
 | 
			
		||||
uint8_t MB_Write_Single_Reg(RS_MsgTypeDef *modbus_msg)
 | 
			
		||||
{	
 | 
			
		||||
	// get origin address for data
 | 
			
		||||
	uint16_t *pHoldRegs; 			
 | 
			
		||||
	modbus_msg->Except_Code = MB_DefineRegistersAddress(&pHoldRegs, modbus_msg->Addr, 1, RegisterType_Holding);	// определение адреса регистров
 | 
			
		||||
	if(modbus_msg->Except_Code != NO_ERRORS)
 | 
			
		||||
		return 0;
 | 
			
		||||
	
 | 
			
		||||
	//-----------WRITTING REG------------	
 | 
			
		||||
	*(pHoldRegs) = modbus_msg->Qnt;
 | 
			
		||||
	return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
	* @brief 		Proccess command Write Multiple Coils (15 - 0x0F).
 | 
			
		||||
	* @param 		modbus_msg 			- указатель на структуру собщения modbus.
 | 
			
		||||
	* @return 	fMessageHandled	- статус о результате обработки комманды.
 | 
			
		||||
	* @details 	Обработка команды Write Multiple Coils.
 | 
			
		||||
	*/
 | 
			
		||||
uint8_t MB_Write_Miltuple_Coils(RS_MsgTypeDef *modbus_msg)
 | 
			
		||||
{
 | 
			
		||||
	//---------CHECK FOR ERRORS----------
 | 
			
		||||
	if (modbus_msg->ByteCnt != Divide_Up(modbus_msg->Qnt, 8))
 | 
			
		||||
	{ // if quantity too large OR if quantity and bytes count arent match
 | 
			
		||||
		modbus_msg->Except_Code = ILLEGAL_DATA_VALUE;
 | 
			
		||||
		return 0;
 | 
			
		||||
	}	
 | 
			
		||||
	// define position of coil
 | 
			
		||||
	uint16_t *coils;					// pointer to coils
 | 
			
		||||
	uint16_t start_shift = 0; // shift in coils register
 | 
			
		||||
	modbus_msg->Except_Code = MB_DefineCoilsAddress(&coils, modbus_msg->Addr, modbus_msg->Qnt, &start_shift, 1);
 | 
			
		||||
	if(modbus_msg->Except_Code != NO_ERRORS)
 | 
			
		||||
		return 0;
 | 
			
		||||
	
 | 
			
		||||
	//----------WRITTING COILS-----------
 | 
			
		||||
	// create mask for coils
 | 
			
		||||
	uint16_t mask_for_coils = 0;	// mask for coils that've been chosen
 | 
			
		||||
	uint32_t setted_coils = 0;		// value of setted coils
 | 
			
		||||
	uint16_t temp_reg = 0;				// temp register for saving coils that hasnt been chosen
 | 
			
		||||
	uint16_t coil_cnt = 0;				// counter for processed coils
 | 
			
		||||
 | 
			
		||||
	// cycle until all registers with requered coils would be processed
 | 
			
		||||
	int shift = start_shift; // set shift to first coil in first register
 | 
			
		||||
	for(int ind = 0; ind <= Divide_Up(start_shift + modbus_msg->Qnt, 16); ind++)
 | 
			
		||||
	{ 
 | 
			
		||||
		//----SET MASK FOR COILS REGISTER----
 | 
			
		||||
		mask_for_coils = 0;
 | 
			
		||||
		for(; shift < 0x10; shift++)
 | 
			
		||||
		{
 | 
			
		||||
			mask_for_coils |= 1<<(shift); // choose certain coil
 | 
			
		||||
			if(++coil_cnt >= modbus_msg->Qnt)
 | 
			
		||||
				break;
 | 
			
		||||
		}
 | 
			
		||||
		shift = 0; // set shift to zero for the next step
 | 
			
		||||
		
 | 
			
		||||
		
 | 
			
		||||
		
 | 
			
		||||
		//-----------WRITE COILS-------------
 | 
			
		||||
		// get current coils
 | 
			
		||||
		temp_reg = *(coils+ind);
 | 
			
		||||
		// set coils
 | 
			
		||||
		setted_coils = ByteSwap16(modbus_msg->DATA[ind]) << start_shift;
 | 
			
		||||
		if(ind > 0)
 | 
			
		||||
		{
 | 
			
		||||
			setted_coils |= ((ByteSwap16(modbus_msg->DATA[ind-1]) << start_shift) >> 16);
 | 
			
		||||
		}
 | 
			
		||||
		// write coils
 | 
			
		||||
			
 | 
			
		||||
		*(coils+ind) = setted_coils & mask_for_coils;		
 | 
			
		||||
		 // restore untouched coils
 | 
			
		||||
		*(coils+ind) |= temp_reg&(~mask_for_coils);
 | 
			
		||||
		
 | 
			
		||||
		
 | 
			
		||||
		if(coil_cnt >= modbus_msg->Qnt) // if all coils written - break cycle
 | 
			
		||||
			break;												// *kind of unnecessary
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
	* @brief 		Proccess command Write Multiple Registers (16 - 0x10).
 | 
			
		||||
	* @param 		modbus_msg 				- указатель на структуру собщения modbus.
 | 
			
		||||
	* @return 	fMessageHandled		- статус о результате обработки комманды.
 | 
			
		||||
	* @details 	Обработка команды Write Multiple Registers.
 | 
			
		||||
	*/
 | 
			
		||||
uint8_t MB_Write_Miltuple_Regs(RS_MsgTypeDef *modbus_msg)
 | 
			
		||||
{
 | 
			
		||||
	//---------CHECK FOR ERRORS----------
 | 
			
		||||
	if (modbus_msg->Qnt*2 != modbus_msg->ByteCnt)
 | 
			
		||||
	{ // if quantity and bytes count arent match
 | 
			
		||||
		modbus_msg->Except_Code = 3;
 | 
			
		||||
		return 0;
 | 
			
		||||
	}	
 | 
			
		||||
	// get origin address for data
 | 
			
		||||
	uint16_t *pHoldRegs; 			
 | 
			
		||||
	modbus_msg->Except_Code = MB_DefineRegistersAddress(&pHoldRegs, modbus_msg->Addr, modbus_msg->Qnt, RegisterType_Holding);	// определение адреса регистров
 | 
			
		||||
	if(modbus_msg->Except_Code != NO_ERRORS)
 | 
			
		||||
		return 0;
 | 
			
		||||
	
 | 
			
		||||
	//-----------WRITTING REGS-----------	
 | 
			
		||||
	for (int i = 0; i<modbus_msg->Qnt; i++)
 | 
			
		||||
	{
 | 
			
		||||
		*(pHoldRegs++) = modbus_msg->DATA[i];
 | 
			
		||||
	}
 | 
			
		||||
	return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/** 
 | 
			
		||||
	* @brief 		Respond accord to received message.
 | 
			
		||||
	* @param 		hRS 		- указатель на хендлер RS.
 | 
			
		||||
	* @param 		RS_msg 	- указатель на структуру сообщения.
 | 
			
		||||
	* @return 	RS_RES	- статус о результате ответа на комманду.
 | 
			
		||||
	* @details		Обработка принятой комманды и ответ на неё.
 | 
			
		||||
	*/
 | 
			
		||||
RS_StatusTypeDef RS_Response(RS_HandleTypeDef *hmodbus, RS_MsgTypeDef *modbus_msg)
 | 
			
		||||
{
 | 
			
		||||
	RS_StatusTypeDef MB_RES = 0;
 | 
			
		||||
	hmodbus->f.MessageHandled = 0;
 | 
			
		||||
	hmodbus->f.EchoResponse = 0;
 | 
			
		||||
	RS_Reset_TX_Flags(hmodbus);			// reset flag for correct transmit
 | 
			
		||||
	
 | 
			
		||||
	if(modbus_msg->Func_Code < ERR_VALUES_START)// if no errors after parsing
 | 
			
		||||
	{
 | 
			
		||||
		switch (modbus_msg->Func_Code)
 | 
			
		||||
		{
 | 
			
		||||
			// Read Coils
 | 
			
		||||
			case MB_R_COILS: 
 | 
			
		||||
				hmodbus->f.MessageHandled = 	MB_Read_Coils(hmodbus->pMessagePtr);
 | 
			
		||||
				break;
 | 
			
		||||
			
 | 
			
		||||
			// Read Hodling Registers
 | 
			
		||||
			case MB_R_HOLD_REGS:
 | 
			
		||||
				hmodbus->f.MessageHandled = 	MB_Read_Hold_Regs(hmodbus->pMessagePtr);
 | 
			
		||||
				break;
 | 
			
		||||
			case MB_R_IN_REGS: 
 | 
			
		||||
				hmodbus->f.MessageHandled = 	MB_Read_Input_Regs(hmodbus->pMessagePtr);
 | 
			
		||||
				break;
 | 
			
		||||
			
 | 
			
		||||
			
 | 
			
		||||
			// Write Single Coils
 | 
			
		||||
			case MB_W_COIL: 
 | 
			
		||||
				hmodbus->f.MessageHandled =	MB_Write_Single_Coil(hmodbus->pMessagePtr);	
 | 
			
		||||
				if(hmodbus->f.MessageHandled) 
 | 
			
		||||
				{
 | 
			
		||||
					hmodbus->f.EchoResponse = 1; 
 | 
			
		||||
					hmodbus->RS_Message_Size -= 2; // echo response if write ok (minus 2 cause of two CRC bytes)
 | 
			
		||||
				}
 | 
			
		||||
				break;
 | 
			
		||||
			
 | 
			
		||||
			case MB_W_HOLD_REG: 	
 | 
			
		||||
				hmodbus->f.MessageHandled =	MB_Write_Single_Reg(hmodbus->pMessagePtr);	
 | 
			
		||||
				if(hmodbus->f.MessageHandled) 
 | 
			
		||||
				{
 | 
			
		||||
					hmodbus->f.EchoResponse = 1;
 | 
			
		||||
					hmodbus->RS_Message_Size -= 2; // echo response if write ok (minus 2 cause of two CRC bytes)
 | 
			
		||||
				}
 | 
			
		||||
				break;
 | 
			
		||||
			
 | 
			
		||||
			// Write Multiple Coils
 | 
			
		||||
			case MB_W_COILS: 
 | 
			
		||||
				hmodbus->f.MessageHandled = 	MB_Write_Miltuple_Coils(hmodbus->pMessagePtr);
 | 
			
		||||
				if(hmodbus->f.MessageHandled) 
 | 
			
		||||
				{
 | 
			
		||||
					hmodbus->f.EchoResponse = 1; 
 | 
			
		||||
					hmodbus->RS_Message_Size = 6; // echo response if write ok (withous data bytes)
 | 
			
		||||
				}
 | 
			
		||||
				break;
 | 
			
		||||
			
 | 
			
		||||
			// Write Multiple Registers
 | 
			
		||||
			case MB_W_HOLD_REGS:
 | 
			
		||||
				hmodbus->f.MessageHandled = 	MB_Write_Miltuple_Regs(hmodbus->pMessagePtr);
 | 
			
		||||
				if(hmodbus->f.MessageHandled) 
 | 
			
		||||
				{
 | 
			
		||||
					hmodbus->f.EchoResponse = 1; 
 | 
			
		||||
					hmodbus->RS_Message_Size = 6; // echo response if write ok (withous data bytes)
 | 
			
		||||
				}
 | 
			
		||||
				break;
 | 
			
		||||
			
 | 
			
		||||
			/* unknown func code */
 | 
			
		||||
			default: modbus_msg->Except_Code = 0x01; /* set exception code: illegal function */
 | 
			
		||||
		}		
 | 
			
		||||
				
 | 
			
		||||
		if(hmodbus->f.MessageHandled == 0)
 | 
			
		||||
    {
 | 
			
		||||
      TrackerCnt_Err(hmodbus->rs_err);
 | 
			
		||||
			modbus_msg->Func_Code += ERR_VALUES_START;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
      TrackerCnt_Ok(hmodbus->rs_err);
 | 
			
		||||
    }
 | 
			
		||||
		
 | 
			
		||||
			
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	// if we need response - check that transmit isnt busy
 | 
			
		||||
	if( RS_Is_TX_Busy(hmodbus) ) 
 | 
			
		||||
		RS_Abort(hmodbus, ABORT_TX);		// if tx busy - set it free
 | 
			
		||||
	
 | 
			
		||||
	// Transmit right there, or sets (fDeferredResponse) to transmit response in main code	
 | 
			
		||||
	MB_RES = RS_Handle_Transmit_Start(hmodbus, modbus_msg);
 | 
			
		||||
	
 | 
			
		||||
	hmodbus->RS_STATUS = MB_RES;
 | 
			
		||||
	return MB_RES;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** 
 | 
			
		||||
	* @brief 		Collect message in buffer to transmit it.
 | 
			
		||||
	* @param 		hRS 					- указатель на хендлер RS.
 | 
			
		||||
	* @param 		RS_msg 				- указатель на структуру сообщения.
 | 
			
		||||
	* @param 		msg_uart_buff	- указатель на буффер UART.
 | 
			
		||||
	* @return 	RS_RES				- статус о результате заполнения буфера.
 | 
			
		||||
	* @details		Заполнение буффера UART из структуры сообщения.
 | 
			
		||||
	*/
 | 
			
		||||
RS_StatusTypeDef RS_Collect_Message(RS_HandleTypeDef *hmodbus, RS_MsgTypeDef *modbus_msg, uint8_t *modbus_uart_buff)
 | 
			
		||||
{
 | 
			
		||||
	int ind = 0; // ind for modbus-uart buffer
 | 
			
		||||
	
 | 
			
		||||
	if(hmodbus->f.EchoResponse && hmodbus->f.MessageHandled) 	// if echo response need
 | 
			
		||||
		ind = hmodbus->RS_Message_Size;
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
		//------INFO ABOUT DATA/MESSAGE------
 | 
			
		||||
		//-----------[first bytes]-----------
 | 
			
		||||
		// set ID of message/user
 | 
			
		||||
		modbus_uart_buff[ind++] = modbus_msg->MbAddr;	
 | 
			
		||||
 | 
			
		||||
		// set dat or err response
 | 
			
		||||
		modbus_uart_buff[ind++] = modbus_msg->Func_Code;	
 | 
			
		||||
 | 
			
		||||
		if (modbus_msg->Func_Code < ERR_VALUES_START) // if no error occur
 | 
			
		||||
		{
 | 
			
		||||
			// set size of received data
 | 
			
		||||
			if (modbus_msg->ByteCnt <= DATA_SIZE*2) // if ByteCnt less than DATA_SIZE
 | 
			
		||||
				modbus_uart_buff[ind++] = modbus_msg->ByteCnt;
 | 
			
		||||
			else																				// otherwise return data_size err
 | 
			
		||||
      {
 | 
			
		||||
        TrackerCnt_Err(hmodbus->rs_err);
 | 
			
		||||
				return RS_COLLECT_MSG_ERR;
 | 
			
		||||
      }
 | 
			
		||||
			
 | 
			
		||||
			//---------------DATA----------------
 | 
			
		||||
			//-----------[data bytes]------------
 | 
			
		||||
			uint16_t *tmp_data_addr = (uint16_t *)modbus_msg->DATA;
 | 
			
		||||
			for(int i = 0; i < modbus_msg->ByteCnt; i++) // filling buffer with data
 | 
			
		||||
			{	// set data
 | 
			
		||||
				if (i%2 == 0)		// HI byte
 | 
			
		||||
					modbus_uart_buff[ind++] = (*tmp_data_addr)>>8;
 | 
			
		||||
				else						// LO byte
 | 
			
		||||
				{
 | 
			
		||||
					modbus_uart_buff[ind++] = *tmp_data_addr;
 | 
			
		||||
					tmp_data_addr++;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		else 	// if some error occur
 | 
			
		||||
		{			// send expection code
 | 
			
		||||
			modbus_uart_buff[ind++] = modbus_msg->Except_Code;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	//---------------CRC----------------
 | 
			
		||||
	//---------[last 16 bytes]----------
 | 
			
		||||
	// calc crc of received data
 | 
			
		||||
	uint16_t CRC_VALUE = crc16(modbus_uart_buff, ind);
 | 
			
		||||
	// write crc to message structure and modbus-uart buffer
 | 
			
		||||
	modbus_msg->MB_CRC = CRC_VALUE;
 | 
			
		||||
	modbus_uart_buff[ind++] = CRC_VALUE;
 | 
			
		||||
	modbus_uart_buff[ind++] = CRC_VALUE >> 8;
 | 
			
		||||
	
 | 
			
		||||
	hmodbus->RS_Message_Size = ind;
 | 
			
		||||
	
 | 
			
		||||
	return RS_OK; // returns ok
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** 
 | 
			
		||||
	* @brief 		Parse message from buffer to process it.
 | 
			
		||||
	* @param 		hRS 					- указатель на хендлер RS.
 | 
			
		||||
	* @param 		RS_msg 				- указатель на структуру сообщения.
 | 
			
		||||
	* @param 		msg_uart_buff	- указатель на буффер UART.
 | 
			
		||||
	* @return 	RS_RES				- статус о результате заполнения структуры.
 | 
			
		||||
	* @details		Заполнение структуры сообщения из буффера UART.
 | 
			
		||||
	*/
 | 
			
		||||
RS_StatusTypeDef RS_Parse_Message(RS_HandleTypeDef *hmodbus, RS_MsgTypeDef *modbus_msg, uint8_t *modbus_uart_buff)
 | 
			
		||||
{
 | 
			
		||||
	uint32_t check_empty_buff;
 | 
			
		||||
	int ind = 0; // ind for modbus-uart buffer
 | 
			
		||||
	//-----INFO ABOUT DATA/MESSAGE-------
 | 
			
		||||
	//-----------[first bits]------------
 | 
			
		||||
	// get ID of message/user
 | 
			
		||||
	modbus_msg->MbAddr = modbus_uart_buff[ind++];
 | 
			
		||||
	if(modbus_msg->MbAddr != hmodbus->ID)
 | 
			
		||||
		return RS_SKIP;
 | 
			
		||||
	
 | 
			
		||||
	// get dat or err response
 | 
			
		||||
	modbus_msg->Func_Code = modbus_uart_buff[ind++];
 | 
			
		||||
	
 | 
			
		||||
	// get address from CMD
 | 
			
		||||
	modbus_msg->Addr = modbus_uart_buff[ind++] << 8;
 | 
			
		||||
	modbus_msg->Addr |= modbus_uart_buff[ind++];
 | 
			
		||||
	
 | 
			
		||||
	// get address from CMD
 | 
			
		||||
	modbus_msg->Qnt = modbus_uart_buff[ind++] << 8;
 | 
			
		||||
	modbus_msg->Qnt |= modbus_uart_buff[ind++];
 | 
			
		||||
	
 | 
			
		||||
	if(hmodbus->f.RX_Half == 0) // if all message received
 | 
			
		||||
	{
 | 
			
		||||
		//---------------DATA----------------
 | 
			
		||||
		// 					  (optional)
 | 
			
		||||
		if (modbus_msg->ByteCnt != 0)
 | 
			
		||||
		{
 | 
			
		||||
			ind++; // increment ind for data_size byte
 | 
			
		||||
			//check that data size is correct
 | 
			
		||||
			if (modbus_msg->ByteCnt > DATA_SIZE*2)
 | 
			
		||||
			{
 | 
			
		||||
        TrackerCnt_Err(hmodbus->rs_err);
 | 
			
		||||
				modbus_msg->Func_Code += ERR_VALUES_START;
 | 
			
		||||
				return RS_PARSE_MSG_ERR;
 | 
			
		||||
			}
 | 
			
		||||
			uint16_t *tmp_data_addr = (uint16_t *)modbus_msg->DATA;
 | 
			
		||||
			for(int i = 0; i < modbus_msg->ByteCnt; i++) // /2 because we transmit 8 bits, not 16 bits
 | 
			
		||||
			{	// set data
 | 
			
		||||
				if (i%2 == 0)
 | 
			
		||||
					*tmp_data_addr = ((uint16_t)modbus_uart_buff[ind++] << 8);
 | 
			
		||||
				else
 | 
			
		||||
				{
 | 
			
		||||
					*tmp_data_addr |= modbus_uart_buff[ind++];
 | 
			
		||||
					tmp_data_addr++;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		//---------------CRC----------------
 | 
			
		||||
		//----------[last 16 bits]----------
 | 
			
		||||
		// calc crc of received data
 | 
			
		||||
		uint16_t CRC_VALUE = crc16(modbus_uart_buff, ind);
 | 
			
		||||
		// get crc of received data
 | 
			
		||||
		modbus_msg->MB_CRC = modbus_uart_buff[ind++];
 | 
			
		||||
		modbus_msg->MB_CRC |= modbus_uart_buff[ind++] << 8;
 | 
			
		||||
		// compare crc
 | 
			
		||||
		if (modbus_msg->MB_CRC != CRC_VALUE)
 | 
			
		||||
    {
 | 
			
		||||
      TrackerCnt_Err(hmodbus->rs_err);
 | 
			
		||||
			modbus_msg->Func_Code += ERR_VALUES_START;
 | 
			
		||||
    }
 | 
			
		||||
	//		hmodbus->MB_RESPONSE = MB_CRC_ERR; // set func code - error about wrong crc
 | 
			
		||||
		
 | 
			
		||||
		// check is buffer empty
 | 
			
		||||
		check_empty_buff = 0;
 | 
			
		||||
		for(int i=0; i<ind;i++)
 | 
			
		||||
			check_empty_buff += modbus_uart_buff[i];
 | 
			
		||||
	//	if(check_empty_buff == 0) 
 | 
			
		||||
	//		hmodbus->MB_RESPONSE = MB_EMPTY_MSG; // 
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	return RS_OK;
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** 
 | 
			
		||||
	* @brief 		Define size of RX Message that need to be received.
 | 
			
		||||
	* @param 		hRS 					- указатель на хендлер RS.
 | 
			
		||||
	* @param 		rx_data_size 	- указатель на переменную для записи кол-ва байт для принятия.
 | 
			
		||||
	* @return 	RS_RES				- статус о корректности рассчета кол-ва байт для принятия.
 | 
			
		||||
	* @details	Определение сколько байтов надо принять по протоколу.
 | 
			
		||||
	*/
 | 
			
		||||
RS_StatusTypeDef RS_Define_Size_of_RX_Message(RS_HandleTypeDef *hmodbus, uint32_t *rx_data_size)
 | 
			
		||||
{		
 | 
			
		||||
	RS_StatusTypeDef MB_RES = 0;
 | 
			
		||||
	
 | 
			
		||||
	MB_RES = RS_Parse_Message(hmodbus, hmodbus->pMessagePtr, hmodbus->pBufferPtr);
 | 
			
		||||
	if(MB_RES == RS_SKIP) // if message not for us
 | 
			
		||||
		return MB_RES;																// return 
 | 
			
		||||
	
 | 
			
		||||
	if ((hmodbus->pMessagePtr->Func_Code & ~ERR_VALUES_START) < 0x0F)
 | 
			
		||||
	{
 | 
			
		||||
		hmodbus->pMessagePtr->ByteCnt = 0;
 | 
			
		||||
		*rx_data_size = 1;
 | 
			
		||||
	}
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
		hmodbus->pMessagePtr->ByteCnt = hmodbus->pBufferPtr[RX_FIRST_PART_SIZE-1]; // get numb of data in command
 | 
			
		||||
	// +1 because that defines is size, not ind.
 | 
			
		||||
		*rx_data_size = hmodbus->pMessagePtr->ByteCnt + 2;
 | 
			
		||||
	}
 | 
			
		||||
	hmodbus->RS_Message_Size = RX_FIRST_PART_SIZE + *rx_data_size; // size of whole message
 | 
			
		||||
	return RS_OK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//-----------------------------FOR USER------------------------------
 | 
			
		||||
//-------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//-------------------------------------------------------------------
 | 
			
		||||
//-------------------------HANDLERS FUNCTION-------------------------
 | 
			
		||||
#if (MODBUS_UART_NUMB == 1) // choose handler for UART
 | 
			
		||||
void USART1_IRQHandler(void)
 | 
			
		||||
#elif (MODBUS_UART_NUMB == 2)
 | 
			
		||||
void USART2_IRQHandler(void)
 | 
			
		||||
#elif (MODBUS_UART_NUMB == 3)
 | 
			
		||||
void USART3_IRQHandler(void)
 | 
			
		||||
#elif (MODBUS_UART_NUMB == 4)
 | 
			
		||||
void USART4_IRQHandler(void)
 | 
			
		||||
#elif (MODBUS_UART_NUMB == 5)
 | 
			
		||||
void USART5_IRQHandler(void)
 | 
			
		||||
#elif (MODBUS_UART_NUMB == 6)
 | 
			
		||||
void USART6_IRQHandler(void)
 | 
			
		||||
#endif
 | 
			
		||||
{	
 | 
			
		||||
	Trace_MB_UART_Enter();
 | 
			
		||||
	RS_UART_Handler(&hmodbus1);
 | 
			
		||||
	Trace_MB_UART_Exit();
 | 
			
		||||
}
 | 
			
		||||
#if (MODBUS_TIM_NUMB == 1) || (MODBUS_TIM_NUMB == 10) // choose handler for TIM
 | 
			
		||||
void TIM1_UP_TIM10_IRQHandler(void)
 | 
			
		||||
#elif (MODBUS_TIM_NUMB == 2)
 | 
			
		||||
void TIM2_IRQHandler(void)
 | 
			
		||||
#elif (MODBUS_TIM_NUMB == 3)
 | 
			
		||||
void TIM3_IRQHandler(void)
 | 
			
		||||
#elif (MODBUS_TIM_NUMB == 4)
 | 
			
		||||
void TIM4_IRQHandler(void)
 | 
			
		||||
#elif (MODBUS_TIM_NUMB == 5)
 | 
			
		||||
void TIM5_IRQHandler(void)
 | 
			
		||||
#elif (MODBUS_TIM_NUMB == 6)
 | 
			
		||||
void TIM6_DAC_IRQHandler(void)
 | 
			
		||||
#elif (MODBUS_TIM_NUMB == 7)
 | 
			
		||||
void TIM7_IRQHandler(void)
 | 
			
		||||
#elif (MODBUS_TIM_NUMB == 8) || (MODBUS_TIM_NUMB == 13)
 | 
			
		||||
void TIM8_UP_TIM13_IRQHandler(void)
 | 
			
		||||
#elif (MODBUS_TIM_NUMB == 1) || (MODBUS_TIM_NUMB == 9)
 | 
			
		||||
void TIM1_BRK_TIM9_IRQHandler(void)
 | 
			
		||||
#elif (MODBUS_TIM_NUMB == 1) || (MODBUS_TIM_NUMB == 11)
 | 
			
		||||
void TIM1_TRG_COM_TIM11_IRQHandler(void)
 | 
			
		||||
#elif (MODBUS_TIM_NUMB == 8) || (MODBUS_TIM_NUMB == 12)
 | 
			
		||||
void TIM8_BRK_TIM12_IRQHandler(void)
 | 
			
		||||
#elif (MODBUS_TIM_NUMB == 8) || (MODBUS_TIM_NUMB == 14)
 | 
			
		||||
void TIM8_TRG_COM_TIM14_IRQHandler(void)
 | 
			
		||||
#endif
 | 
			
		||||
{	
 | 
			
		||||
	Trace_MB_TIM_Enter();
 | 
			
		||||
	RS_TIM_Handler(&hmodbus1);
 | 
			
		||||
	Trace_MB_TIM_Exit();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//-------------------------HANDLERS FUNCTION-------------------------
 | 
			
		||||
//-------------------------------------------------------------------
 | 
			
		||||
							
								
								
									
										325
									
								
								diode_tester/Core/Interfaces/modbus.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										325
									
								
								diode_tester/Core/Interfaces/modbus.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,325 @@
 | 
			
		||||
/** 
 | 
			
		||||
	**************************************************************************
 | 
			
		||||
	* @file 	modbus.h
 | 
			
		||||
	* @brief 	Заголовочный файл модуля MODBUS.
 | 
			
		||||
	* @details 	Данный файл необходимо подключить в rs_message.h. После подключать 
 | 
			
		||||
	* rs_message.h к основному проекту.
 | 
			
		||||
	* 
 | 
			
		||||
	* @defgroup MODBUS
 | 
			
		||||
	* @brief 		Modbus stuff
 | 
			
		||||
	*
 | 
			
		||||
	*************************************************************************/
 | 
			
		||||
#ifndef __MODBUS_H_
 | 
			
		||||
#define __MODBUS_H_
 | 
			
		||||
 
 | 
			
		||||
#include "mylibs_include.h"
 | 
			
		||||
#include "modbus_data.h"
 | 
			
		||||
//#include "settings.h"		// for modbus settings
 | 
			
		||||
 | 
			
		||||
/** 
 | 
			
		||||
	* @addtogroup MODBUS_SETTINGS
 | 
			
		||||
	* @ingroup 		MODBUS
 | 
			
		||||
	* @brief 			Some defines for modbus
 | 
			
		||||
	@{
 | 
			
		||||
	*/
 | 
			
		||||
/////////////////////////////////////////////////////////////////////
 | 
			
		||||
//////////////////////////---SETTINGS---/////////////////////////////
 | 
			
		||||
// USER SETTINGS FOR MODBUS IN interface_config.h
 | 
			
		||||
//////////////////////////---SETTINGS---/////////////////////////////
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/////////////////////////////////////////////////////////////////////
 | 
			
		||||
/////////////////////---USER MESSAGE DEFINES---//////////////////////
 | 
			
		||||
//-------------DEFINES FOR STRUCTURE----------------
 | 
			
		||||
/* defines for structure of modbus message */
 | 
			
		||||
#define MbAddr_SIZE 						1						///< size of (MbAddr)
 | 
			
		||||
#define Func_Code_SIZE					1						///< size of (Func_Code)
 | 
			
		||||
#define	Addr_SIZE								2						///< size of (Addr)
 | 
			
		||||
#define Qnt_SIZE								2						///< size of (Qnt)
 | 
			
		||||
#define ByteCnt_SIZE						1						///< size of (ByteCnt)
 | 
			
		||||
#define DATA_SIZE 							125 				///< maximum number of data: DWORD (NOT MESSAGE SIZE)
 | 
			
		||||
#define CRC_SIZE 								2 					///< size of (MB_CRC) in bytes
 | 
			
		||||
 | 
			
		||||
/** @brief Size of whole message */
 | 
			
		||||
#define INFO_SIZE_MAX 					(MbAddr_SIZE+Func_Code_SIZE+Addr_SIZE+Qnt_SIZE+ByteCnt_SIZE)
 | 
			
		||||
 | 
			
		||||
/** @brief Size of first part of message that will be received
 | 
			
		||||
first receive info part of message, than defines size of rest message*/
 | 
			
		||||
#define RX_FIRST_PART_SIZE			INFO_SIZE_MAX
 | 
			
		||||
 | 
			
		||||
/** @brief Size of buffer: max size of whole message */
 | 
			
		||||
#define MSG_SIZE_MAX 						(INFO_SIZE_MAX + DATA_SIZE*2 + CRC_SIZE) // max possible size of message
 | 
			
		||||
 | 
			
		||||
/** @brief Structure for modbus exception codes */
 | 
			
		||||
typedef enum //MB_ExceptionTypeDef
 | 
			
		||||
{
 | 
			
		||||
	// reading
 | 
			
		||||
	NO_ERRORS =							0x00,		///< no errors
 | 
			
		||||
	ILLEGAL_FUNCTION =			0x01,		///< Принятый код функции не может быть обработан
 | 
			
		||||
	ILLEGAL_DATA_ADDRESS =	0x02,		///< Адрес данных, указанный в запросе, недоступен
 | 
			
		||||
	ILLEGAL_DATA_VALUE =		0x03,		///< Значение, содержащееся в поле данных запроса, является недопустимой величиной
 | 
			
		||||
	SLAVE_DEVICE_FAILURE =	0x04,		///< Невосстанавливаемая ошибка имела место, пока ведомое устройство пыталось выполнить затребованное действие
 | 
			
		||||
//	ACKNOWLEDGE =						0x05,		///< idk
 | 
			
		||||
//	SLAVE_DEVICE_BUSY =			0x06,		///< idk
 | 
			
		||||
//	MEMORY_PARITY_ERROR =		0x08,		///< idk
 | 
			
		||||
}MB_ExceptionTypeDef;
 | 
			
		||||
 | 
			
		||||
#define ERR_VALUES_START				0x80U				///< from this value starts error func codes
 | 
			
		||||
/** @brief Structure for modbus func codes */
 | 
			
		||||
typedef enum //MB_FunctonTypeDef
 | 
			
		||||
{
 | 
			
		||||
  /* COMMANDS */
 | 
			
		||||
	// reading
 | 
			
		||||
	MB_R_COILS = 			  0x01,			///< Чтение битовых ячеек
 | 
			
		||||
	MB_R_DISC_IN = 		  0x02,		  ///< Чтение дискретных входов
 | 
			
		||||
#ifndef TESTER_MODBUS_SWITCH_COMMAND_R_IN_REGS_AND_R_HOLD_REGS
 | 
			
		||||
	MB_R_HOLD_REGS = 	  0x03,			///< Чтение входных регистров
 | 
			
		||||
	MB_R_IN_REGS = 		  0x04,			///< Чтение регистров хранения
 | 
			
		||||
#else
 | 
			
		||||
	MB_R_HOLD_REGS = 	  0x04,			///< Чтение входных регистров
 | 
			
		||||
	MB_R_IN_REGS = 		  0x03,			///< Чтение регистров хранения
 | 
			
		||||
#endif
 | 
			
		||||
	
 | 
			
		||||
	// writting
 | 
			
		||||
	MB_W_COIL = 			  0x05,			///< Запись битовой ячейки
 | 
			
		||||
	MB_W_HOLD_REG = 		0x06,			///< Запись одиночного регистра
 | 
			
		||||
	MB_W_COILS = 			  0x0F,			///< Запись нескольких битовых ячеек
 | 
			
		||||
	MB_W_HOLD_REGS = 		0x10,			///< Запись нескольких регистров
 | 
			
		||||
  
 | 
			
		||||
  /* ERRORS */
 | 
			
		||||
	// error reading
 | 
			
		||||
	MB_ERR_R_COILS = 			  MB_R_COILS + ERR_VALUES_START,			  ///< Ошибка чтения битовых ячеек
 | 
			
		||||
	MB_ERR_R_DISC_IN = 		  MB_R_DISC_IN + ERR_VALUES_START,	    ///< Ошибка чтения дискретных входов
 | 
			
		||||
	MB_ERR_R_IN_REGS = 		  MB_R_IN_REGS + ERR_VALUES_START,			///< Ошибка чтения регистров хранения
 | 
			
		||||
	MB_ERR_R_HOLD_REGS = 	  MB_R_HOLD_REGS + ERR_VALUES_START,		///< Ошибка чтения входных регистров
 | 
			
		||||
	
 | 
			
		||||
	// error writting
 | 
			
		||||
	MB_ERR_W_COIL = 			  MB_W_COIL + ERR_VALUES_START,			    ///< Ошибка записи битовой ячейки
 | 
			
		||||
	MB_ERR_W_HOLD_REG = 		MB_W_HOLD_REG + ERR_VALUES_START,			///< Ошибка записи одиночного регистра
 | 
			
		||||
	MB_ERR_W_COILS = 			  MB_W_COILS + ERR_VALUES_START,			  ///< Ошибка записи нескольких битовых ячеек
 | 
			
		||||
	MB_ERR_W_HOLD_REGS = 		MB_W_HOLD_REGS + ERR_VALUES_START,	  ///< Ошибка записи нескольких регистров
 | 
			
		||||
}MB_FunctonTypeDef;
 | 
			
		||||
 | 
			
		||||
/** @brief Structure for modbus messsage */
 | 
			
		||||
typedef struct 	// RS_MsgTypeDef
 | 
			
		||||
{
 | 
			
		||||
	uint8_t 							MbAddr;							///< Modbus Slave Address
 | 
			
		||||
	MB_FunctonTypeDef 		Func_Code;					///< Modbus Function Code
 | 
			
		||||
	uint16_t 							Addr;								///< Modbus Address of data
 | 
			
		||||
	uint16_t 							Qnt;								///< Quantity of modbus data
 | 
			
		||||
	uint8_t 							ByteCnt;						///< Quantity of bytes of data in message to transmit/receive
 | 
			
		||||
	
 | 
			
		||||
	uint16_t 							DATA[DATA_SIZE];		///< Modbus Data
 | 
			
		||||
	MB_ExceptionTypeDef		Except_Code;				///< Exception Code for the command
 | 
			
		||||
	
 | 
			
		||||
	uint16_t 							MB_CRC;							///< Modbus CRC
 | 
			
		||||
}RS_MsgTypeDef;
 | 
			
		||||
//--------------------------------------------------
 | 
			
		||||
extern RS_MsgTypeDef MODBUS_MSG;
 | 
			
		||||
/////////////////////---MODBUS USER SETTINGS---//////////////////////
 | 
			
		||||
 | 
			
		||||
/** MODBUS_SETTINGS
 | 
			
		||||
  * @} 
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/////////////////////////////////////////////////////////////////////
 | 
			
		||||
////////////////////---MODBUS MESSAGE DEFINES---/////////////////////
 | 
			
		||||
/** 
 | 
			
		||||
	* @addtogroup MODBUS_MESSAGE_DEFINES
 | 
			
		||||
	* @ingroup 		MODBUS
 | 
			
		||||
	* @brief 			Some defines for modbus
 | 
			
		||||
	@{
 | 
			
		||||
	*/
 | 
			
		||||
/** @brief Structure for coils operation */
 | 
			
		||||
typedef enum
 | 
			
		||||
{
 | 
			
		||||
	SET_COIL,
 | 
			
		||||
	RESET_COIL,
 | 
			
		||||
	TOOGLE_COIL,
 | 
			
		||||
}MB_CoilsOpTypeDef;
 | 
			
		||||
 | 
			
		||||
//--------------------------------------------------
 | 
			
		||||
 | 
			
		||||
/** 
 | 
			
		||||
	* @brief 	Macros to set pointer to 16-bit array
 | 
			
		||||
	* @param 	_arr_ 				- массив регистров (16-бит).
 | 
			
		||||
	*/
 | 
			
		||||
#define MB_Set_Arr16_Ptr(_arr_)												((uint16_t*)(&(_arr_)))
 | 
			
		||||
/** 
 | 
			
		||||
	* @brief 	Macros to set pointer to register
 | 
			
		||||
	* @param 	_parr_ 				- массив регистров.
 | 
			
		||||
	* @param 	_addr_ 				- Номер регистра (его индекс) от начала массива _arr_.
 | 
			
		||||
	*/
 | 
			
		||||
#define MB_Set_Register_Ptr(_parr_, _addr_)						((uint16_t *)(_parr_)+(_addr_))
 | 
			
		||||
 | 
			
		||||
/** 
 | 
			
		||||
	* @brief 	Macros to set pointer to a certain register that contains certain coil
 | 
			
		||||
	* @param 	_parr_ 				- массив коилов.
 | 
			
		||||
	* @param 	_coil_ 				- Номер коила от начала массива _arr_.
 | 
			
		||||
	*	@note		Используется вместе с @ref MB_Set_Coil_Mask
 | 
			
		||||
	@verbatim	Пояснение выражений
 | 
			
		||||
						(_coil_/16) - get index (address shift) of register that contain certain coil
 | 
			
		||||
	Visual explanation: 30th coil in coils registers array
 | 
			
		||||
	xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxCx
 | 
			
		||||
	|register[0]----|	|register[1]----|
 | 
			
		||||
	|skip this------|	|get this-------|
 | 
			
		||||
										|shift to 14 bit|
 | 
			
		||||
	@endverbatim
 | 
			
		||||
	*/
 | 
			
		||||
#define MB_Set_Coil_Reg_Ptr(_parr_, _coil_)						((uint16_t *)(_parr_)+((_coil_)/16))
 | 
			
		||||
/** 
 | 
			
		||||
	* @brief 	Macros to set mask to a certain bit in coils register
 | 
			
		||||
	* @param 	_coil_ 				- Номер коила от начала массива _arr_.
 | 
			
		||||
	*	@note		Используется вместе с @ref MB_Set_Coil_Reg_Ptr
 | 
			
		||||
	@verbatim	Пояснение выражений
 | 
			
		||||
						(16*(_coil_/16) - how many coils we need to skip. e.g. (16*30/16) - skip 16 coils from first register
 | 
			
		||||
						_coil_-(16*(_coil_/16)) - shift to certain coil in certain register
 | 
			
		||||
					e.g. Coil(30) gets in register[1] (30/16 = 1) coil №14 (30 - (16*30/16) = 30 - 16 = 14)
 | 
			
		||||
	
 | 
			
		||||
	Visual explanation: 30th coil in coils registers array
 | 
			
		||||
	xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxCx
 | 
			
		||||
	|register[0]----|	|register[1]----|
 | 
			
		||||
	|skip this------|	|get this-------|
 | 
			
		||||
										|shift to 14 bit|
 | 
			
		||||
	@endverbatim
 | 
			
		||||
	*/
 | 
			
		||||
#define MB_Set_Coil_Mask(_coil_)											(1 << ( _coil_ - (16*((_coil_)/16)) ))
 | 
			
		||||
	
 | 
			
		||||
/** 
 | 
			
		||||
	* @brief 	Read Coil at its local address.
 | 
			
		||||
	* @param 	_parr_ 				- массив коилов.
 | 
			
		||||
	* @param 	_coil_ 				- Номер коила от начала массива _arr_.
 | 
			
		||||
	* @return uint16_t			- Возвращает запрошенный коил на 0м бите.
 | 
			
		||||
	*
 | 
			
		||||
  * @details 	Позволяет обратиться к коилу по адресу относительно _arr_.
 | 
			
		||||
	*/
 | 
			
		||||
#define MB_Read_Coil_Local(_parr_, _coil_)					((	*MB_Set_Coil_Reg_Ptr(_parr_, _coil_)	&		MB_Set_Coil_Mask(_coil_) ) >> (_coil_))
 | 
			
		||||
/** 
 | 
			
		||||
	* @brief 	Set Coil at its local address.
 | 
			
		||||
	* @param 	_parr_ 				- указатель на массив коилов.
 | 
			
		||||
	* @param 	_coil_ 				- Номер коила от начала массива _arr_.
 | 
			
		||||
	*	
 | 
			
		||||
  * @details 	Позволяет обратиться к коилу по адресу относительно _arr_.
 | 
			
		||||
	*/
 | 
			
		||||
#define	MB_Set_Coil_Local(_parr_, _coil_)							*MB_Set_Coil_Reg_Ptr(_parr_, _coil_) 	|= 	MB_Set_Coil_Mask(_coil_)
 | 
			
		||||
/** 
 | 
			
		||||
	* @brief 	Reset Coil at its local address.
 | 
			
		||||
	* @param 	_parr_ 				- указатель на массив коилов.
 | 
			
		||||
	* @param 	_coil_ 				- Номер коила от начала массива _arr_.
 | 
			
		||||
	*
 | 
			
		||||
  * @details 	Позволяет обратиться к коилу по адресу относительно _arr_.
 | 
			
		||||
	*/
 | 
			
		||||
#define MB_Reset_Coil_Local(_parr_, _coil_)						*MB_Set_Coil_Reg_Ptr(_parr_, _coil_) 	&= ~(MB_Set_Coil_Mask(_coil_))
 | 
			
		||||
/** 
 | 
			
		||||
	* @brief 	Set Coil at its local address.
 | 
			
		||||
	* @param 	_parr_ 				- указатель на массив коилов.
 | 
			
		||||
	* @param 	_coil_ 				- Номер коила от начала массива _arr_.
 | 
			
		||||
	*	
 | 
			
		||||
  * @details 	Позволяет обратиться к коилу по адресу относительно _arr_.
 | 
			
		||||
	*/
 | 
			
		||||
#define	MB_Toogle_Coil_Local(_parr_, _coil_)					*MB_Set_Coil_Reg_Ptr(_parr_, _coil_) 	^= 	MB_Set_Coil_Mask(_coil_)
 | 
			
		||||
//--------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//------------------OTHER DEFINES-------------------
 | 
			
		||||
#define RegisterType_Holding				0
 | 
			
		||||
#define RegisterType_Input					1
 | 
			
		||||
#define RegisterType_Discrete				2
 | 
			
		||||
// create hadnles and settings for uart, tim, rs with _modbus_ name
 | 
			
		||||
#define CONCAT(a,b) a##b
 | 
			
		||||
#define Create_MODBUS_Handles(_modbus_)												\
 | 
			
		||||
				UART_SettingsTypeDef CONCAT(_modbus_, _suart);				\
 | 
			
		||||
				UART_HandleTypeDef CONCAT(_modbus_, _huart);					\
 | 
			
		||||
				TIM_SettingsTypeDef CONCAT(_modbus_, _stim);					\
 | 
			
		||||
				TIM_HandleTypeDef CONCAT(_modbus_, _htim);						\
 | 
			
		||||
				RS_HandleTypeDef CONCAT(h, _modbus_)	
 | 
			
		||||
//--------------------------------------------------
 | 
			
		||||
/** GENERAL_MODBUS_STUFF
 | 
			
		||||
  * @} 
 | 
			
		||||
  */
 | 
			
		||||
////////////////////---MODBUS MESSAGE DEFINES---/////////////////////
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/////////////////////////////////////////////////////////////////////
 | 
			
		||||
/////////////////////////---FUNCTIONS---/////////////////////////////
 | 
			
		||||
/** 
 | 
			
		||||
	* @addtogroup MODBUS_FUNCTIONS
 | 
			
		||||
	* @ingroup 		MODBUS
 | 
			
		||||
	* @brief 			Function for controling modbus communication
 | 
			
		||||
	*/
 | 
			
		||||
	
 | 
			
		||||
//----------------FUNCTIONS FOR USER----------------
 | 
			
		||||
/** 
 | 
			
		||||
	* @addtogroup MODBUS_DATA_ACCESS_FUNCTIONS
 | 
			
		||||
	* @ingroup 		MODBUS_FUNCTIONS
 | 
			
		||||
	* @brief 			Function for user use
 | 
			
		||||
	@{
 | 
			
		||||
	*/
 | 
			
		||||
/* First set up of MODBUS */
 | 
			
		||||
void MODBUS_FirstInit(void);
 | 
			
		||||
/* Set or Reset Coil at its global address */
 | 
			
		||||
MB_ExceptionTypeDef MB_Write_Coil_Global(uint16_t Addr, MB_CoilsOpTypeDef WriteVal);
 | 
			
		||||
/* Read Coil at its global address */
 | 
			
		||||
uint16_t MB_Read_Coil_Global(uint16_t Addr, MB_ExceptionTypeDef *Exception);
 | 
			
		||||
 | 
			
		||||
/** MODBUS_DATA_ACCESS_FUNCTIONS
 | 
			
		||||
  * @} 
 | 
			
		||||
  */
 | 
			
		||||
	
 | 
			
		||||
//---------PROCESS MODBUS COMMAND FUNCTIONS---------
 | 
			
		||||
/** 
 | 
			
		||||
	* @addtogroup MODBUS_CMD_PROCESS_FUNCTIONS
 | 
			
		||||
	* @ingroup 		MODBUS_FUNCTIONS
 | 
			
		||||
	* @brief 			Function process commands
 | 
			
		||||
	@{
 | 
			
		||||
	*/
 | 
			
		||||
/* Check is address valid for certain array */
 | 
			
		||||
MB_ExceptionTypeDef MB_Check_Address_For_Arr(uint16_t Addr, uint16_t Qnt, uint16_t R_ARR_ADDR, uint16_t R_ARR_NUMB);
 | 
			
		||||
/* Define Address Origin for Input/Holding Registers */
 | 
			
		||||
MB_ExceptionTypeDef MB_DefineRegistersAddress(uint16_t **pRegs, uint16_t Addr, uint16_t Qnt, uint8_t RegisterType);
 | 
			
		||||
/* Define Address Origin for coils */
 | 
			
		||||
MB_ExceptionTypeDef MB_DefineCoilsAddress(uint16_t **pCoils, uint16_t Addr, uint16_t Qnt, uint16_t *start_shift, uint8_t WriteFlag);
 | 
			
		||||
/* Proccess command Read Coils (01 - 0x01) */
 | 
			
		||||
uint8_t MB_Read_Coils(RS_MsgTypeDef *modbus_msg);
 | 
			
		||||
/* Proccess command Read Holding Registers (03 - 0x03) */
 | 
			
		||||
uint8_t MB_Read_Hold_Regs(RS_MsgTypeDef *modbus_msg);
 | 
			
		||||
/* Proccess command Read Input Registers (04 - 0x04) */
 | 
			
		||||
uint8_t MB_Read_Input_Regs(RS_MsgTypeDef *modbus_msg);
 | 
			
		||||
/* 	Proccess command Write Single Coils (05 - 0x05) */
 | 
			
		||||
uint8_t MB_Write_Single_Coil(RS_MsgTypeDef *modbus_msg);
 | 
			
		||||
/* Proccess command Write Multiple Coils (15 - 0x0F) */
 | 
			
		||||
uint8_t MB_Write_Miltuple_Coils(RS_MsgTypeDef *modbus_msg);
 | 
			
		||||
/* Proccess command Write Multiple Register (16 - 0x10) */
 | 
			
		||||
uint8_t MB_Write_Miltuple_Regs(RS_MsgTypeDef *modbus_msg);
 | 
			
		||||
 | 
			
		||||
/** MODBUS_DATA_ACCESS_FUNCTIONS
 | 
			
		||||
  * @} 
 | 
			
		||||
  */
 | 
			
		||||
/////////////////////////---FUNCTIONS---/////////////////////////////
 | 
			
		||||
	
 | 
			
		||||
	
 | 
			
		||||
	
 | 
			
		||||
/////////////////////////////////////////////////////////////////////
 | 
			
		||||
/////////////////////////---CALC DEFINES---//////////////////////////
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// TRACES DEFINES
 | 
			
		||||
#ifndef Trace_MB_UART_Enter
 | 
			
		||||
#define Trace_MB_UART_Enter()
 | 
			
		||||
#endif //Trace_MB_UART_Enter
 | 
			
		||||
	
 | 
			
		||||
#ifndef Trace_MB_UART_Exit
 | 
			
		||||
#define Trace_MB_UART_Exit()
 | 
			
		||||
#endif //Trace_MB_UART_Exit
 | 
			
		||||
 | 
			
		||||
#ifndef Trace_MB_TIM_Enter
 | 
			
		||||
#define Trace_MB_TIM_Enter()
 | 
			
		||||
#endif //Trace_MB_TIM_Enter
 | 
			
		||||
	
 | 
			
		||||
#ifndef Trace_MB_TIM_Exit
 | 
			
		||||
#define Trace_MB_TIM_Exit()
 | 
			
		||||
#endif //Trace_MB_TIM_Exit
 | 
			
		||||
 | 
			
		||||
#endif //__MODBUS_H_
 | 
			
		||||
							
								
								
									
										163
									
								
								diode_tester/Core/Interfaces/modbus_data.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										163
									
								
								diode_tester/Core/Interfaces/modbus_data.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,163 @@
 | 
			
		||||
/** 
 | 
			
		||||
**************************************************************************
 | 
			
		||||
* @file   modbus_data.h
 | 
			
		||||
* @brief    Заголовочный файл с описанием даты MODBUS.
 | 
			
		||||
* @details  Данный файл необходимо подключается в rs_message.h. После rs_message.h 
 | 
			
		||||
* подключается к основному проекту.
 | 
			
		||||
* 
 | 
			
		||||
* @defgroup MODBUS_DATA
 | 
			
		||||
* @ingroup  MODBUS
 | 
			
		||||
* @brief    Modbus data description
 | 
			
		||||
*
 | 
			
		||||
*************************************************************************/
 | 
			
		||||
 | 
			
		||||
#ifndef _MODBUS_DATA_H_
 | 
			
		||||
#define _MODBUS_DATA_H_
 | 
			
		||||
  
 | 
			
		||||
#include "stdint.h"
 | 
			
		||||
//--------------DEFINES FOR REGISTERS---------------
 | 
			
		||||
// DEFINES FOR ARRAYS
 | 
			
		||||
/** 
 | 
			
		||||
  * @addtogroup MODBUS_DATA_RERISTERS_DEFINES
 | 
			
		||||
  * @ingroup    MODBUS_DATA
 | 
			
		||||
  * @brief      Defines for registers
 | 
			
		||||
  Структура дефайна адресов
 | 
			
		||||
  @verbatim    
 | 
			
		||||
  Для массивов регистров:
 | 
			
		||||
    R_<NAME_ARRAY>_ADDR   -  модбас адресс первого регистра в массиве
 | 
			
		||||
    R_<NAME_ARRAY>_QNT    -  количество регистров в массиве
 | 
			
		||||
  
 | 
			
		||||
  @endverbatim
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
  
 | 
			
		||||
  
 | 
			
		||||
/** 
 | 
			
		||||
  * @brief Регистры хранения
 | 
			
		||||
  */
 | 
			
		||||
typedef struct //MB_DataInRegsTypeDef
 | 
			
		||||
{
 | 
			
		||||
  unsigned DUMMY;
 | 
			
		||||
}MB_DataInRegsTypeDef;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/** 
 | 
			
		||||
  * @brief Входные регистры 
 | 
			
		||||
  */
 | 
			
		||||
typedef struct //MB_DataInRegsTypeDef
 | 
			
		||||
{
 | 
			
		||||
  unsigned DUMMY;
 | 
			
		||||
}MB_DataHoldRegsTypeDef;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// DEFINES FOR INPUT REGISTERS ARRAYS
 | 
			
		||||
#define   R_TE_VOLTAGE_ADDR                 0
 | 
			
		||||
#define   R_TE_VOLTAGE_QNT                  85
 | 
			
		||||
 | 
			
		||||
#define   R_STATUS_REG_ADDR                 85
 | 
			
		||||
#define   R_STATUS_REG_QNT                  1
 | 
			
		||||
 | 
			
		||||
// DEFINES FOR HOLDING REGISTERS ARRAYS
 | 
			
		||||
#define   R_SETPOINTS_ADDR                  0
 | 
			
		||||
#define   R_SETPOINTS_QNT                   170
 | 
			
		||||
 | 
			
		||||
#define   R_SETTINGS_ADDR                   170
 | 
			
		||||
#define   R_SETTINGS_QNT                    5
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// DEFINES FOR REGISTERS LOCAL ADDRESSES
 | 
			
		||||
//#define R_SET_ERROR(_te_num_)          0
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
/** MODBUS_DATA_RERISTERS_DEFINES
 | 
			
		||||
  * @} 
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
//----------------DEFINES FOR COILS-----------------
 | 
			
		||||
/** 
 | 
			
		||||
  * @addtogroup MODBUS_DATA_COILS_DEFINES
 | 
			
		||||
  * @ingroup    MODBUS_DATA
 | 
			
		||||
  * @brief      Defines for coils
 | 
			
		||||
  @verbatim    
 | 
			
		||||
  Структура дефайна
 | 
			
		||||
  Для массивов коилов:
 | 
			
		||||
    C_<NAME_ARRAY>_ADDR   - модбас адресс первого коила в массиве
 | 
			
		||||
    C_<NAME_ARRAY>_QNT    - количество коилов в массиве (минимум 16)
 | 
			
		||||
 | 
			
		||||
  @endverbatim
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
  
 | 
			
		||||
  
 | 
			
		||||
  
 | 
			
		||||
/** 
 | 
			
		||||
  * @brief     Коилы
 | 
			
		||||
  */
 | 
			
		||||
typedef struct //MB_DataCoilsTypeDef
 | 
			
		||||
{
 | 
			
		||||
  unsigned DUMMY;
 | 
			
		||||
}MB_DataCoilsTypeDef;
 | 
			
		||||
 | 
			
		||||
// DEFINES FOR COIL ARRAYS
 | 
			
		||||
#define C_TE_EXCLUDE_ADDR              0
 | 
			
		||||
#define C_TE_EXCLUDE_QNT              85
 | 
			
		||||
 | 
			
		||||
/** MODBUS_DATA_COILS_DEFINES
 | 
			
		||||
  * @} 
 | 
			
		||||
  */
 | 
			
		||||
  
 | 
			
		||||
  
 | 
			
		||||
//-----------MODBUS DEVICE DATA SETTING-------------
 | 
			
		||||
// MODBUS DATA STRUCTTURE
 | 
			
		||||
/** 
 | 
			
		||||
  * @brief Структура со всеми регистрами и коилами модбас 
 | 
			
		||||
  * @ingroup  MODBUS_DATA
 | 
			
		||||
  */
 | 
			
		||||
typedef struct // tester modbus data
 | 
			
		||||
{
 | 
			
		||||
  MB_DataInRegsTypeDef      InRegs;     ///< Modbus input registers @ref MB_DataInRegsTypeDef
 | 
			
		||||
 | 
			
		||||
  MB_DataCoilsTypeDef       Coils;      ///< Modbus coils @ref MB_DataCoilsTypeDef
 | 
			
		||||
  
 | 
			
		||||
  MB_DataHoldRegsTypeDef    HoldRegs;   ///< Modbus holding registers @ref MB_DataHoldRegsTypeDef
 | 
			
		||||
}MB_DataStructureTypeDef;
 | 
			
		||||
extern MB_DataStructureTypeDef MB_DATA;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif //_MODBUS_DATA_H_
 | 
			
		||||
 | 
			
		||||
/////////////////////////////////////////////////////////////
 | 
			
		||||
///////////////////////TEMP/OUTDATE/OTHER////////////////////
 | 
			
		||||
 | 
			
		||||
//typedef enum //MB_TESTERCommandsTypeDef
 | 
			
		||||
//{
 | 
			
		||||
//  StandartMode       = 0x00, ///< Стандартная работа
 | 
			
		||||
//  Opros_TE_Disable   = 0x01, ///< Запрет опроса ТЭ (активен только обмен с ЛСУ ЭС, ТЭ не контролируются)
 | 
			
		||||
//}MB_TESTERCommandsTypeDef;
 | 
			
		||||
 | 
			
		||||
///**
 | 
			
		||||
//  * @brief     Состояние МЗКТЭ
 | 
			
		||||
//  */
 | 
			
		||||
//typedef enum //MB_TESTERErrStatusTypeDef
 | 
			
		||||
//{
 | 
			
		||||
//  TESTER_OK           = 0x0,   ///< МЗКТЭ функционирует нормально. Идет опрос ТЭ.
 | 
			
		||||
//  NonCritical_Err    = 0x1,  ///< Неисправность МЗКТЭ, при которой МЗКТЭ может выполнять свои основные функции (некоторые программные ошибки из @ref MB_TESTERTrackerTypeDef).
 | 
			
		||||
//  Critical_Err       = 0x2,  ///< Неисправность МЗКТЭ, при которой выполнение основных функций не представляется возможным (ошибки 1-3 и  некоторые программные ошибки из @ref MB_TESTERTrackerTypeDef)
 | 
			
		||||
//  
 | 
			
		||||
//}MB_TESTERErrStatusTypeDef;
 | 
			
		||||
//typedef enum
 | 
			
		||||
//{
 | 
			
		||||
//  TE_No_Err   = 0x0,   ///< Напряжения на всех ТЭ выше аварийных порогов, задаваемых уставками «Авария»
 | 
			
		||||
//  TE_Err      = 0x1,  ///< Напряжение на одном или нескольких ТЭ достигло или ниже аварийного порога, задаваемого уставкой «Авария»
 | 
			
		||||
//}MB_TEErrActiveTypeDef;
 | 
			
		||||
//typedef enum
 | 
			
		||||
//{
 | 
			
		||||
//  TE_No_Warn   = 0x0,   ///< Напряжения на всех ТЭ выше предупредительных порогов, задаваемых уставкой «Предупреждение»
 | 
			
		||||
//  TE_Warn      = 0x1,  ///< Напряжение на одном или нескольких ТЭ достигло или ниже предупредительного порога, задаваемого уставкой «Предупреждение»
 | 
			
		||||
//}MB_TEWarnActiveTypeDef;
 | 
			
		||||
//typedef enum
 | 
			
		||||
//{
 | 
			
		||||
//  OprosTE_Enable   = 0x0,   ///< Опрос ТЭ разрешен
 | 
			
		||||
//  OprosTE_Disable      = 0x1,  ///< Опрос ТЭ запрещен  (см. регистр хранения 170)
 | 
			
		||||
//}MB_OprosTETypeDef;
 | 
			
		||||
							
								
								
									
										580
									
								
								diode_tester/Core/Interfaces/rs_message.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										580
									
								
								diode_tester/Core/Interfaces/rs_message.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,580 @@
 | 
			
		||||
/** 
 | 
			
		||||
**************************************************************************
 | 
			
		||||
* @file rs_message.c
 | 
			
		||||
* @brief Модуль для реализации протоколов по RS/UART.
 | 
			
		||||
**************************************************************************
 | 
			
		||||
  @verbatim
 | 
			
		||||
  //-------------------Функции-------------------//
 | 
			
		||||
  Functions: users
 | 
			
		||||
    -	RS_Parse_Message/RS_Collect_Message	Заполнение структуры сообщения и буфера
 | 
			
		||||
    -	RS_Response  									Ответ на сообщение
 | 
			
		||||
    - RS_Define_Size_of_RX_Message	Определение размера принимаемых данных
 | 
			
		||||
  
 | 
			
		||||
  Functions: general
 | 
			
		||||
    -	RS_Receive_IT									Ожидание комманды и ответ на неё
 | 
			
		||||
    -	RS_Transmit_IT								Отправление комманды и ожидание ответа
 | 
			
		||||
    -	RS_Init												Инициализация переферии и структуры для RS
 | 
			
		||||
    -	RS_ReInit_UART								Реинициализация UART для RS
 | 
			
		||||
    -	RS_Abort											Отмена приема/передачи по ЮАРТ
 | 
			
		||||
    -	RS_Init												Инициализация периферии и modbus handler
 | 
			
		||||
  
 | 
			
		||||
  Functions: callback/handler
 | 
			
		||||
    - RS_Handle_Receive_Start				Функция для запуска приема или остановки RS
 | 
			
		||||
    - RS_Handle_Transmit_Start			Функция для запуска передачи или остановки RS
 | 
			
		||||
    
 | 
			
		||||
    -	RS_UART_RxCpltCallback				Коллбек при окончании приема или передачи
 | 
			
		||||
      RS_UART_TxCpltCallback		
 | 
			
		||||
      
 | 
			
		||||
    - RS_UART_Handler								Обработчик прерывания для UART
 | 
			
		||||
    - RS_TIM_Handler								Обработчик прерывания для TIM
 | 
			
		||||
    
 | 
			
		||||
  Functions: uart initialize (это было в отдельных файлах, мб надо обратно разнести)
 | 
			
		||||
    - UART_Base_Init							Инициализация UART для RS
 | 
			
		||||
    - RS_UART_GPIO_Init						Инициализация GPIO для RS
 | 
			
		||||
    - UART_DMA_Init								Инициализация DMA для RS
 | 
			
		||||
    - UART_MspInit								Аналог HAL_MspInit для RS
 | 
			
		||||
    - UART_MspDeInit							Аналог HAL_MspDeInit для RS
 | 
			
		||||
  
 | 
			
		||||
  @endverbatim
 | 
			
		||||
*************************************************************************/
 | 
			
		||||
#include "rs_message.h"
 | 
			
		||||
 | 
			
		||||
uint8_t RS_Buffer[MSG_SIZE_MAX]; // uart buffer
 | 
			
		||||
 | 
			
		||||
#ifndef INCLUDE_GENERAL_PERIPH_LIBS
 | 
			
		||||
extern void RS_UART_Init(void);
 | 
			
		||||
extern void RS_UART_DeInit(UART_HandleTypeDef *huart);
 | 
			
		||||
extern void RS_TIM_Init(void);
 | 
			
		||||
extern void RS_TIM_DeInit(TIM_HandleTypeDef *htim);
 | 
			
		||||
#endif 
 | 
			
		||||
 | 
			
		||||
//-------------------------------------------------------------------
 | 
			
		||||
//-------------------------GENERAL FUNCTIONS-------------------------
 | 
			
		||||
/**
 | 
			
		||||
  * @brief 	Start receive IT.
 | 
			
		||||
  * @param 	hRS 		- указатель на хендлер RS.
 | 
			
		||||
  * @param 	RS_msg 	- указатель на структуру сообщения.
 | 
			
		||||
  * @return RS_RES	- статус о состоянии RS после инициализации приема.
 | 
			
		||||
	*/
 | 
			
		||||
RS_StatusTypeDef RS_Receive_IT(RS_HandleTypeDef *hRS, RS_MsgTypeDef *RS_msg)
 | 
			
		||||
{
 | 
			
		||||
	RS_StatusTypeDef RS_RES = 0;
 | 
			
		||||
	HAL_StatusTypeDef uart_res = 0;
 | 
			
		||||
	
 | 
			
		||||
	//-------------CHECK RS LINE----------------
 | 
			
		||||
	// check that receive isnt busy
 | 
			
		||||
	if( RS_Is_RX_Busy(hRS) ) // if tx busy - return busy status
 | 
			
		||||
		return RS_BUSY;	
 | 
			
		||||
	
 | 
			
		||||
	//-----------INITIALIZE RECEIVE-------------
 | 
			
		||||
	// if all OK: start receiving
 | 
			
		||||
	RS_EnableReceive();
 | 
			
		||||
	RS_Set_Busy(hRS);							// set RS busy	
 | 
			
		||||
	RS_Set_RX_Flags(hRS);					// initialize flags for receive
 | 
			
		||||
	hRS->pMessagePtr = RS_msg; 		// set pointer to message structire for filling it from UARTHandler fucntions
 | 
			
		||||
	
 | 
			
		||||
	// start receiving
 | 
			
		||||
	uart_res = HAL_UART_Receive_IT(hRS->huart, hRS->pBufferPtr, RX_FIRST_PART_SIZE); // receive until ByteCnt+1 byte, 
 | 
			
		||||
	// then in Callback restart receive for rest bytes	
 | 
			
		||||
	
 | 
			
		||||
	// if receive isnt started - abort RS
 | 
			
		||||
	if(uart_res != HAL_OK)
 | 
			
		||||
	{
 | 
			
		||||
		RS_RES = RS_Abort(hRS, ABORT_RS);
 | 
			
		||||
    printf_rs_err("\n%d: Error RS: Failed to start RS receiving...", uwTick);
 | 
			
		||||
    TrackerCnt_Err(hRS->rs_err);
 | 
			
		||||
	}
 | 
			
		||||
	else
 | 
			
		||||
  {
 | 
			
		||||
		RS_RES = RS_OK;
 | 
			
		||||
    printf_rs("\n%d: RS: Start Receiving...", uwTick);
 | 
			
		||||
    TrackerCnt_Ok(hRS->rs_err);
 | 
			
		||||
  }
 | 
			
		||||
	
 | 
			
		||||
	hRS->RS_STATUS = RS_RES;
 | 
			
		||||
	return RS_RES; // returns result of receive init	
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief 	Start transmit IT.
 | 
			
		||||
  * @param 	hRS 		- указатель на хендлер RS.
 | 
			
		||||
  * @param 	RS_msg 	- указатель на структуру сообщения.
 | 
			
		||||
  * @return RS_RES	- статус о состоянии RS после инициализации передачи.
 | 
			
		||||
	*/
 | 
			
		||||
RS_StatusTypeDef RS_Transmit_IT(RS_HandleTypeDef *hRS, RS_MsgTypeDef *RS_msg)
 | 
			
		||||
{	
 | 
			
		||||
	RS_StatusTypeDef RS_RES = 0;
 | 
			
		||||
	HAL_StatusTypeDef uart_res = 0;
 | 
			
		||||
	
 | 
			
		||||
	//-------------CHECK RS LINE----------------
 | 
			
		||||
	// check that transmit isnt busy
 | 
			
		||||
	if( RS_Is_TX_Busy(hRS) ) // if tx busy - return busy status
 | 
			
		||||
		return RS_BUSY;
 | 
			
		||||
		// check receive line
 | 
			
		||||
 | 
			
		||||
	
 | 
			
		||||
	//------------COLLECT MESSAGE---------------
 | 
			
		||||
	RS_RES = RS_Collect_Message(hRS, RS_msg, hRS->pBufferPtr);
 | 
			
		||||
	if (RS_RES != RS_OK) // if message isnt collect - stop RS and return error in RS_RES
 | 
			
		||||
	{// need collect message status, so doesnt write abort to RS_RES
 | 
			
		||||
		RS_Abort(hRS, ABORT_RS);
 | 
			
		||||
		RS_Handle_Receive_Start(hRS, hRS->pMessagePtr);	// restart receive
 | 
			
		||||
	}
 | 
			
		||||
	else // if collect successful
 | 
			
		||||
	{
 | 
			
		||||
		
 | 
			
		||||
		//----------INITIALIZE TRANSMIT-------------
 | 
			
		||||
    RS_EnableTransmit();
 | 
			
		||||
//    for(int i = 0; i < hRS->sRS_Timeout; i++);
 | 
			
		||||
    
 | 
			
		||||
		RS_Set_Busy(hRS);							// set RS busy
 | 
			
		||||
		RS_Set_TX_Flags(hRS);					// initialize flags for transmit IT
 | 
			
		||||
		hRS->pMessagePtr = RS_msg; 		// set pointer for filling given structure from UARTHandler fucntion
 | 
			
		||||
 | 
			
		||||
		// if all OK: start transmitting
 | 
			
		||||
		uart_res = HAL_UART_Transmit_IT(hRS->huart, hRS->pBufferPtr, hRS->RS_Message_Size); 
 | 
			
		||||
		// if transmit isnt started - abort RS
 | 
			
		||||
		if(uart_res != HAL_OK)
 | 
			
		||||
		{
 | 
			
		||||
			RS_RES = RS_Abort(hRS, ABORT_RS);
 | 
			
		||||
      printf_rs_err("\n%d: Error RS: Failed to start RS transmitting...", uwTick);
 | 
			
		||||
      TrackerCnt_Err(hRS->rs_err);
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
      RS_RES = RS_OK;
 | 
			
		||||
      printf_rs("\n%d: RS: Start Transmitting...", uwTick);
 | 
			
		||||
      TrackerCnt_Ok(hRS->rs_err);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
	
 | 
			
		||||
	
 | 
			
		||||
	hRS->RS_STATUS = RS_RES;
 | 
			
		||||
	return RS_RES; // returns result of transmit init 	
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** 
 | 
			
		||||
	* @brief 	Initialize UART and handle RS stucture.
 | 
			
		||||
	* @param 	hRS 					- указатель на хендлер RS.
 | 
			
		||||
	* @param 	suart 				- указатель на структуру с настройками UART.
 | 
			
		||||
	* @param 	stim 					- указатель на структуру с настройками таймера.
 | 
			
		||||
	* @param 	pRS_BufferPtr - указатель на буффер для приема-передачи по UART. Если он NULL, то поставиться библиотечный буфер.
 | 
			
		||||
	* @return RS_RES				- статус о состоянии RS после инициализации.
 | 
			
		||||
	* @note		Инициализация перефирии и структуры для приема-передачи по RS.
 | 
			
		||||
	*/
 | 
			
		||||
#ifdef INCLUDE_GENERAL_PERIPH_LIBS
 | 
			
		||||
RS_StatusTypeDef RS_Init(RS_HandleTypeDef *hRS, UART_SettingsTypeDef *suart, TIM_SettingsTypeDef *stim, uint8_t *pRS_BufferPtr)
 | 
			
		||||
#else
 | 
			
		||||
RS_StatusTypeDef RS_Init(RS_HandleTypeDef *hRS, UART_HandleTypeDef *huart, TIM_HandleTypeDef *htim, uint8_t *pRS_BufferPtr)
 | 
			
		||||
#endif
 | 
			
		||||
{
 | 
			
		||||
	// check that hRS is defined
 | 
			
		||||
	if (hRS == NULL)
 | 
			
		||||
		return RS_ERR;
 | 
			
		||||
#ifdef INCLUDE_GENERAL_PERIPH_LIBS
 | 
			
		||||
	// check that huart is defined
 | 
			
		||||
	if ((suart->huart.Instance == NULL) || (suart->huart.Init.BaudRate == NULL)) 
 | 
			
		||||
		return RS_ERR;
 | 
			
		||||
#else
 | 
			
		||||
	// check that huart is defined
 | 
			
		||||
	if (huart == NULL) 
 | 
			
		||||
		return RS_ERR;
 | 
			
		||||
#endif
 | 
			
		||||
	// init uart
 | 
			
		||||
  
 | 
			
		||||
#ifdef INCLUDE_GENERAL_PERIPH_LIBS
 | 
			
		||||
	UART_Base_Init(suart);
 | 
			
		||||
	hRS->huart = &suart->huart;
 | 
			
		||||
#else
 | 
			
		||||
	RS_UART_Init();
 | 
			
		||||
	hRS->huart = huart;
 | 
			
		||||
#endif
 | 
			
		||||
	
 | 
			
		||||
	
 | 
			
		||||
#ifdef INCLUDE_GENERAL_PERIPH_LIBS
 | 
			
		||||
	// check that timeout in interrupt needed
 | 
			
		||||
	if (hRS->sRS_Timeout)
 | 
			
		||||
	{
 | 
			
		||||
		if (stim->htim.Instance == NULL) // check is timer defined
 | 
			
		||||
			return RS_ERR;	
 | 
			
		||||
					
 | 
			
		||||
		// calc frequency corresponding to timeout and tims 1ms tickbase
 | 
			
		||||
		stim->sTickBaseUS = TIM_TickBase_1MS;
 | 
			
		||||
		stim->htim.Init.Period = hRS->sRS_Timeout;
 | 
			
		||||
		
 | 
			
		||||
		TIM_Base_Init(stim);
 | 
			
		||||
		hRS->htim = &stim->htim;
 | 
			
		||||
	}
 | 
			
		||||
#else
 | 
			
		||||
	RS_TIM_Init();
 | 
			
		||||
	hRS->htim = htim;
 | 
			
		||||
#endif
 | 
			
		||||
	
 | 
			
		||||
	if (hRS->sRS_RX_Size_Mode == NULL)
 | 
			
		||||
		return RS_ERR;
 | 
			
		||||
	
 | 
			
		||||
	// check that buffer is defined
 | 
			
		||||
	if (hRS->pBufferPtr == NULL)
 | 
			
		||||
	{
 | 
			
		||||
		hRS->pBufferPtr = RS_Buffer; 		// if no - set default
 | 
			
		||||
	}
 | 
			
		||||
	else
 | 
			
		||||
		hRS->pBufferPtr = pRS_BufferPtr; // if yes - set by user
 | 
			
		||||
		
 | 
			
		||||
	return RS_OK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** 
 | 
			
		||||
	* @brief 	ReInitialize UART and RS receive.
 | 
			
		||||
	* @param 	hRS 					- указатель на хендлер RS.
 | 
			
		||||
	* @param 	suart 				- указатель на структуру с настройками UART.
 | 
			
		||||
	* @return RS_RES				- статус о состоянии RS после инициализации.
 | 
			
		||||
	* @note		Реинициализация UART и приема по RS.
 | 
			
		||||
	*/
 | 
			
		||||
#ifdef INCLUDE_GENERAL_PERIPH_LIBS
 | 
			
		||||
HAL_StatusTypeDef RS_ReInit_UART(RS_HandleTypeDef *hRS, UART_SettingsTypeDef *suart)
 | 
			
		||||
#else
 | 
			
		||||
HAL_StatusTypeDef RS_ReInit_UART(RS_HandleTypeDef *hRS, UART_HandleTypeDef *huart)
 | 
			
		||||
#endif
 | 
			
		||||
{
 | 
			
		||||
	HAL_StatusTypeDef RS_RES;
 | 
			
		||||
	hRS->f.ReInit_UART = 0;
 | 
			
		||||
	
 | 
			
		||||
#ifdef INCLUDE_GENERAL_PERIPH_LIBS
 | 
			
		||||
	// check is settings are valid
 | 
			
		||||
	if(Check_UART_Init_Struct(suart) != HAL_OK)
 | 
			
		||||
		return HAL_ERROR;
 | 
			
		||||
  
 | 
			
		||||
	RS_Abort(hRS, ABORT_RS);
 | 
			
		||||
  
 | 
			
		||||
	UART_MspDeInit(&suart->huart);
 | 
			
		||||
  
 | 
			
		||||
	RS_RES = UART_Base_Init(suart);	
 | 
			
		||||
  
 | 
			
		||||
  RS_RES = RS_UART_Init()
 | 
			
		||||
	
 | 
			
		||||
#else
 | 
			
		||||
//	// check is settings are valid
 | 
			
		||||
//	if(Check_UART_Init_Struct(suart) != HAL_OK)
 | 
			
		||||
//		return HAL_ERROR;
 | 
			
		||||
  
 | 
			
		||||
	RS_Abort(hRS, ABORT_RS);
 | 
			
		||||
  
 | 
			
		||||
	RS_UART_DeInit(huart);
 | 
			
		||||
  
 | 
			
		||||
  RS_UART_Init();
 | 
			
		||||
	
 | 
			
		||||
#endif
 | 
			
		||||
	
 | 
			
		||||
	RS_Receive_IT(hRS, hRS->pMessagePtr);
 | 
			
		||||
	return RS_RES;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
	* @brief 	Abort RS/UART.
 | 
			
		||||
	* @param 	hRS 				- указатель на хендлер RS.
 | 
			
		||||
	* @param 	AbortMode 	- выбор, что надо отменить.
 | 
			
		||||
							- ABORT_TX:		 Отмена передачи по ЮАРТ, с очищением флагов TX,
 | 
			
		||||
							- ABORT_RX:		 Отмена приема по ЮАРТ, с очищением флагов RX,
 | 
			
		||||
							- ABORT_RX_TX: Отмена приема и передачи по ЮАРТ,
 | 
			
		||||
							- ABORT_RS: 	 Отмена приема-передачи RS, с очищением всей структуры.
 | 
			
		||||
	* @return RS_RES			- статус о состоянии RS после аборта.
 | 
			
		||||
	* @note		Отмена работы UART в целом или отмена приема/передачи RS. 
 | 
			
		||||
						Также очищается хендл hRS.
 | 
			
		||||
	*/
 | 
			
		||||
RS_StatusTypeDef RS_Abort(RS_HandleTypeDef *hRS, RS_AbortTypeDef AbortMode)
 | 
			
		||||
{
 | 
			
		||||
	HAL_StatusTypeDef uart_res = 0;
 | 
			
		||||
	hRS->htim->Instance->CNT = 0;
 | 
			
		||||
	__HAL_TIM_CLEAR_IT(hRS->htim, TIM_IT_UPDATE);
 | 
			
		||||
	
 | 
			
		||||
	if(hRS->sRS_Timeout)								// if timeout setted
 | 
			
		||||
		HAL_TIM_Base_Stop_IT(hRS->htim);	// stop timeout
 | 
			
		||||
	
 | 
			
		||||
	if((AbortMode&ABORT_RS) == 0x00)
 | 
			
		||||
	{	
 | 
			
		||||
		if((AbortMode&ABORT_RX) == ABORT_RX)
 | 
			
		||||
		{
 | 
			
		||||
			uart_res = HAL_UART_AbortReceive(hRS->huart); 	// abort receive
 | 
			
		||||
			RS_Reset_RX_Flags(hRS);
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		if((AbortMode&ABORT_TX) == ABORT_TX)
 | 
			
		||||
		{
 | 
			
		||||
			uart_res = HAL_UART_AbortTransmit(hRS->huart); 	// abort transmit
 | 
			
		||||
			RS_Reset_TX_Flags(hRS);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
		uart_res = HAL_UART_Abort(hRS->huart);
 | 
			
		||||
		RS_Clear_All(hRS);
 | 
			
		||||
	}
 | 
			
		||||
	hRS->RS_STATUS = RS_ABORTED;
 | 
			
		||||
	return RS_ABORTED;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//-------------------------GENERAL FUNCTIONS-------------------------
 | 
			
		||||
//-------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//-------------------------------------------------------------------
 | 
			
		||||
//--------------------CALLBACK/HANDLER FUNCTIONS---------------------
 | 
			
		||||
/**
 | 
			
		||||
	* @brief 	Handle for starting receive.
 | 
			
		||||
	* @param 	hRS 		- указатель на хендлер RS.
 | 
			
		||||
	* @param 	RS_msg 	- указатель на структуру сообщения.
 | 
			
		||||
	* @return RS_RES	- статус о состоянии RS после инициализации приема или окончания общения.
 | 
			
		||||
	* @note		Определяет начинать прием команды/ответа или нет.
 | 
			
		||||
	*/
 | 
			
		||||
RS_StatusTypeDef RS_Handle_Receive_Start(RS_HandleTypeDef *hRS, RS_MsgTypeDef *RS_msg)
 | 
			
		||||
{	
 | 
			
		||||
	RS_StatusTypeDef RS_RES = 0;
 | 
			
		||||
	
 | 
			
		||||
	switch(hRS->sRS_Mode)
 | 
			
		||||
	{
 | 
			
		||||
		case SLAVE_ALWAYS_WAIT: 											// in slave mode with permanent waiting
 | 
			
		||||
			RS_RES = RS_Receive_IT(hRS, RS_msg); break; // start receiving again
 | 
			
		||||
		case SLAVE_TIMEOUT_WAIT:											// in slave mode with timeout waiting (start receiving cmd by request)
 | 
			
		||||
			RS_Set_Free(hRS);	 RS_RES = RS_OK; break;		// end RS communication (set RS unbusy)
 | 
			
		||||
	}
 | 
			
		||||
  
 | 
			
		||||
  if(RS_RES != RS_OK)
 | 
			
		||||
  {
 | 
			
		||||
    TrackerCnt_Err(hRS->rs_err);
 | 
			
		||||
  }
 | 
			
		||||
	
 | 
			
		||||
	return RS_RES;
 | 
			
		||||
}
 | 
			
		||||
/**  
 | 
			
		||||
	* @brief 	Handle for starting transmit.
 | 
			
		||||
	* @param 	hRS 		- указатель на хендлер RS.
 | 
			
		||||
	* @param 	RS_msg 	- указатель на структуру сообщения.
 | 
			
		||||
	* @return RS_RES	- статус о состоянии RS после инициализации передачи.
 | 
			
		||||
	* @note		Определяет отвечать ли на команду или нет.
 | 
			
		||||
	*/
 | 
			
		||||
RS_StatusTypeDef RS_Handle_Transmit_Start(RS_HandleTypeDef *hRS, RS_MsgTypeDef *RS_msg)
 | 
			
		||||
{	
 | 
			
		||||
	RS_StatusTypeDef RS_RES = 0;
 | 
			
		||||
	
 | 
			
		||||
	switch(hRS->sRS_Mode)
 | 
			
		||||
	{
 | 
			
		||||
		case SLAVE_ALWAYS_WAIT: 	// in slave mode always response
 | 
			
		||||
		case SLAVE_TIMEOUT_WAIT:	// transmit response
 | 
			
		||||
			RS_RES = RS_Transmit_IT(hRS, RS_msg); break; 
 | 
			
		||||
	}
 | 
			
		||||
  if(RS_RES != RS_OK)
 | 
			
		||||
  {
 | 
			
		||||
    TrackerCnt_Err(hRS->rs_err);
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
	return RS_RES;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**  
 | 
			
		||||
	* @brief 	UART RX Callback: define behaviour after receiving parts of message.
 | 
			
		||||
	* @param 	hRS 		- указатель на хендлер RS.
 | 
			
		||||
	* @return RS_RES	- статус о состоянии RS после обработки приема.
 | 
			
		||||
	* @note		Контролирует прием сообщения: определяет размер принимаемой посылки и обрабатывает его.
 | 
			
		||||
	*/
 | 
			
		||||
RS_StatusTypeDef RS_UART_RxCpltCallback(RS_HandleTypeDef *hRS)
 | 
			
		||||
{
 | 
			
		||||
	RS_StatusTypeDef RS_RES = 0;
 | 
			
		||||
	HAL_StatusTypeDef uart_res = 0;
 | 
			
		||||
	
 | 
			
		||||
	// if we had received bytes before ByteCnt
 | 
			
		||||
	if((hRS->sRS_RX_Size_Mode == RS_RX_Size_NotConst) && (hRS->f.RX_Half == 0)) // if data size isnt constant and its first half, and
 | 
			
		||||
	{	// First receive part of message, then define size of rest of message, and start receive it
 | 
			
		||||
		hRS->f.RX_Half = 1;
 | 
			
		||||
		//---------------FIND DATA SIZE-----------------
 | 
			
		||||
		uint32_t NuRS_of_Rest_Bytes = 0;
 | 
			
		||||
		RS_RES = RS_Define_Size_of_RX_Message(hRS, &NuRS_of_Rest_Bytes);
 | 
			
		||||
		
 | 
			
		||||
		
 | 
			
		||||
		// if there is no bytes to receive OR we need to skip this message - restart receive
 | 
			
		||||
		if ((NuRS_of_Rest_Bytes == 0) || (RS_RES == RS_SKIP))
 | 
			
		||||
		{
 | 
			
		||||
      TrackerCnt_Err(hRS->rs_err);
 | 
			
		||||
			RS_Abort(hRS, ABORT_RX);
 | 
			
		||||
			RS_RES = RS_Handle_Receive_Start(hRS, hRS->pMessagePtr);
 | 
			
		||||
			return RS_RES;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		//-------------START UART RECEIVE---------------
 | 
			
		||||
		uart_res = HAL_UART_Receive_IT(hRS->huart, (hRS->pBufferPtr + RX_FIRST_PART_SIZE), NuRS_of_Rest_Bytes); 
 | 
			
		||||
		
 | 
			
		||||
		if(uart_res != HAL_OK)
 | 
			
		||||
		{// need uart status, so doesnt write abort to RS_RES
 | 
			
		||||
      TrackerCnt_Err(hRS->rs_err);
 | 
			
		||||
			RS_RES = RS_Abort(hRS, ABORT_RS);
 | 
			
		||||
		}
 | 
			
		||||
		else
 | 
			
		||||
			RS_RES = RS_OK;
 | 
			
		||||
	}	 
 | 
			
		||||
	else // if we had received whole message
 | 
			
		||||
	{
 | 
			
		||||
		hRS->f.RX_Half = 0;
 | 
			
		||||
 | 
			
		||||
		//---------PROCESS DATA & ENDING RECEIVING--------
 | 
			
		||||
		RS_Set_RX_End(hRS);
 | 
			
		||||
		
 | 
			
		||||
		if(hRS->sRS_Timeout)								// if timeout setted
 | 
			
		||||
			HAL_TIM_Base_Stop_IT(hRS->htim);	// stop timeout
 | 
			
		||||
		
 | 
			
		||||
		// parse received data
 | 
			
		||||
		RS_RES = RS_Parse_Message(hRS, hRS->pMessagePtr, hRS->pBufferPtr); // parse message
 | 
			
		||||
    
 | 
			
		||||
		// RESPONSE
 | 
			
		||||
		RS_RES = RS_Response(hRS, hRS->pMessagePtr);	
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	return RS_RES;	
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**  
 | 
			
		||||
	* @brief 	UART TX Callback: define behaviour after transmiting message.
 | 
			
		||||
	* @param 	hRS 		- указатель на хендлер RS.
 | 
			
		||||
	* @return RS_RES	- статус о состоянии RS после обработки приема.
 | 
			
		||||
	* @note		Определяет поведение RS после передачи сообщения.
 | 
			
		||||
	*/
 | 
			
		||||
RS_StatusTypeDef RS_UART_TxCpltCallback(RS_HandleTypeDef *hRS)
 | 
			
		||||
{
 | 
			
		||||
	RS_StatusTypeDef RS_RES = RS_OK;
 | 
			
		||||
	HAL_StatusTypeDef uart_res = 0;
 | 
			
		||||
	
 | 
			
		||||
	//--------------ENDING TRANSMITTING-------------
 | 
			
		||||
	RS_Set_TX_End(hRS);
 | 
			
		||||
	RS_EnableReceive();
 | 
			
		||||
//  for(int i = 0; i < hRS->sRS_Timeout; i++);
 | 
			
		||||
	
 | 
			
		||||
	//-----------START RECEIVING or END RS----------
 | 
			
		||||
	RS_RES = RS_Handle_Receive_Start(hRS, hRS->pMessagePtr);
 | 
			
		||||
	
 | 
			
		||||
	return RS_RES;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**  
 | 
			
		||||
	* @brief 	Handler for UART.
 | 
			
		||||
	* @param 	hRS 		- указатель на хендлер RS.
 | 
			
		||||
	* @note		Обрабатывает ошибки если есть и вызывает RS Коллбеки.
 | 
			
		||||
	*					Добавить вызов этой функции в UARTx_IRQHandler().
 | 
			
		||||
	*/
 | 
			
		||||
void RS_UART_Handler(RS_HandleTypeDef *hRS)
 | 
			
		||||
{
 | 
			
		||||
  HAL_UART_IRQHandler(hRS->huart);
 | 
			
		||||
	//-------------CALL RS CALLBACKS------------	
 | 
			
		||||
	/* IF NO ERROR OCCURS */
 | 
			
		||||
	if(hRS->huart->ErrorCode == 0) 
 | 
			
		||||
	{
 | 
			
		||||
		hRS->htim->Instance->CNT = 0; // reset cnt;
 | 
			
		||||
		/* Start timeout */
 | 
			
		||||
		if(hRS->sRS_Timeout)								// if timeout setted
 | 
			
		||||
			if((hRS->huart->RxXferCount+1 == hRS->huart->RxXferSize) && RS_Is_RX_Busy(hRS)) // if first byte is received and receive is active
 | 
			
		||||
      {
 | 
			
		||||
				HAL_TIM_Base_Start_IT(hRS->htim);
 | 
			
		||||
        RS_Set_RX_Active_Flags(hRS);
 | 
			
		||||
      }
 | 
			
		||||
		
 | 
			
		||||
		/* RX Callback */
 | 
			
		||||
		if ((	hRS->huart->RxXferCount == 0U) && RS_Is_RX_Busy(hRS) && 	// if all bytes are received and receive is active
 | 
			
		||||
					hRS->huart->RxState != HAL_UART_STATE_BUSY_RX)						// also check that receive "REALLY" isnt busy
 | 
			
		||||
			RS_UART_RxCpltCallback(hRS);
 | 
			
		||||
		
 | 
			
		||||
		/* TX Callback */
 | 
			
		||||
		if ((	hRS->huart->TxXferCount == 0U) && RS_Is_TX_Busy(hRS) &&  // if all bytes are transmited and transmit is active
 | 
			
		||||
					hRS->huart->gState != HAL_UART_STATE_BUSY_TX)						// also check that receive "REALLY" isnt busy
 | 
			
		||||
			RS_UART_TxCpltCallback(hRS);
 | 
			
		||||
	}
 | 
			
		||||
	//----------------ERRORS HANDLER----------------
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
    TrackerCnt_Err(hRS->rs_err);
 | 
			
		||||
		/* de-init uart transfer */
 | 
			
		||||
		RS_Abort(hRS, ABORT_RS);
 | 
			
		||||
		RS_Handle_Receive_Start(hRS, hRS->pMessagePtr);
 | 
			
		||||
				
 | 
			
		||||
		// later, maybe, will be added specific handlers for err	
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**  
 | 
			
		||||
	* @brief 	Handler for TIM.
 | 
			
		||||
	* @param 	hRS 		- указатель на хендлер RS.
 | 
			
		||||
	* @note		Попадание сюда = таймаут и перезапуск RS приема
 | 
			
		||||
	*					Добавить вызов этой функции в TIMx_IRQHandler().
 | 
			
		||||
	*/
 | 
			
		||||
void RS_TIM_Handler(RS_HandleTypeDef *hRS)
 | 
			
		||||
{
 | 
			
		||||
  HAL_TIM_IRQHandler(hRS->htim);
 | 
			
		||||
	HAL_TIM_Base_Stop_IT(hRS->htim);
 | 
			
		||||
	RS_Abort(hRS, ABORT_RS);	
 | 
			
		||||
	
 | 
			
		||||
	RS_Handle_Receive_Start(hRS, hRS->pMessagePtr);
 | 
			
		||||
}
 | 
			
		||||
//--------------------CALLBACK/HANDLER FUNCTIONS---------------------
 | 
			
		||||
//-------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//-------------------------------------------------------------------
 | 
			
		||||
//--------------WEAK PROTOTYPES FOR PROCESSING MESSAGE---------------
 | 
			
		||||
/** 
 | 
			
		||||
	* @brief 	Respond accord to received message.
 | 
			
		||||
	* @param 	hRS 		- указатель на хендлер RS.
 | 
			
		||||
	* @param 	RS_msg 	- указатель на структуру сообщения.
 | 
			
		||||
	* @return RS_RES	- статус о результате ответа на комманду.
 | 
			
		||||
	* @note		Обработка принятой комманды и ответ на неё.
 | 
			
		||||
	*/
 | 
			
		||||
__weak RS_StatusTypeDef RS_Response(RS_HandleTypeDef *hRS, RS_MsgTypeDef *RS_msg)
 | 
			
		||||
{
 | 
			
		||||
	/* Redefine function for user purposes */
 | 
			
		||||
	return RS_ERR;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** 
 | 
			
		||||
	* @brief 	Collect message in buffer to transmit it.
 | 
			
		||||
	* @param 	hRS 					- указатель на хендлер RS.
 | 
			
		||||
	* @param 	RS_msg 				- указатель на структуру сообщения.
 | 
			
		||||
	* @param 	msg_uart_buff	- указатель на буффер UART.
 | 
			
		||||
	* @return RS_RES				- статус о результате заполнения буфера.
 | 
			
		||||
	* @note		Заполнение буффера UART из структуры сообщения.
 | 
			
		||||
	*/
 | 
			
		||||
__weak RS_StatusTypeDef RS_Collect_Message(RS_HandleTypeDef *hRS, RS_MsgTypeDef *RS_msg, uint8_t *msg_uart_buff)
 | 
			
		||||
{
 | 
			
		||||
	/* Redefine function for user purposes */
 | 
			
		||||
	return RS_ERR;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** 
 | 
			
		||||
	* @brief 	Parse message from buffer to process it.
 | 
			
		||||
	* @param 	hRS 					- указатель на хендлер RS.
 | 
			
		||||
	* @param 	RS_msg 				- указатель на структуру сообщения.
 | 
			
		||||
	* @param 	msg_uart_buff	- указатель на буффер UART.
 | 
			
		||||
	* @return RS_RES				- статус о результате заполнения структуры.
 | 
			
		||||
	* @note		Заполнение структуры сообщения из буффера UART.
 | 
			
		||||
	*/
 | 
			
		||||
__weak RS_StatusTypeDef RS_Parse_Message(RS_HandleTypeDef *hRS, RS_MsgTypeDef *RS_msg, uint8_t *msg_uart_buff)
 | 
			
		||||
{
 | 
			
		||||
	/* Redefine function for user purposes */
 | 
			
		||||
	return RS_ERR;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** 
 | 
			
		||||
	* @brief 	Define size of RX Message that need to be received.
 | 
			
		||||
	* @param 	hRS 					- указатель на хендлер RS.
 | 
			
		||||
	* @param 	rx_data_size 	- указатель на переменную для записи кол-ва байт для принятия.
 | 
			
		||||
	* @return RS_RES				- статус о корректности рассчета кол-ва байт для принятия.
 | 
			
		||||
	* @note		Определение сколько байтов надо принять по протоколу.
 | 
			
		||||
	*/
 | 
			
		||||
__weak RS_StatusTypeDef RS_Define_Size_of_RX_Message(RS_HandleTypeDef *hRS, uint32_t *rx_data_size)
 | 
			
		||||
{
 | 
			
		||||
	/* Redefine function for user purposes */
 | 
			
		||||
	return RS_ERR;
 | 
			
		||||
}
 | 
			
		||||
//--------------WEAK PROTOTYPES FOR PROCESSING MESSAGE---------------
 | 
			
		||||
//-------------------------------------------------------------------
 | 
			
		||||
							
								
								
									
										265
									
								
								diode_tester/Core/Interfaces/rs_message.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										265
									
								
								diode_tester/Core/Interfaces/rs_message.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,265 @@
 | 
			
		||||
/**
 | 
			
		||||
**************************************************************************
 | 
			
		||||
* @file rs_message.h
 | 
			
		||||
* @brief Заголовочный файл для модуля реализации протоколов по RS/UART.
 | 
			
		||||
**************************************************************************
 | 
			
		||||
* @defgroup RS_TOOLS
 | 
			
		||||
* @brief 		Всякое для работы по UART/RS
 | 
			
		||||
**************************************************************************
 | 
			
		||||
@details
 | 
			
		||||
**************************************************************************
 | 
			
		||||
Для настройки RS/UART под нужный протокол, необходимо:
 | 
			
		||||
  - Определить структуру сообщения RS_MsgTypeDef и 
 | 
			
		||||
  дефайны RX_FIRST_PART_SIZE и MSG_SIZE_MAX.
 | 
			
		||||
  - Подключить этот файл в раздел rs_message.h.
 | 
			
		||||
	- Определить функции для обработки сообщения: RS_Parse_Message(), 
 | 
			
		||||
  RS_Collect_Message(), RS_Response(), RS_Define_Size_of_RX_Message()
 | 
			
		||||
	- Добавить UART/TIM Handler в Хендлер используемых UART/TIM.
 | 
			
		||||
 
 | 
			
		||||
Так же данный модуль использует счетчики 
 | 
			
		||||
**************************************************************************
 | 
			
		||||
@verbatim
 | 
			
		||||
Визуальное описание. Форматирование сохраняется как в коде.
 | 
			
		||||
@endverbatim
 | 
			
		||||
*************************************************************************/
 | 
			
		||||
#ifndef __RS_LIB_H_
 | 
			
		||||
#define __RS_LIB_H_
 | 
			
		||||
 | 
			
		||||
#include "modbus.h" 
 | 
			
		||||
 | 
			
		||||
#include "mylibs_include.h"
 | 
			
		||||
#include "crc_algs.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/////////////////////////////////////////////////////////////////////
 | 
			
		||||
////////////////////////////---DEFINES---////////////////////////////
 | 
			
		||||
/* Check that all defines required by RS are defined */
 | 
			
		||||
#ifndef MSG_SIZE_MAX
 | 
			
		||||
#error Define MSG_SIZE_MAX (Maximum size of message). This is necessary to create buffer for UART.
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef RX_FIRST_PART_SIZE
 | 
			
		||||
#error Define RX_FIRST_PART_SIZE (Size of first part of message). This is necessary to receive the first part of the message, from which determine the size of the remaining part of the message.
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/* Clear message-uart buffer */
 | 
			
		||||
#define RS_Clear_Buff(_buff_)				for(int i=0; i<MSG_SIZE_MAX;i++)	_buff_[i] = NULL
 | 
			
		||||
 | 
			
		||||
/* Set/Reset flags */
 | 
			
		||||
#define RS_Set_Free(_hRS_)					_hRS_->f.RS_Busy = 0
 | 
			
		||||
#define RS_Set_Busy(_hRS_)					_hRS_->f.RS_Busy = 1
 | 
			
		||||
 | 
			
		||||
#define RS_Set_RX_Flags(_hRS_)			    _hRS_->f.RX_Busy = 1; _hRS_->f.RX_Done = 0; _hRS_->f.RX_Half = 0
 | 
			
		||||
#define RS_Set_RX_Active_Flags(_hRS_)   _hRS_->f.RX_Ongoing = 1
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#define RS_Set_TX_Flags(_hRS_)			    _hRS_->f.TX_Busy = 1; _hRS_->f.TX_Done = 0
 | 
			
		||||
 | 
			
		||||
#define RS_Reset_RX_Active_Flags(_hRS_) _hRS_->f.RX_Ongoing = 0
 | 
			
		||||
#define RS_Reset_RX_Flags(_hRS_)		    RS_Reset_RX_Active_Flags(_hRS_); _hRS_->f.RX_Busy = 0; _hRS_->f.RX_Done = 0; _hRS_->f.RX_Half = 0
 | 
			
		||||
#define RS_Reset_TX_Flags(_hRS_)		    _hRS_->f.TX_Busy = 0; _hRS_->f.TX_Done = 0
 | 
			
		||||
 | 
			
		||||
#define RS_Set_RX_End_Flag(_hRS_)		_hRS_->f.RX_Done = 1;
 | 
			
		||||
#define RS_Set_TX_End_Flag(_hRS_)		_hRS_->f.TX_Done = 1
 | 
			
		||||
 | 
			
		||||
#define RS_Set_RX_End(_hRS_)				RS_Reset_RX_Flags(_hRS_); RS_Set_RX_End_Flag(_hRS_)
 | 
			
		||||
#define RS_Set_TX_End(_hRS_)				RS_Reset_TX_Flags(_hRS_); RS_Set_TX_End_Flag(_hRS_)
 | 
			
		||||
 | 
			
		||||
/* Clear all RS stuff */
 | 
			
		||||
#define RS_Clear_All(_hRS_) 				RS_Clear_Buff(_hRS_->pBufferPtr);	RS_Reset_RX_Flags(_hRS_);	RS_Reset_TX_Flags(_hRS_);
 | 
			
		||||
 | 
			
		||||
//#define MB_Is_RX_Busy(_hRS_)				((_hRS_->huart->gState&HAL_USART_STATE_BUSY_RX) == HAL_USART_STATE_BUSY_RX)
 | 
			
		||||
//#define MB_Is_TX_Busy(_hRS_)				((_hRS_->huart->gState&HAL_USART_STATE_BUSY_RX) == HAL_USART_STATE_BUSY_TX)
 | 
			
		||||
#define RS_Is_RX_Busy(_hRS_)				(_hRS_->f.RX_Busy == 1)
 | 
			
		||||
#define RS_Is_TX_Busy(_hRS_)				(_hRS_->f.TX_Busy == 1)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifndef RS_EnableReceive
 | 
			
		||||
#define RS_EnableReceive()
 | 
			
		||||
#endif
 | 
			
		||||
#ifndef RS_EnableTransmit
 | 
			
		||||
#define RS_EnableTransmit()
 | 
			
		||||
#endif
 | 
			
		||||
////////////////////////////---DEFINES---////////////////////////////
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/////////////////////////////////////////////////////////////////////
 | 
			
		||||
///////////////////////---STRUCTURES & ENUMS---//////////////////////
 | 
			
		||||
//------------------ENUMERATIONS--------------------
 | 
			
		||||
/** @brief Enums for respond CMD about RS status */
 | 
			
		||||
typedef enum		// RS_StatusTypeDef
 | 
			
		||||
{
 | 
			
		||||
	/* IN-CODE STATUS (start from 0x01, and goes up)*/
 | 
			
		||||
	/*0x01*/	RS_OK = 0x01,
 | 
			
		||||
	/*0x02*/	RS_ERR,	
 | 
			
		||||
	/*0x03*/	RS_ABORTED,	
 | 
			
		||||
	/*0x04*/	RS_BUSY,		
 | 
			
		||||
	/*0x05*/	RS_SKIP,	
 | 
			
		||||
	
 | 
			
		||||
	/*0x06*/	RS_COLLECT_MSG_ERR,
 | 
			
		||||
	/*0x07*/	RS_PARSE_MSG_ERR,
 | 
			
		||||
	
 | 
			
		||||
	// reserved values
 | 
			
		||||
//	/*0x00*/ 	RS_UNKNOWN_ERR = 				0x00, ///< reserved for case, if no one error founded (nothing changed response from zero)
 | 
			
		||||
}RS_StatusTypeDef;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/** @brief Enums for RS Modes */
 | 
			
		||||
typedef enum	// RS_ModeTypeDef
 | 
			
		||||
{
 | 
			
		||||
	SLAVE_ALWAYS_WAIT =				0x01,		///< Slave mode with infinity waiting
 | 
			
		||||
	SLAVE_TIMEOUT_WAIT = 			0x02,		///< Slave mode with waiting with timeout
 | 
			
		||||
//	MASTER = 									0x03,		///< Master mode
 | 
			
		||||
}RS_ModeTypeDef;
 | 
			
		||||
 | 
			
		||||
/** @brief Enums for RS UART Modes */
 | 
			
		||||
typedef enum	// RS_ITModeTypeDef
 | 
			
		||||
{
 | 
			
		||||
	BLCK_MODE = 		0x00,		///< Blocking mode
 | 
			
		||||
	IT_MODE = 			0x01,		///< Interrupt mode
 | 
			
		||||
}RS_ITModeTypeDef;
 | 
			
		||||
 | 
			
		||||
/** @brief Enums for Abort modes */
 | 
			
		||||
typedef enum	// RS_AbortTypeDef
 | 
			
		||||
{
 | 
			
		||||
	ABORT_TX = 			0x01,		///< Abort transmit
 | 
			
		||||
	ABORT_RX = 			0x02,		///< Abort receive
 | 
			
		||||
	ABORT_RX_TX =		0x03,		///< Abort receive and transmit
 | 
			
		||||
	ABORT_RS = 			0x04,		///< Abort uart and reset RS structure
 | 
			
		||||
}RS_AbortTypeDef;
 | 
			
		||||
 | 
			
		||||
/** @brief Enums for RX Size modes */
 | 
			
		||||
typedef enum	// RS_RXSizeTypeDef
 | 
			
		||||
{
 | 
			
		||||
	RS_RX_Size_Const = 			0x01,		///< size of receiving message is constant
 | 
			
		||||
	RS_RX_Size_NotConst = 	0x02,		///< size of receiving message isnt constant
 | 
			
		||||
}RS_RXSizeTypeDef;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//-----------STRUCTURE FOR HANDLE RS------------
 | 
			
		||||
/** @brief Struct for flags RS */
 | 
			
		||||
typedef struct
 | 
			
		||||
{
 | 
			
		||||
	unsigned 									RX_Half:1;						///< flag: 0 - receiving msg before ByteCnt, 	0 - receiving msg after ByteCnt
 | 
			
		||||
	
 | 
			
		||||
	unsigned 									RS_Busy:1;						///< flag: 1 - RS is busy, 0 - RS isnt busy		
 | 
			
		||||
	unsigned 									RX_Ongoing:1;				  ///< flag: 1 - receiving data right now, 	0 - waiting for receiving data
 | 
			
		||||
  
 | 
			
		||||
	unsigned 									RX_Busy:1;						///< flag: 1 - receiving is active, 	0 - receiving isnt active
 | 
			
		||||
	unsigned 									TX_Busy:1;						///< flag: 1 - transmiting is active, 0 - transmiting isnt active				
 | 
			
		||||
	
 | 
			
		||||
	unsigned 									RX_Done:1;						///< flag: 1 - receiving is done, 	0 - receiving isnt done	
 | 
			
		||||
	unsigned 									TX_Done:1;						///< flag: 1 - transmiting is done, 0 - transmiting isnt done	
 | 
			
		||||
		
 | 
			
		||||
	// setted by user
 | 
			
		||||
	unsigned 									MessageHandled:1;		  ///< flag: 1 - RS command is handled, 				0 - RS command isnt handled yet
 | 
			
		||||
	unsigned 									EchoResponse:1;			  ///< flag: 1 - response with received msg,		0 - response with own msg
 | 
			
		||||
	unsigned 									DeferredResponse:1;	  ///< flag: 1 - response not in interrupt, 		0 - response in interrupt
 | 
			
		||||
	unsigned 									ReInit_UART:1;				///< flag: 1 - need to reinitialize uart, 		0 - nothing	
 | 
			
		||||
}RS_FlagsTypeDef;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/** 
 | 
			
		||||
	* @brief 	Handle for RS communication.
 | 
			
		||||
	* @note 	Prefixes: h - handle, s - settings, f - flag
 | 
			
		||||
	*/
 | 
			
		||||
typedef struct	// RS_HandleTypeDef
 | 
			
		||||
{		
 | 
			
		||||
	/* MESSAGE */
 | 
			
		||||
	uint8_t										ID;										///< ID of RS "channel"
 | 
			
		||||
	RS_MsgTypeDef 						*pMessagePtr;					///< pointer to message struct
 | 
			
		||||
	uint8_t 									*pBufferPtr;					///< pointer to message buffer
 | 
			
		||||
	uint32_t									RS_Message_Size;			///< size of whole message, not only data
 | 
			
		||||
	
 | 
			
		||||
	/* HANDLERS and SETTINGS */
 | 
			
		||||
	UART_HandleTypeDef 				*huart;								///< handler for used uart
 | 
			
		||||
	TIM_HandleTypeDef 				*htim;								///< handler for used tim
 | 
			
		||||
	RS_ModeTypeDef						sRS_Mode;							///< setting: slave or master @ref RS_ModeTypeDef
 | 
			
		||||
	RS_ITModeTypeDef					sRS_IT_Mode;					///< setting: 1 - IT mode, 	0 - Blocking mode 
 | 
			
		||||
	uint16_t 									sRS_Timeout;					///< setting: timeout in ms
 | 
			
		||||
	RS_RXSizeTypeDef					sRS_RX_Size_Mode;			///< setting: 1 - not const, 0 - const 
 | 
			
		||||
	
 | 
			
		||||
	/* FLAGS */		
 | 
			
		||||
	RS_FlagsTypeDef           f;                    ///< These flags for controling receive/transmit
 | 
			
		||||
  
 | 
			
		||||
	/* RS STATUS */
 | 
			
		||||
	RS_StatusTypeDef 					RS_STATUS;						///< RS status
 | 
			
		||||
  RS_TrackerTypeDef         rs_err;
 | 
			
		||||
}RS_HandleTypeDef;
 | 
			
		||||
extern RS_HandleTypeDef hmodbus1;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
///////////////////////---STRUCTURES & ENUMS---//////////////////////
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/////////////////////////////////////////////////////////////////////
 | 
			
		||||
///////////////////////////---FUNCTIONS---///////////////////////////
 | 
			
		||||
//----------------FUNCTIONS FOR PROCESSING MESSAGE-------------------
 | 
			
		||||
/*--------------------Defined by users purposes--------------------*/
 | 
			
		||||
/* Respond accord to received message */
 | 
			
		||||
RS_StatusTypeDef RS_Response(RS_HandleTypeDef *hRS, RS_MsgTypeDef *RS_msg);
 | 
			
		||||
 | 
			
		||||
/* Collect message in buffer to transmit it */
 | 
			
		||||
RS_StatusTypeDef RS_Collect_Message(RS_HandleTypeDef *hRS, RS_MsgTypeDef *RS_msg, uint8_t *msg_uart_buff);
 | 
			
		||||
 | 
			
		||||
/* Parse message from buffer to process it */
 | 
			
		||||
RS_StatusTypeDef RS_Parse_Message(RS_HandleTypeDef *hRS, RS_MsgTypeDef *RS_msg, uint8_t *msg_uart_buff);
 | 
			
		||||
 | 
			
		||||
/* Define size of RX Message that need to be received */
 | 
			
		||||
RS_StatusTypeDef RS_Define_Size_of_RX_Message(RS_HandleTypeDef *hRS, uint32_t *rx_data_size);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//-------------------------GENERAL FUNCTIONS-------------------------
 | 
			
		||||
/*-----------------Should be called from main code-----------------*/
 | 
			
		||||
/* Start receive IT */
 | 
			
		||||
RS_StatusTypeDef RS_Receive_IT(RS_HandleTypeDef *hRS, RS_MsgTypeDef *RS_msg);
 | 
			
		||||
 | 
			
		||||
/* Start transmit IT */
 | 
			
		||||
RS_StatusTypeDef RS_Transmit_IT(RS_HandleTypeDef *hRS, RS_MsgTypeDef *RS_msg);
 | 
			
		||||
 | 
			
		||||
/* Initialize UART and handle RS stucture */
 | 
			
		||||
#ifdef INCLUDE_GENERAL_PERIPH_LIBS
 | 
			
		||||
RS_StatusTypeDef RS_Init(RS_HandleTypeDef *hRS, UART_SettingsTypeDef *suart, TIM_SettingsTypeDef *stim, uint8_t *pRS_BufferPtr);
 | 
			
		||||
#else
 | 
			
		||||
RS_StatusTypeDef RS_Init(RS_HandleTypeDef *hRS, UART_HandleTypeDef *huart, TIM_HandleTypeDef *htim, uint8_t *pRS_BufferPtr);
 | 
			
		||||
#endif
 | 
			
		||||
/* ReInitialize UART and RS receive */
 | 
			
		||||
#ifdef INCLUDE_GENERAL_PERIPH_LIBS
 | 
			
		||||
HAL_StatusTypeDef RS_ReInit_UART(RS_HandleTypeDef *hRS, UART_SettingsTypeDef *suart);
 | 
			
		||||
#else
 | 
			
		||||
HAL_StatusTypeDef RS_ReInit_UART(RS_HandleTypeDef *hRS, UART_HandleTypeDef *suart);
 | 
			
		||||
#endif
 | 
			
		||||
/* Abort RS/UART */
 | 
			
		||||
RS_StatusTypeDef RS_Abort(RS_HandleTypeDef *hRS, RS_AbortTypeDef AbortMode);
 | 
			
		||||
//-------------------------GENERAL FUNCTIONS-------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//-------------------------------------------------------------------
 | 
			
		||||
//--------------------CALLBACK/HANDLER FUNCTIONS---------------------
 | 
			
		||||
/* Handle for starting receive */
 | 
			
		||||
RS_StatusTypeDef RS_Handle_Receive_Start(RS_HandleTypeDef *hRS, RS_MsgTypeDef *RS_msg);
 | 
			
		||||
/* Handle for starting transmit */
 | 
			
		||||
RS_StatusTypeDef RS_Handle_Transmit_Start(RS_HandleTypeDef *hRS, RS_MsgTypeDef *RS_msg);
 | 
			
		||||
/* UART RX Callback: define behaviour after receiving parts of message */
 | 
			
		||||
RS_StatusTypeDef RS_UART_RxCpltCallback(RS_HandleTypeDef *hRS);
 | 
			
		||||
/* UART TX Callback: define behaviour after transmiting message */
 | 
			
		||||
RS_StatusTypeDef RS_UART_TxCpltCallback(RS_HandleTypeDef *hRS);
 | 
			
		||||
/* Handler for UART */
 | 
			
		||||
void RS_UART_Handler(RS_HandleTypeDef *hRS);
 | 
			
		||||
/* Handler for TIM */
 | 
			
		||||
void RS_TIM_Handler(RS_HandleTypeDef *hRS);
 | 
			
		||||
//--------------------CALLBACK/HANDLER FUNCTIONS---------------------
 | 
			
		||||
///////////////////////////---FUNCTIONS---///////////////////////////
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifndef printf_rs_err
 | 
			
		||||
#define printf_rs_err(...)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef printf_rs
 | 
			
		||||
#define printf_rs(...)
 | 
			
		||||
#endif
 | 
			
		||||
#endif // __RS_LIB_H_
 | 
			
		||||
							
								
								
									
										249
									
								
								diode_tester/Core/MyLibs/bit_access.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										249
									
								
								diode_tester/Core/MyLibs/bit_access.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,249 @@
 | 
			
		||||
/** 
 | 
			
		||||
**************************************************************************
 | 
			
		||||
* @file mylibs_defs.h
 | 
			
		||||
* @brief Заголочный файл для дефайнов библиотеки MyLibsGeneral.
 | 
			
		||||
**************************************************************************
 | 
			
		||||
* @defgroup BIT_ACCESS_DEFINES    Bit access defines
 | 
			
		||||
* @ingroup  MYLIBS_DEFINES
 | 
			
		||||
* @brief 		Всякое для доступа к битам в unsigned
 | 
			
		||||
*************************************************************************/
 | 
			
		||||
#ifndef __BIT_ACCESS_H_
 | 
			
		||||
#define __BIT_ACCESS_H_
 | 
			
		||||
#include "mylibs_defs.h"
 | 
			
		||||
 | 
			
		||||
/** 
 | 
			
		||||
	* @addtogroup BIT_ACCESS_TYPEDEF   Byte access typedefs
 | 
			
		||||
	* @ingroup 		BIT_ACCESS_DEFINES
 | 
			
		||||
  * @brief 		  Дефайны юнионов для обращения к битам.
 | 
			
		||||
	@{
 | 
			
		||||
	*/
 | 
			
		||||
typedef union
 | 
			
		||||
{
 | 
			
		||||
  uint8_t all;
 | 
			
		||||
  struct
 | 
			
		||||
  {
 | 
			
		||||
    unsigned bit0:1;
 | 
			
		||||
    unsigned bit1:1;
 | 
			
		||||
    unsigned bit2:1;
 | 
			
		||||
    unsigned bit3:1;
 | 
			
		||||
    unsigned reserved:4;
 | 
			
		||||
  }bit;
 | 
			
		||||
}uint4_BitTypeDef;
 | 
			
		||||
 | 
			
		||||
typedef union
 | 
			
		||||
{
 | 
			
		||||
  uint8_t all;
 | 
			
		||||
  struct
 | 
			
		||||
  {
 | 
			
		||||
    unsigned bit0:1;
 | 
			
		||||
    unsigned bit1:1;
 | 
			
		||||
    unsigned bit2:1;
 | 
			
		||||
    unsigned bit3:1;
 | 
			
		||||
    unsigned bit4:1;
 | 
			
		||||
    unsigned reserved:3;
 | 
			
		||||
  }bit;
 | 
			
		||||
}uint5_BitTypeDef;
 | 
			
		||||
 | 
			
		||||
typedef union
 | 
			
		||||
{
 | 
			
		||||
  uint8_t all;
 | 
			
		||||
  struct
 | 
			
		||||
  {
 | 
			
		||||
    unsigned bit0:1;
 | 
			
		||||
    unsigned bit1:1;
 | 
			
		||||
    unsigned bit2:1;
 | 
			
		||||
    unsigned bit3:1;
 | 
			
		||||
    unsigned bit4:1;
 | 
			
		||||
    unsigned bit5:1;
 | 
			
		||||
    unsigned reserved:2;
 | 
			
		||||
  }bit;
 | 
			
		||||
}uint6_BitTypeDef;
 | 
			
		||||
 | 
			
		||||
typedef union
 | 
			
		||||
{
 | 
			
		||||
  uint8_t all;
 | 
			
		||||
  struct
 | 
			
		||||
  {
 | 
			
		||||
    unsigned bit0:1;
 | 
			
		||||
    unsigned bit1:1;
 | 
			
		||||
    unsigned bit2:1;
 | 
			
		||||
    unsigned bit3:1;
 | 
			
		||||
    unsigned bit4:1;
 | 
			
		||||
    unsigned bit5:1;
 | 
			
		||||
    unsigned bit6:1;
 | 
			
		||||
    unsigned reserved:1;
 | 
			
		||||
  }bit;
 | 
			
		||||
}uint7_BitTypeDef;
 | 
			
		||||
 | 
			
		||||
typedef union
 | 
			
		||||
{
 | 
			
		||||
  uint8_t all;
 | 
			
		||||
  struct
 | 
			
		||||
  {
 | 
			
		||||
    unsigned bit0:1;
 | 
			
		||||
    unsigned bit1:1;
 | 
			
		||||
    unsigned bit2:1;
 | 
			
		||||
    unsigned bit3:1;
 | 
			
		||||
    unsigned bit4:1;
 | 
			
		||||
    unsigned bit5:1;
 | 
			
		||||
    unsigned bit6:1;
 | 
			
		||||
    unsigned bit7:1;
 | 
			
		||||
  }bit;
 | 
			
		||||
}uint8_BitTypeDef;
 | 
			
		||||
 | 
			
		||||
typedef union
 | 
			
		||||
{
 | 
			
		||||
  uint16_t all;
 | 
			
		||||
  struct
 | 
			
		||||
  {
 | 
			
		||||
    unsigned bit0:1;
 | 
			
		||||
    unsigned bit1:1;
 | 
			
		||||
    unsigned bit2:1;
 | 
			
		||||
    unsigned bit3:1;
 | 
			
		||||
    unsigned bit4:1;
 | 
			
		||||
    unsigned bit5:1;
 | 
			
		||||
    unsigned bit6:1;
 | 
			
		||||
    unsigned bit7:1;
 | 
			
		||||
    unsigned bit8:1;
 | 
			
		||||
    unsigned bit9:1;
 | 
			
		||||
    unsigned bit10:1;
 | 
			
		||||
    unsigned bit11:1;
 | 
			
		||||
    unsigned bit12:1;
 | 
			
		||||
    unsigned bit13:1;
 | 
			
		||||
    unsigned bit14:1;
 | 
			
		||||
    unsigned bit15:1;
 | 
			
		||||
  }bit;
 | 
			
		||||
}uint16_BitTypeDef;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
typedef union
 | 
			
		||||
{
 | 
			
		||||
  uint32_t all;
 | 
			
		||||
  struct
 | 
			
		||||
  {
 | 
			
		||||
    unsigned bit0:1;
 | 
			
		||||
    unsigned bit1:1;
 | 
			
		||||
    unsigned bit2:1;
 | 
			
		||||
    unsigned bit3:1;
 | 
			
		||||
    unsigned bit4:1;
 | 
			
		||||
    unsigned bit5:1;
 | 
			
		||||
    unsigned bit6:1;
 | 
			
		||||
    unsigned bit7:1;
 | 
			
		||||
    unsigned bit8:1;
 | 
			
		||||
    unsigned bit9:1;
 | 
			
		||||
    unsigned bit10:1;
 | 
			
		||||
    unsigned bit11:1;
 | 
			
		||||
    unsigned bit12:1;
 | 
			
		||||
    unsigned bit13:1;
 | 
			
		||||
    unsigned bit14:1;
 | 
			
		||||
    unsigned bit15:1;
 | 
			
		||||
    unsigned bit16:1;
 | 
			
		||||
    unsigned bit17:1;
 | 
			
		||||
    unsigned bit18:1;
 | 
			
		||||
    unsigned bit19:1;
 | 
			
		||||
    unsigned bit20:1;
 | 
			
		||||
    unsigned bit21:1;
 | 
			
		||||
    unsigned bit22:1;
 | 
			
		||||
    unsigned bit23:1;
 | 
			
		||||
    unsigned bit24:1;
 | 
			
		||||
    unsigned bit25:1;
 | 
			
		||||
    unsigned bit26:1;
 | 
			
		||||
    unsigned bit27:1;
 | 
			
		||||
    unsigned bit28:1;
 | 
			
		||||
    unsigned bit29:1;
 | 
			
		||||
    unsigned bit30:1;
 | 
			
		||||
    unsigned bit31:1;
 | 
			
		||||
  }bit;
 | 
			
		||||
}uint32_BitTypeDef;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
typedef union
 | 
			
		||||
{
 | 
			
		||||
  uint64_t all;
 | 
			
		||||
  struct
 | 
			
		||||
  {
 | 
			
		||||
    unsigned bit0:1;
 | 
			
		||||
    unsigned bit1:1;
 | 
			
		||||
    unsigned bit2:1;
 | 
			
		||||
    unsigned bit3:1;
 | 
			
		||||
    unsigned bit4:1;
 | 
			
		||||
    unsigned bit5:1;
 | 
			
		||||
    unsigned bit6:1;
 | 
			
		||||
    unsigned bit7:1;
 | 
			
		||||
    unsigned bit8:1;
 | 
			
		||||
    unsigned bit9:1;
 | 
			
		||||
    unsigned bit10:1;
 | 
			
		||||
    unsigned bit11:1;
 | 
			
		||||
    unsigned bit12:1;
 | 
			
		||||
    unsigned bit13:1;
 | 
			
		||||
    unsigned bit14:1;
 | 
			
		||||
    unsigned bit15:1;
 | 
			
		||||
    unsigned bit16:1;
 | 
			
		||||
    unsigned bit17:1;
 | 
			
		||||
    unsigned bit18:1;
 | 
			
		||||
    unsigned bit19:1;
 | 
			
		||||
    unsigned bit20:1;
 | 
			
		||||
    unsigned bit21:1;
 | 
			
		||||
    unsigned bit22:1;
 | 
			
		||||
    unsigned bit23:1;
 | 
			
		||||
    unsigned bit24:1;
 | 
			
		||||
    unsigned bit25:1;
 | 
			
		||||
    unsigned bit26:1;
 | 
			
		||||
    unsigned bit27:1;
 | 
			
		||||
    unsigned bit28:1;
 | 
			
		||||
    unsigned bit29:1;
 | 
			
		||||
    unsigned bit30:1;
 | 
			
		||||
    unsigned bit31:1;
 | 
			
		||||
    unsigned bit32:1;
 | 
			
		||||
    unsigned bit33:1;
 | 
			
		||||
    unsigned bit34:1;
 | 
			
		||||
    unsigned bit35:1;
 | 
			
		||||
    unsigned bit36:1;
 | 
			
		||||
    unsigned bit37:1;
 | 
			
		||||
    unsigned bit38:1;
 | 
			
		||||
    unsigned bit39:1;
 | 
			
		||||
    unsigned bit40:1;
 | 
			
		||||
    unsigned bit41:1;
 | 
			
		||||
    unsigned bit42:1;
 | 
			
		||||
    unsigned bit43:1;
 | 
			
		||||
    unsigned bit44:1;
 | 
			
		||||
    unsigned bit45:1;
 | 
			
		||||
    unsigned bit46:1;
 | 
			
		||||
    unsigned bit47:1;
 | 
			
		||||
    unsigned bit48:1;
 | 
			
		||||
    unsigned bit49:1;
 | 
			
		||||
    unsigned bit50:1;
 | 
			
		||||
    unsigned bit51:1;
 | 
			
		||||
    unsigned bit52:1;
 | 
			
		||||
    unsigned bit53:1;
 | 
			
		||||
    unsigned bit54:1;
 | 
			
		||||
    unsigned bit55:1;
 | 
			
		||||
    unsigned bit56:1;
 | 
			
		||||
    unsigned bit57:1;
 | 
			
		||||
    unsigned bit58:1;
 | 
			
		||||
    unsigned bit59:1;
 | 
			
		||||
    unsigned bit60:1;
 | 
			
		||||
    unsigned bit61:1;
 | 
			
		||||
    unsigned bit62:1;
 | 
			
		||||
    unsigned bit63:1;
 | 
			
		||||
  }bit;
 | 
			
		||||
}uint64_BitTypeDef;
 | 
			
		||||
/** BIT_ACCESS_TYPEDEF
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** 
 | 
			
		||||
	* @addtogroup BIT_ACCESS_FUNCTIONS   Byte access functions
 | 
			
		||||
	* @ingroup 		BIT_ACCESS_DEFINES
 | 
			
		||||
  * @brief 		  Дефайны для обращения к битам в unsigned.
 | 
			
		||||
	@{
 | 
			
		||||
	*/
 | 
			
		||||
#define uint8_bit(_uint8_, _bit_)       (*(uint8_BitTypeDef *)(&(_uint8_))).bit.bit##_bit_
 | 
			
		||||
#define uint16_bit(_uint8_, _bit_)      (*(uint16_BitTypeDef *)(&(_uint8_))).bit.bit##_bit_
 | 
			
		||||
#define uint32_bit(_uint8_, _bit_)      (*(uint32_BitTypeDef *)(&(_uint8_))).bit.bit##_bit_
 | 
			
		||||
#define uint64_bit(_uint8_, _bit_)      (*(uint64_BitTypeDef *)(&(_uint8_))).bit.bit##_bit_
 | 
			
		||||
 
 | 
			
		||||
/** BIT_ACCESS_FUNCTIONS
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
#endif //__BIT_ACCESS_H_
 | 
			
		||||
							
								
								
									
										36
									
								
								diode_tester/Core/MyLibs/mylibs_config.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								diode_tester/Core/MyLibs/mylibs_config.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,36 @@
 | 
			
		||||
/** 
 | 
			
		||||
**************************************************************************
 | 
			
		||||
* @file mylibs_config.h
 | 
			
		||||
* @brief Конфигурации для библиотек MyLibs
 | 
			
		||||
**************************************************************************
 | 
			
		||||
* @defgroup MYLIBS_CONFIG   Configs My Libs
 | 
			
		||||
* @ingroup  MYLIBS_ALL
 | 
			
		||||
* @brief 		Конфигурации для библиотек MyLibs
 | 
			
		||||
@{
 | 
			
		||||
*************************************************************************/
 | 
			
		||||
#ifndef __MYLIBS_CONFIG_H_
 | 
			
		||||
#define __MYLIBS_CONFIG_H_
 | 
			
		||||
 | 
			
		||||
#include "stm32f1xx_hal.h"
 | 
			
		||||
 | 
			
		||||
// user includes
 | 
			
		||||
#include "interface_config.h"
 | 
			
		||||
#include "tester_config.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#define RS_USER_VARS_NUMB       0
 | 
			
		||||
#define ADC_USER_VARS_NUMB      0
 | 
			
		||||
#define ADC_CH_USER_VARS_NUMB   0
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#define INCLUDE_BIT_ACCESS_LIB
 | 
			
		||||
#define INCLUDE_TRACKERS_LIB
 | 
			
		||||
#define INCLUDE_TRACE_LIB
 | 
			
		||||
//#define INCLUDE_GENERAL_PERIPH_LIBS
 | 
			
		||||
//#define FREERTOS_DELAY
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/** MYLIBS_CONFIG
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
#endif //__MYLIBS_CONFIG_H_
 | 
			
		||||
							
								
								
									
										106
									
								
								diode_tester/Core/MyLibs/mylibs_defs.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										106
									
								
								diode_tester/Core/MyLibs/mylibs_defs.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,106 @@
 | 
			
		||||
/** 
 | 
			
		||||
**************************************************************************
 | 
			
		||||
* @file mylibs_defs.h
 | 
			
		||||
* @brief Заголочный файл для дефайнов библиотеки MyLibsGeneral.
 | 
			
		||||
**************************************************************************
 | 
			
		||||
* @defgroup MYLIBS_DEFINES  My Libs defines
 | 
			
		||||
* @brief 		Базовые дефайны для всего проекта
 | 
			
		||||
*
 | 
			
		||||
*************************************************************************/
 | 
			
		||||
#ifndef __MYLIBS_DEFINES_H_
 | 
			
		||||
#define __MYLIBS_DEFINES_H_
 | 
			
		||||
 | 
			
		||||
#include "stm32f1xx_hal.h"
 | 
			
		||||
#include "mylibs_config.h"
 | 
			
		||||
 | 
			
		||||
/***************************************************************************
 | 
			
		||||
******************************ERROR_HANDLER********************************/
 | 
			
		||||
/** 
 | 
			
		||||
	* @addtogroup ERROR_HANDLER_DEFINES   Error Handler defines
 | 
			
		||||
	* @ingroup 		MYLIBS_DEFINES
 | 
			
		||||
  * @brief 		  Дефайны для определения функции обработки ошибок
 | 
			
		||||
	@{
 | 
			
		||||
	*/
 | 
			
		||||
 | 
			
		||||
/* extern Error_Handler from main.h */
 | 
			
		||||
extern void Error_Handler(void);
 | 
			
		||||
 | 
			
		||||
/* Define error handler for MyLibs */
 | 
			
		||||
#define MyLibs_Error_Handler(_params_) 	Error_Handler(_params_)
 | 
			
		||||
/* If error handler not defined - set void */
 | 
			
		||||
#ifndef MyLibs_Error_Handler
 | 
			
		||||
#define ((void)0U)
 | 
			
		||||
#endif // MyLibs_Error_Handler
 | 
			
		||||
 | 
			
		||||
/** ERROR_HANDLER_DEFINES
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
  
 | 
			
		||||
 | 
			
		||||
/***************************************************************************
 | 
			
		||||
********************************ACCESS_DEFINES*****************************/
 | 
			
		||||
 | 
			
		||||
#define ClearStruct(_struct_)     memset(&(_struct_), 0, sizeof(_struct_))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/***************************************************************************
 | 
			
		||||
******************************DELAYS_DEFINES*******************************/
 | 
			
		||||
/** 
 | 
			
		||||
	* @addtogroup DELAYS_DEFINES    Delays defines
 | 
			
		||||
	* @ingroup 		MYLIBS_DEFINES
 | 
			
		||||
  * @brief 		  Дефайны для реализации задержек
 | 
			
		||||
	@{
 | 
			
		||||
	*/
 | 
			
		||||
 | 
			
		||||
#ifdef FREERTOS_DELAY
 | 
			
		||||
	#define msDelay(_ms_)			osDelay(_ms_)
 | 
			
		||||
#else
 | 
			
		||||
	#define msDelay(_ms_)			HAL_Delay(_ms_)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/** DELAYS_DEFINES
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/***************************************************************************
 | 
			
		||||
*******************************MATH_DEFINES********************************/
 | 
			
		||||
/** 
 | 
			
		||||
	* @addtogroup MATH_DEFINES      Math defines
 | 
			
		||||
	* @ingroup 		MYLIBS_DEFINES
 | 
			
		||||
  * @brief 		  Дефайны для различных математических функций
 | 
			
		||||
	@{
 | 
			
		||||
	*/
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
	* @brief	Calc dividing including remainder
 | 
			
		||||
	*	@param 	_val_		- делимое.
 | 
			
		||||
	*	@param 	_div_		- делитель.
 | 
			
		||||
	*	@details 	Если результат деления без остатка: он возвращается как есть
 | 
			
		||||
						Если с остатком - округляется вверх
 | 
			
		||||
	*/
 | 
			
		||||
//#define Divide_Up(_val_, _div_)												(((_val_)%(_div_))? (_val_)/(_div_)+1 : (_val_)/_div_)	/* через тернарный оператор */
 | 
			
		||||
#define Divide_Up(_val_, _div_)												((_val_ - 1) / _div_) + 1																	/* через мат выражение */	
 | 
			
		||||
 | 
			
		||||
/** 
 | 
			
		||||
	* @brief 	Swap between Little Endian and Big Endian
 | 
			
		||||
	* @param 	v 			- Переменная для свапа.
 | 
			
		||||
  * @return v (new)	- Свапнутая переменная.
 | 
			
		||||
  * @details 	Переключения между двумя типами хранения слова: HI-LO байты и LO-HI байты.
 | 
			
		||||
	*/
 | 
			
		||||
#define ByteSwap16(v)																	(((v&0xFF00) >> (8)) | ((v&0x00FF) << (8)))
 | 
			
		||||
 | 
			
		||||
/** 
 | 
			
		||||
	* @brief 	Absolute
 | 
			
		||||
	* @param 	x 			- Переменная для модудя.
 | 
			
		||||
  * @return x (new)	- Число по модулю.
 | 
			
		||||
  * @details  Берет число по модулю. Хз как работает библиотечный abs в stdlib.h, мб это быстрее, но вряд ли конечно.
 | 
			
		||||
	*/
 | 
			
		||||
#define ABS(x) ( ((x) > 0)? (x) : -(x))?
 | 
			
		||||
 | 
			
		||||
/** MATH_DEFINES
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
  
 | 
			
		||||
#endif //__MYLIBS_DEFINES_H_
 | 
			
		||||
							
								
								
									
										79
									
								
								diode_tester/Core/MyLibs/mylibs_include.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										79
									
								
								diode_tester/Core/MyLibs/mylibs_include.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,79 @@
 | 
			
		||||
/** 
 | 
			
		||||
**************************************************************************
 | 
			
		||||
* @file mylibs_include.h
 | 
			
		||||
* @brief Заголочный файл для всех библиотек
 | 
			
		||||
**************************************************************************
 | 
			
		||||
@details
 | 
			
		||||
Здесь нужно собрать библиотеки и дефайны, которые должны быть видны во всем проекте,
 | 
			
		||||
чтобы не подключать 100 инклюдов в каждом ".c" файле
 | 
			
		||||
**************************************************************************
 | 
			
		||||
* @defgroup MYLIBS_ALL      My Libs
 | 
			
		||||
* @brief 		Все используемые MyLibs библиотеки
 | 
			
		||||
*
 | 
			
		||||
*************************************************************************/
 | 
			
		||||
#ifndef __MYLIBS_INCLUDE_H_
 | 
			
		||||
#define __MYLIBS_INCLUDE_H_
 | 
			
		||||
 | 
			
		||||
#include "mylibs_defs.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifdef ARM_MATH_CM4
 | 
			
		||||
	#include "arm_math.h"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifdef INCLUDE_BIT_ACCESS_LIB
 | 
			
		||||
#include "bit_access.h"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef INCLUDE_TRACKERS_LIB
 | 
			
		||||
#include "trackers.h"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef INCLUDE_TRACE_LIB
 | 
			
		||||
#include "trace.h"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifdef INCLUDE_GENERAL_PERIPH_LIBS
 | 
			
		||||
 | 
			
		||||
#include "general_flash.h"
 | 
			
		||||
#include "general_gpio.h"
 | 
			
		||||
#ifdef HAL_SPI_MODULE_ENABLED
 | 
			
		||||
#include "general_spi.h"
 | 
			
		||||
#endif
 | 
			
		||||
#ifdef HAL_UART_MODULE_ENABLED
 | 
			
		||||
#include "general_uart.h"
 | 
			
		||||
#endif
 | 
			
		||||
#ifdef HAL_TIM_MODULE_ENABLED
 | 
			
		||||
#include "general_tim.h"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#endif //INCLUDE_GENERAL_PERIPH_LIBS
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/////////////////////////---USER SETTINGS---/////////////////////////
 | 
			
		||||
// user includes
 | 
			
		||||
#include "stdlib.h"
 | 
			
		||||
#include "string.h"
 | 
			
		||||
#include "stdio.h"
 | 
			
		||||
#include "math.h"
 | 
			
		||||
 | 
			
		||||
#include "main.h"
 | 
			
		||||
#include "modbus_data.h"
 | 
			
		||||
 | 
			
		||||
/** @brief Struct for trackers for Measure */
 | 
			
		||||
/** @brief Struct for trackers for RS */
 | 
			
		||||
typedef TrackerTypeDef(RS_USER_VARS_NUMB)      RS_TrackerTypeDef;
 | 
			
		||||
/** @brief Struct for trackers for ADC */
 | 
			
		||||
typedef TrackerTypeDef(ADC_USER_VARS_NUMB)     ADC_TrackerTypeDef;
 | 
			
		||||
/** @brief Struct for trackers for ADC Channel */
 | 
			
		||||
typedef TrackerTypeDef(ADC_CH_USER_VARS_NUMB)  ADCChannel_TrackerTypeDef;
 | 
			
		||||
/////////////////////////---USER SETTINGS---/////////////////////////
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif // __MYLIBS_INCLUDE_H_
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										80
									
								
								diode_tester/Core/MyLibs/trace.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										80
									
								
								diode_tester/Core/MyLibs/trace.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,80 @@
 | 
			
		||||
/** 
 | 
			
		||||
**************************************************************************
 | 
			
		||||
* @file trace.h
 | 
			
		||||
* @brief Заголочный файл для работы с трассировкой.
 | 
			
		||||
**************************************************************************
 | 
			
		||||
* @addtogroup 	TRACE           Trace defines
 | 
			
		||||
* @ingroup 		  MYLIBS_DEFINES
 | 
			
		||||
* @brief 		    Дефайны для работы с трассировкой
 | 
			
		||||
*************************************************************************/
 | 
			
		||||
#ifndef __TRACE_H_
 | 
			
		||||
#define __TRACE_H_
 | 
			
		||||
#include "mylibs_defs.h"
 | 
			
		||||
 | 
			
		||||
/** 
 | 
			
		||||
	* @addtogroup TRACE_SERIAL    Serial trace defines
 | 
			
		||||
	* @ingroup 		TRACE
 | 
			
		||||
  * @brief 		  Дефайны для работы с serial трассировкой
 | 
			
		||||
  * @details    Определяется дефайн my_printf() для работы с serial трассировкой:
 | 
			
		||||
    - для RTT это будет вызов функции SEGGER_RTT_printf(), с подключением библиотеки SEGGER_RTT.h
 | 
			
		||||
    - для SWO это будет просто printf(), но библиотеку STDOUT надо подключить самостоятельно:
 | 
			
		||||
    
 | 
			
		||||
    @verbatim
 | 
			
		||||
    Manage Run-Time Environment -> Compiler -> I/O -> STDOUT
 | 
			
		||||
    @endverbatim
 | 
			
		||||
    
 | 
			
		||||
    - Если трассировка отключена, то все дефайны определяются как 'ничего' и на производительность кода не влияют
 | 
			
		||||
	@{
 | 
			
		||||
	*/
 | 
			
		||||
/* Выбор какой serial trace использовать */
 | 
			
		||||
#ifdef SERIAL_TRACE_ENABLE
 | 
			
		||||
 | 
			
		||||
  #if defined(RTT_TRACE_ENABLE)
 | 
			
		||||
    #undef SWO_TRACE_ENABLE
 | 
			
		||||
    #include "SEGGER_RTT.h"
 | 
			
		||||
    #define my_printf(...)     SEGGER_RTT_printf(0, __VA_ARGS__)
 | 
			
		||||
  #elif defined(SWO_TRACE_ENABLE)
 | 
			
		||||
    #undef RTT_TRACE_ENABLE
 | 
			
		||||
    #define my_printf(...)     printf(__VA_ARGS__)
 | 
			
		||||
  #else // NO_TRACE
 | 
			
		||||
    #define my_printf(...)     
 | 
			
		||||
    #warning No trace is selected. Serial debug wont work.
 | 
			
		||||
  #endif // RTT_TRACE_ENABLE/SWO_TRACE_ENABLE/NO_TRACE
 | 
			
		||||
#else //SERIAL_TRACE_ENABLE
 | 
			
		||||
  #define my_printf(...)     
 | 
			
		||||
  #undef RTT_TRACE_ENABLE
 | 
			
		||||
  #undef SWO_TRACE_ENABLE
 | 
			
		||||
 | 
			
		||||
#endif //SERIAL_TRACE_ENABLE
 | 
			
		||||
 | 
			
		||||
/** TRACE_SERIAL
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/** 
 | 
			
		||||
	* @addtogroup TRACE_GPIO    GPIO trace defines
 | 
			
		||||
	* @ingroup 		TRACE
 | 
			
		||||
  * @brief 		  Дефайны для работы с GPIO трассировкой
 | 
			
		||||
  * @details    Определяется дефайны для работы с GPIO трассировкой:
 | 
			
		||||
    - TRACE_GPIO_RESET() - для сброса ножки GPIO (через BSRR)
 | 
			
		||||
    - TRACE_GPIO_SET() - для выставления ножки GPIO (через BSRR)
 | 
			
		||||
    
 | 
			
		||||
    - Если трассировка отключена, то все дефайны определяются как 'ничего' и на производительность кода не влияют
 | 
			
		||||
	@{
 | 
			
		||||
	*/
 | 
			
		||||
#ifndef GPIO_TRACE_ENABLE
 | 
			
		||||
  #define TRACE_GPIO_RESET(_gpio_,_pin_)
 | 
			
		||||
  #define TRACE_GPIO_SET(_gpio_,_pin_)
 | 
			
		||||
#else
 | 
			
		||||
  #define TRACE_GPIO_RESET(_gpio_,_pin_)				(_gpio_)->BSRR = ((_pin_)<<16)
 | 
			
		||||
  #define TRACE_GPIO_SET(_gpio_,_pin_)					(_gpio_)->BSRR = (((_pin_)))
 | 
			
		||||
#endif //GPIO_TRACE_ENABLE
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/** TRACE_GPIO
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif //__TRACE_H_
 | 
			
		||||
							
								
								
									
										141
									
								
								diode_tester/Core/MyLibs/trackers.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										141
									
								
								diode_tester/Core/MyLibs/trackers.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,141 @@
 | 
			
		||||
/** 
 | 
			
		||||
**************************************************************************
 | 
			
		||||
* @file mylibs_defs.h
 | 
			
		||||
* @brief Заголочный файл для дефайнов библиотеки MyLibsGeneral.
 | 
			
		||||
**************************************************************************
 | 
			
		||||
* @defgroup MYLIBS_DEFINES  My Libs defines
 | 
			
		||||
* @brief 		Базовые дефайны для всего проекта
 | 
			
		||||
*
 | 
			
		||||
*************************************************************************/
 | 
			
		||||
#ifndef __TRACKERS_H_
 | 
			
		||||
#define __TRACKERS_H_
 | 
			
		||||
#include "mylibs_defs.h"
 | 
			
		||||
 | 
			
		||||
/** 
 | 
			
		||||
	* @addtogroup TRACKERS        Trackers defines
 | 
			
		||||
	* @ingroup 		MYLIBS_DEFINES
 | 
			
		||||
  * @brief 		  Дефайны для работы с трекерами
 | 
			
		||||
  * @details    Есть дефайн для объявления структуры трекера: TrackerTypeDef(num_user_vars). 
 | 
			
		||||
    Структура состоит из следующих элементов: 
 | 
			
		||||
    - cnt_ok
 | 
			
		||||
    - cnt_err
 | 
			
		||||
    - cnt_warn
 | 
			
		||||
    - user[num_user_vars]    
 | 
			
		||||
    Также есть ряд функций (дефайнов) для обращения к элементам этой структуры.
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
    Если трассировка отключена, то все дефайны определяются как ничего и на производительность кода не влияют  
 | 
			
		||||
    
 | 
			
		||||
    @par Пример:
 | 
			
		||||
    Определяем typedef трекера измерений @ref Measure_TrackerTypeDef
 | 
			
		||||
 | 
			
		||||
    @verbatim
 | 
			
		||||
    typedef TrackerTypeDef(MEASURE_USER_VARS_NUMB) Measure_TrackerTypeDef;
 | 
			
		||||
    @endverbatim
 | 
			
		||||
 | 
			
		||||
    И через @ref Measure_TrackerTypeDef структура подключается в @ref TESTER_MeasureHandleTypeDef, а также
 | 
			
		||||
    если необхожимо в другие структуру, например в структуру всех ошибок через указатель @ref TESTER_TrackerTypeDef
 | 
			
		||||
    
 | 
			
		||||
	@{  
 | 
			
		||||
	*/
 | 
			
		||||
 | 
			
		||||
#ifdef TRACKERS_ENABLE
 | 
			
		||||
  /** 
 | 
			
		||||
    * @brief Структура для счетчиков отладки
 | 
			
		||||
    * @param num_user_vars - количество пользовательских счетчиков
 | 
			
		||||
    * @details Содержит счетчик для успешных событый (cnt_ok),
 | 
			
		||||
    * счетчик для ошибок (cnt_err), счетчик для предупреждений (cnt_warn).
 | 
			
		||||
    *
 | 
			
		||||
    * Также есть возможность объявить пользовательские счетчики в 
 | 
			
		||||
    * количестве <num_user_vars> штук.
 | 
			
		||||
    *
 | 
			
		||||
    * Для работы с структурой можно использовать функции:
 | 
			
		||||
    * - TrackerCnt_Ok()
 | 
			
		||||
    * - TrackerCnt_Err()
 | 
			
		||||
    * - TrackerCnt_Warn()
 | 
			
		||||
    * - TrackerCnt_User()
 | 
			
		||||
    * - TrackerWrite_User()
 | 
			
		||||
    * - TrackerClear_All()
 | 
			
		||||
    * - TrackerClear_Ok()
 | 
			
		||||
    * - TrackerClear_Err()
 | 
			
		||||
    * - TrackerClear_Warn()
 | 
			
		||||
    * - TrackerClear_User()
 | 
			
		||||
    * - TrackerClear_UserAll()
 | 
			
		||||
    */
 | 
			
		||||
  #define TrackerTypeDef(num_user_vars)       \
 | 
			
		||||
  struct                                      \
 | 
			
		||||
  {                                           \
 | 
			
		||||
    uint32_t cnt_ok;                          \
 | 
			
		||||
    uint32_t cnt_err;                         \
 | 
			
		||||
    uint32_t cnt_warn;                        \
 | 
			
		||||
    uint32_t user[num_user_vars];             \
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /** @brief Получить количетство пользовательских переменных */
 | 
			
		||||
  #define num_of_usercnts(_user_)                               (sizeof(_user_) / sizeof(_user_[0]))
 | 
			
		||||
  /** @brief Проверка существует ли указанная пользовательская переменная */
 | 
			
		||||
  #define assert_usertracker(_cntstruct_, _uservarnumb_)        ((_uservarnumb_) < num_of_usercnts((_cntstruct_).user))
 | 
			
		||||
  /** @brief Условие для проверки существует ли указанная пользовательская переменная */
 | 
			
		||||
  #define if_assert_usertracker(_cntstruct_, _uservarnumb_)     if(assert_usertracker(_cntstruct_, _uservarnumb_))
 | 
			
		||||
  /** @brief Тернарный оператор для проверки существует ли указанная пользовательская переменная */
 | 
			
		||||
  #define tern_assert_usertracker(_cntstruct_, _uservarnumb_)   (assert_usertracker(_cntstruct_, _uservarnumb_)) ? _uservarnumb_ : 0
 | 
			
		||||
 | 
			
		||||
  
 | 
			
		||||
  
 | 
			
		||||
  /** 
 | 
			
		||||
    * @brief Запись числа в пользовательскую переменную 
 | 
			
		||||
    * @note   Здесь нет проверки - существует ли пользовательская переменная! 
 | 
			
		||||
    *         Есть возможность выйти за границы структуры!!! 
 | 
			
		||||
    *         Чтобы этого избежать используете дефайн #ref assert_usertracker()
 | 
			
		||||
    */
 | 
			
		||||
  #define TrackerGet_User(_cntstruct_, _uservarnumb_)             (_cntstruct_).user[tern_assert_usertracker(_cntstruct_, _uservarnumb_)]
 | 
			
		||||
  
 | 
			
		||||
  
 | 
			
		||||
  
 | 
			
		||||
  /** @brief Инкрементирование счетчика успешных событий */
 | 
			
		||||
  #define TrackerCnt_Ok(_cntstruct_)                              (_cntstruct_).cnt_ok++
 | 
			
		||||
  /** @brief Инкрементирование счетчика ошибок */
 | 
			
		||||
  #define TrackerCnt_Err(_cntstruct_)                             (_cntstruct_).cnt_err++
 | 
			
		||||
  /** @brief Инкрементирование счетчика предупреждений */
 | 
			
		||||
  #define TrackerCnt_Warn(_cntstruct_)                            (_cntstruct_).cnt_warn++
 | 
			
		||||
  /** @brief Инкрементирование пользовательской переменной */
 | 
			
		||||
  #define TrackerCnt_User(_cntstruct_, _uservarnumb_)             if_assert_usertracker(_cntstruct_, _uservarnumb_) (_cntstruct_).user[_uservarnumb_]++;
 | 
			
		||||
  /** @brief Запись числа в пользовательскую переменную */
 | 
			
		||||
  #define TrackerWrite_User(_cntstruct_, _uservarnumb_, _val_)    if_assert_usertracker(_cntstruct_, _uservarnumb_) (_cntstruct_).user[_uservarnumb_] = (_val_)
 | 
			
		||||
 | 
			
		||||
  /** @brief Очистка всей структуры */
 | 
			
		||||
  #define TrackerClear_All(_cntstruct_)                           memset(&(_cntstruct_), 0, sizeof(_cntstruct_))
 | 
			
		||||
  /** @brief Очистка счетчика успешных событий */
 | 
			
		||||
  #define TrackerClear_Ok(_cntstruct_)                            (_cntstruct_).cnt_ok = 0
 | 
			
		||||
  /** @brief Очистка счетчика ошибок */
 | 
			
		||||
  #define TrackerClear_Err(_cntstruct_)                           (_cntstruct_).cnt_err = 0
 | 
			
		||||
  /** @brief Очистка счетчика предупреждений */
 | 
			
		||||
  #define TrackerClear_Warn(_cntstruct_)                          (_cntstruct_).cnt_warn = 0
 | 
			
		||||
  /** @brief Очистка пользовательской переменной */
 | 
			
		||||
  #define TrackerClear_User(_cntstruct_, _uservarnumb_)           if_assert_usertracker(_cntstruct_, _uservarnumb_) (_cntstruct_).user[_uservarnumb_] = 0;
 | 
			
		||||
  /** @brief Очистка всех пользовательских переменных */
 | 
			
		||||
  #define TrackerClear_UserAll(_cntstruct_)                       memset(&(_cntstruct_).user, 0, sizeof((_cntstruct_).user))
 | 
			
		||||
 | 
			
		||||
#else //TRACKERS_ENABLE
 | 
			
		||||
  #define TrackerTypeDef(num_user_vars)                    void *
 | 
			
		||||
 | 
			
		||||
  #define num_of_usercnts(_user_)                               
 | 
			
		||||
  #define assert_tracecnt(_cntstruct_, _uservarnumb_)           
 | 
			
		||||
 | 
			
		||||
  #define TrackerCnt_Ok(_cntstruct_)                              
 | 
			
		||||
  #define TrackerCnt_Err(_cntstruct_)                             
 | 
			
		||||
  #define TrackerCnt_Warn(_cntstruct_)                            
 | 
			
		||||
  #define TrackerCnt_User(_cntstruct_, _uservarnumb_)                 
 | 
			
		||||
  #define TrackerWrite_User(_cntstruct_, _uservarnumb_, _val_)     
 | 
			
		||||
 | 
			
		||||
  /** @brief Очистка всей структуры */
 | 
			
		||||
  #define TrackerClear_All(_cntstruct_)                        
 | 
			
		||||
  #define TrackerClear_Ok(_cntstruct_)                         
 | 
			
		||||
  #define TrackerClear_Err(_cntstruct_)                        
 | 
			
		||||
  #define TrackerClear_Warn(_cntstruct_)                       
 | 
			
		||||
  #define TrackerClear_User(_cntstruct_)                       
 | 
			
		||||
  #define TrackerClear_UserAll(_cntstruct_)                    
 | 
			
		||||
 | 
			
		||||
#endif //TRACKERS_ENABLE
 | 
			
		||||
  
 | 
			
		||||
#endif //__TRACKERS_H_
 | 
			
		||||
@ -45,9 +45,9 @@ void MX_ADC1_Init(void)
 | 
			
		||||
  */
 | 
			
		||||
  hadc1.Instance = ADC1;
 | 
			
		||||
  hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
 | 
			
		||||
  hadc1.Init.ContinuousConvMode = DISABLE;
 | 
			
		||||
  hadc1.Init.ContinuousConvMode = ENABLE;
 | 
			
		||||
  hadc1.Init.DiscontinuousConvMode = DISABLE;
 | 
			
		||||
  hadc1.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T3_TRGO;
 | 
			
		||||
  hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
 | 
			
		||||
  hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
 | 
			
		||||
  hadc1.Init.NbrOfConversion = 1;
 | 
			
		||||
  if (HAL_ADC_Init(&hadc1) != HAL_OK)
 | 
			
		||||
@ -98,7 +98,7 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle)
 | 
			
		||||
    hdma_adc1.Init.MemInc = DMA_MINC_ENABLE;
 | 
			
		||||
    hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
 | 
			
		||||
    hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
 | 
			
		||||
    hdma_adc1.Init.Mode = DMA_NORMAL;
 | 
			
		||||
    hdma_adc1.Init.Mode = DMA_CIRCULAR;
 | 
			
		||||
    hdma_adc1.Init.Priority = DMA_PRIORITY_LOW;
 | 
			
		||||
    if (HAL_DMA_Init(&hdma_adc1) != HAL_OK)
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
@ -42,10 +42,23 @@
 | 
			
		||||
void MX_GPIO_Init(void)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
  GPIO_InitTypeDef GPIO_InitStruct = {0};
 | 
			
		||||
 | 
			
		||||
  /* GPIO Ports Clock Enable */
 | 
			
		||||
  __HAL_RCC_GPIOC_CLK_ENABLE();
 | 
			
		||||
  __HAL_RCC_GPIOD_CLK_ENABLE();
 | 
			
		||||
  __HAL_RCC_GPIOA_CLK_ENABLE();
 | 
			
		||||
 | 
			
		||||
  /*Configure GPIO pin Output Level */
 | 
			
		||||
  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
 | 
			
		||||
 | 
			
		||||
  /*Configure GPIO pin : PC13 */
 | 
			
		||||
  GPIO_InitStruct.Pin = GPIO_PIN_13;
 | 
			
		||||
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
 | 
			
		||||
  GPIO_InitStruct.Pull = GPIO_NOPULL;
 | 
			
		||||
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
 | 
			
		||||
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* USER CODE BEGIN 2 */
 | 
			
		||||
 | 
			
		||||
@ -21,11 +21,13 @@
 | 
			
		||||
#include "adc.h"
 | 
			
		||||
#include "dma.h"
 | 
			
		||||
#include "tim.h"
 | 
			
		||||
#include "usart.h"
 | 
			
		||||
#include "gpio.h"
 | 
			
		||||
 | 
			
		||||
/* Private includes ----------------------------------------------------------*/
 | 
			
		||||
/* USER CODE BEGIN Includes */
 | 
			
		||||
 | 
			
		||||
#include "rs_message.h"
 | 
			
		||||
#include "tester_adc_func.h"
 | 
			
		||||
/* USER CODE END Includes */
 | 
			
		||||
 | 
			
		||||
/* Private typedef -----------------------------------------------------------*/
 | 
			
		||||
@ -58,6 +60,10 @@ void SystemClock_Config(void);
 | 
			
		||||
/* Private user code ---------------------------------------------------------*/
 | 
			
		||||
/* USER CODE BEGIN 0 */
 | 
			
		||||
 | 
			
		||||
int delay = 250;
 | 
			
		||||
int delay_en = 1;
 | 
			
		||||
int before_pulse_delay = 50;
 | 
			
		||||
int pulse_delay = 10;
 | 
			
		||||
/* USER CODE END 0 */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@ -92,14 +98,28 @@ int main(void)
 | 
			
		||||
  MX_DMA_Init();
 | 
			
		||||
  MX_ADC1_Init();
 | 
			
		||||
  MX_TIM3_Init();
 | 
			
		||||
  MX_USART1_UART_Init();
 | 
			
		||||
  MX_TIM2_Init();
 | 
			
		||||
  /* USER CODE BEGIN 2 */
 | 
			
		||||
 | 
			
		||||
//  HAL_ADC_Start_DMA(&hadc1, (uint32_t *)buff, ADC_BUFF_SIZE);
 | 
			
		||||
//  HAL_TIM_Base_Start_IT(&htim3);
 | 
			
		||||
  TESTER_ADC_StructInit(&tester_adc);
 | 
			
		||||
  /* USER CODE END 2 */
 | 
			
		||||
 | 
			
		||||
  /* Infinite loop */
 | 
			
		||||
  /* USER CODE BEGIN WHILE */
 | 
			
		||||
  while (1)
 | 
			
		||||
  {
 | 
			
		||||
		if(delay_en)
 | 
			
		||||
			msDelay(delay);
 | 
			
		||||
//    HAL_UART_Transmit(&huart1, (uint8_t *)"axaxa", 5, 100);
 | 
			
		||||
    
 | 
			
		||||
    ADC_DMA_StartRead(&tester_adc);
 | 
			
		||||
    for(int i = 0; i < before_pulse_delay; i++);
 | 
			
		||||
    HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, 1);
 | 
			
		||||
    for(int i = 0; i < pulse_delay; i++);
 | 
			
		||||
    HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, 0);
 | 
			
		||||
    ADC_DMA_ReadWhileDMA(&tester_adc, 1000);
 | 
			
		||||
    /* USER CODE END WHILE */
 | 
			
		||||
 | 
			
		||||
    /* USER CODE BEGIN 3 */
 | 
			
		||||
 | 
			
		||||
@ -22,6 +22,7 @@
 | 
			
		||||
#include "stm32f1xx_it.h"
 | 
			
		||||
/* Private includes ----------------------------------------------------------*/
 | 
			
		||||
/* USER CODE BEGIN Includes */
 | 
			
		||||
#include "tester_adc_func.h"
 | 
			
		||||
/* USER CODE END Includes */
 | 
			
		||||
 | 
			
		||||
/* Private typedef -----------------------------------------------------------*/
 | 
			
		||||
@ -56,9 +57,12 @@
 | 
			
		||||
 | 
			
		||||
/* External variables --------------------------------------------------------*/
 | 
			
		||||
extern DMA_HandleTypeDef hdma_adc1;
 | 
			
		||||
extern TIM_HandleTypeDef htim2;
 | 
			
		||||
extern TIM_HandleTypeDef htim3;
 | 
			
		||||
extern UART_HandleTypeDef huart1;
 | 
			
		||||
/* USER CODE BEGIN EV */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/* USER CODE END EV */
 | 
			
		||||
 | 
			
		||||
/******************************************************************************/
 | 
			
		||||
@ -205,7 +209,7 @@ void SysTick_Handler(void)
 | 
			
		||||
void DMA1_Channel1_IRQHandler(void)
 | 
			
		||||
{
 | 
			
		||||
  /* USER CODE BEGIN DMA1_Channel1_IRQn 0 */
 | 
			
		||||
 | 
			
		||||
  ADC_DMA_Handler(&tester_adc);
 | 
			
		||||
  /* USER CODE END DMA1_Channel1_IRQn 0 */
 | 
			
		||||
  HAL_DMA_IRQHandler(&hdma_adc1);
 | 
			
		||||
  /* USER CODE BEGIN DMA1_Channel1_IRQn 1 */
 | 
			
		||||
@ -213,13 +217,27 @@ void DMA1_Channel1_IRQHandler(void)
 | 
			
		||||
  /* USER CODE END DMA1_Channel1_IRQn 1 */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief This function handles TIM2 global interrupt.
 | 
			
		||||
  */
 | 
			
		||||
void TIM2_IRQHandler(void)
 | 
			
		||||
{
 | 
			
		||||
  /* USER CODE BEGIN TIM2_IRQn 0 */
 | 
			
		||||
 | 
			
		||||
  /* USER CODE END TIM2_IRQn 0 */
 | 
			
		||||
  HAL_TIM_IRQHandler(&htim2);
 | 
			
		||||
  /* USER CODE BEGIN TIM2_IRQn 1 */
 | 
			
		||||
 | 
			
		||||
  /* USER CODE END TIM2_IRQn 1 */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief This function handles TIM3 global interrupt.
 | 
			
		||||
  */
 | 
			
		||||
void TIM3_IRQHandler(void)
 | 
			
		||||
{
 | 
			
		||||
  /* USER CODE BEGIN TIM3_IRQn 0 */
 | 
			
		||||
 | 
			
		||||
  HAL_NVIC_ClearPendingIRQ(TIM3_IRQn);
 | 
			
		||||
  /* USER CODE END TIM3_IRQn 0 */
 | 
			
		||||
  HAL_TIM_IRQHandler(&htim3);
 | 
			
		||||
  /* USER CODE BEGIN TIM3_IRQn 1 */
 | 
			
		||||
@ -227,6 +245,20 @@ void TIM3_IRQHandler(void)
 | 
			
		||||
  /* USER CODE END TIM3_IRQn 1 */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief This function handles USART1 global interrupt.
 | 
			
		||||
  */
 | 
			
		||||
void USART1_IRQHandler(void)
 | 
			
		||||
{
 | 
			
		||||
  /* USER CODE BEGIN USART1_IRQn 0 */
 | 
			
		||||
 | 
			
		||||
  /* USER CODE END USART1_IRQn 0 */
 | 
			
		||||
  HAL_UART_IRQHandler(&huart1);
 | 
			
		||||
  /* USER CODE BEGIN USART1_IRQn 1 */
 | 
			
		||||
 | 
			
		||||
  /* USER CODE END USART1_IRQn 1 */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* USER CODE BEGIN 1 */
 | 
			
		||||
 | 
			
		||||
/* USER CODE END 1 */
 | 
			
		||||
 | 
			
		||||
@ -24,8 +24,49 @@
 | 
			
		||||
 | 
			
		||||
/* USER CODE END 0 */
 | 
			
		||||
 | 
			
		||||
TIM_HandleTypeDef htim2;
 | 
			
		||||
TIM_HandleTypeDef htim3;
 | 
			
		||||
 | 
			
		||||
/* TIM2 init function */
 | 
			
		||||
void MX_TIM2_Init(void)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
  /* USER CODE BEGIN TIM2_Init 0 */
 | 
			
		||||
 | 
			
		||||
  /* USER CODE END TIM2_Init 0 */
 | 
			
		||||
 | 
			
		||||
  TIM_ClockConfigTypeDef sClockSourceConfig = {0};
 | 
			
		||||
  TIM_MasterConfigTypeDef sMasterConfig = {0};
 | 
			
		||||
 | 
			
		||||
  /* USER CODE BEGIN TIM2_Init 1 */
 | 
			
		||||
 | 
			
		||||
  /* USER CODE END TIM2_Init 1 */
 | 
			
		||||
  htim2.Instance = TIM2;
 | 
			
		||||
  htim2.Init.Prescaler = 0;
 | 
			
		||||
  htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
 | 
			
		||||
  htim2.Init.Period = 65535;
 | 
			
		||||
  htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
 | 
			
		||||
  htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
 | 
			
		||||
  if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
 | 
			
		||||
  {
 | 
			
		||||
    Error_Handler();
 | 
			
		||||
  }
 | 
			
		||||
  sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
 | 
			
		||||
  if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
 | 
			
		||||
  {
 | 
			
		||||
    Error_Handler();
 | 
			
		||||
  }
 | 
			
		||||
  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
 | 
			
		||||
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
 | 
			
		||||
  if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
 | 
			
		||||
  {
 | 
			
		||||
    Error_Handler();
 | 
			
		||||
  }
 | 
			
		||||
  /* USER CODE BEGIN TIM2_Init 2 */
 | 
			
		||||
 | 
			
		||||
  /* USER CODE END TIM2_Init 2 */
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
/* TIM3 init function */
 | 
			
		||||
void MX_TIM3_Init(void)
 | 
			
		||||
{
 | 
			
		||||
@ -70,7 +111,22 @@ void MX_TIM3_Init(void)
 | 
			
		||||
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
  if(tim_baseHandle->Instance==TIM3)
 | 
			
		||||
  if(tim_baseHandle->Instance==TIM2)
 | 
			
		||||
  {
 | 
			
		||||
  /* USER CODE BEGIN TIM2_MspInit 0 */
 | 
			
		||||
 | 
			
		||||
  /* USER CODE END TIM2_MspInit 0 */
 | 
			
		||||
    /* TIM2 clock enable */
 | 
			
		||||
    __HAL_RCC_TIM2_CLK_ENABLE();
 | 
			
		||||
 | 
			
		||||
    /* TIM2 interrupt Init */
 | 
			
		||||
    HAL_NVIC_SetPriority(TIM2_IRQn, 0, 0);
 | 
			
		||||
    HAL_NVIC_EnableIRQ(TIM2_IRQn);
 | 
			
		||||
  /* USER CODE BEGIN TIM2_MspInit 1 */
 | 
			
		||||
 | 
			
		||||
  /* USER CODE END TIM2_MspInit 1 */
 | 
			
		||||
  }
 | 
			
		||||
  else if(tim_baseHandle->Instance==TIM3)
 | 
			
		||||
  {
 | 
			
		||||
  /* USER CODE BEGIN TIM3_MspInit 0 */
 | 
			
		||||
 | 
			
		||||
@ -90,7 +146,21 @@ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)
 | 
			
		||||
void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
  if(tim_baseHandle->Instance==TIM3)
 | 
			
		||||
  if(tim_baseHandle->Instance==TIM2)
 | 
			
		||||
  {
 | 
			
		||||
  /* USER CODE BEGIN TIM2_MspDeInit 0 */
 | 
			
		||||
 | 
			
		||||
  /* USER CODE END TIM2_MspDeInit 0 */
 | 
			
		||||
    /* Peripheral clock disable */
 | 
			
		||||
    __HAL_RCC_TIM2_CLK_DISABLE();
 | 
			
		||||
 | 
			
		||||
    /* TIM2 interrupt Deinit */
 | 
			
		||||
    HAL_NVIC_DisableIRQ(TIM2_IRQn);
 | 
			
		||||
  /* USER CODE BEGIN TIM2_MspDeInit 1 */
 | 
			
		||||
 | 
			
		||||
  /* USER CODE END TIM2_MspDeInit 1 */
 | 
			
		||||
  }
 | 
			
		||||
  else if(tim_baseHandle->Instance==TIM3)
 | 
			
		||||
  {
 | 
			
		||||
  /* USER CODE BEGIN TIM3_MspDeInit 0 */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										122
									
								
								diode_tester/Core/Src/usart.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										122
									
								
								diode_tester/Core/Src/usart.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,122 @@
 | 
			
		||||
/* USER CODE BEGIN Header */
 | 
			
		||||
/**
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  * @file    usart.c
 | 
			
		||||
  * @brief   This file provides code for the configuration
 | 
			
		||||
  *          of the USART instances.
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  * @attention
 | 
			
		||||
  *
 | 
			
		||||
  * Copyright (c) 2024 STMicroelectronics.
 | 
			
		||||
  * All rights reserved.
 | 
			
		||||
  *
 | 
			
		||||
  * This software is licensed under terms that can be found in the LICENSE file
 | 
			
		||||
  * in the root directory of this software component.
 | 
			
		||||
  * If no LICENSE file comes with this software, it is provided AS-IS.
 | 
			
		||||
  *
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  */
 | 
			
		||||
/* USER CODE END Header */
 | 
			
		||||
/* Includes ------------------------------------------------------------------*/
 | 
			
		||||
#include "usart.h"
 | 
			
		||||
 | 
			
		||||
/* USER CODE BEGIN 0 */
 | 
			
		||||
 | 
			
		||||
/* USER CODE END 0 */
 | 
			
		||||
 | 
			
		||||
UART_HandleTypeDef huart1;
 | 
			
		||||
 | 
			
		||||
/* USART1 init function */
 | 
			
		||||
 | 
			
		||||
void MX_USART1_UART_Init(void)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
  /* USER CODE BEGIN USART1_Init 0 */
 | 
			
		||||
 | 
			
		||||
  /* USER CODE END USART1_Init 0 */
 | 
			
		||||
 | 
			
		||||
  /* USER CODE BEGIN USART1_Init 1 */
 | 
			
		||||
 | 
			
		||||
  /* USER CODE END USART1_Init 1 */
 | 
			
		||||
  huart1.Instance = USART1;
 | 
			
		||||
  huart1.Init.BaudRate = 115200;
 | 
			
		||||
  huart1.Init.WordLength = UART_WORDLENGTH_8B;
 | 
			
		||||
  huart1.Init.StopBits = UART_STOPBITS_1;
 | 
			
		||||
  huart1.Init.Parity = UART_PARITY_NONE;
 | 
			
		||||
  huart1.Init.Mode = UART_MODE_TX_RX;
 | 
			
		||||
  huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
 | 
			
		||||
  huart1.Init.OverSampling = UART_OVERSAMPLING_16;
 | 
			
		||||
  if (HAL_UART_Init(&huart1) != HAL_OK)
 | 
			
		||||
  {
 | 
			
		||||
    Error_Handler();
 | 
			
		||||
  }
 | 
			
		||||
  /* USER CODE BEGIN USART1_Init 2 */
 | 
			
		||||
 | 
			
		||||
  /* USER CODE END USART1_Init 2 */
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
  GPIO_InitTypeDef GPIO_InitStruct = {0};
 | 
			
		||||
  if(uartHandle->Instance==USART1)
 | 
			
		||||
  {
 | 
			
		||||
  /* USER CODE BEGIN USART1_MspInit 0 */
 | 
			
		||||
 | 
			
		||||
  /* USER CODE END USART1_MspInit 0 */
 | 
			
		||||
    /* USART1 clock enable */
 | 
			
		||||
    __HAL_RCC_USART1_CLK_ENABLE();
 | 
			
		||||
 | 
			
		||||
    __HAL_RCC_GPIOA_CLK_ENABLE();
 | 
			
		||||
    /**USART1 GPIO Configuration
 | 
			
		||||
    PA9     ------> USART1_TX
 | 
			
		||||
    PA10     ------> USART1_RX
 | 
			
		||||
    */
 | 
			
		||||
    GPIO_InitStruct.Pin = GPIO_PIN_9;
 | 
			
		||||
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
 | 
			
		||||
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
 | 
			
		||||
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 | 
			
		||||
 | 
			
		||||
    GPIO_InitStruct.Pin = GPIO_PIN_10;
 | 
			
		||||
    GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
 | 
			
		||||
    GPIO_InitStruct.Pull = GPIO_NOPULL;
 | 
			
		||||
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 | 
			
		||||
 | 
			
		||||
    /* USART1 interrupt Init */
 | 
			
		||||
    HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
 | 
			
		||||
    HAL_NVIC_EnableIRQ(USART1_IRQn);
 | 
			
		||||
  /* USER CODE BEGIN USART1_MspInit 1 */
 | 
			
		||||
 | 
			
		||||
  /* USER CODE END USART1_MspInit 1 */
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
  if(uartHandle->Instance==USART1)
 | 
			
		||||
  {
 | 
			
		||||
  /* USER CODE BEGIN USART1_MspDeInit 0 */
 | 
			
		||||
 | 
			
		||||
  /* USER CODE END USART1_MspDeInit 0 */
 | 
			
		||||
    /* Peripheral clock disable */
 | 
			
		||||
    __HAL_RCC_USART1_CLK_DISABLE();
 | 
			
		||||
 | 
			
		||||
    /**USART1 GPIO Configuration
 | 
			
		||||
    PA9     ------> USART1_TX
 | 
			
		||||
    PA10     ------> USART1_RX
 | 
			
		||||
    */
 | 
			
		||||
    HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10);
 | 
			
		||||
 | 
			
		||||
    /* USART1 interrupt Deinit */
 | 
			
		||||
    HAL_NVIC_DisableIRQ(USART1_IRQn);
 | 
			
		||||
  /* USER CODE BEGIN USART1_MspDeInit 1 */
 | 
			
		||||
 | 
			
		||||
  /* USER CODE END USART1_MspDeInit 1 */
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* USER CODE BEGIN 1 */
 | 
			
		||||
 | 
			
		||||
/* USER CODE END 1 */
 | 
			
		||||
							
								
								
									
										457
									
								
								diode_tester/Core/Tester_main/tester_adc_func.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										457
									
								
								diode_tester/Core/Tester_main/tester_adc_func.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,457 @@
 | 
			
		||||
#include "tester_adc_func.h"
 | 
			
		||||
#include "adc.h"
 | 
			
		||||
 | 
			
		||||
TESTER_ADCTypeDef tester_adc = {0};
 | 
			
		||||
 | 
			
		||||
uint16_t ADC_DMA_Buff[ADC_DMA_BUFF_SIZE];
 | 
			
		||||
uint16_t ADC_DMA_HalfBuff[ADC_DMA_BUFF_SIZE/2];
 | 
			
		||||
 | 
			
		||||
void ADC_DMA_Handler(TESTER_ADCTypeDef *adc)
 | 
			
		||||
{
 | 
			
		||||
  int flag_parse_dma = 0;
 | 
			
		||||
  int buff_start_ind = 0;
 | 
			
		||||
  int buff_end_ind = 0;    
 | 
			
		||||
  
 | 
			
		||||
  if(adc->f.dmaHandlerbusy)
 | 
			
		||||
    return;
 | 
			
		||||
  
 | 
			
		||||
  
 | 
			
		||||
  
 | 
			
		||||
  adc->f.dmaHandlerbusy = 1;    
 | 
			
		||||
  __disable_irq();
 | 
			
		||||
  
 | 
			
		||||
  if(DMA1->ISR & DMA_FLAG_HT1)
 | 
			
		||||
  {
 | 
			
		||||
    memcpy(ADC_DMA_HalfBuff, ADC_DMA_Buff, sizeof(ADC_DMA_HalfBuff));
 | 
			
		||||
    
 | 
			
		||||
    adc->f.dmaBufferHalfDone = 1;
 | 
			
		||||
    
 | 
			
		||||
    buff_start_ind = 0;
 | 
			
		||||
    buff_end_ind = ADC_BUFF_SIZE/2;
 | 
			
		||||
    flag_parse_dma = 1;
 | 
			
		||||
  }
 | 
			
		||||
  else if (DMA1->ISR & DMA_FLAG_TC1)
 | 
			
		||||
  {
 | 
			
		||||
    memcpy(ADC_DMA_HalfBuff, (ADC_DMA_Buff+ADC_DMA_BUFF_SIZE/2), sizeof(ADC_DMA_HalfBuff));
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
    adc->f.dmaBufferHalfDone = 2;
 | 
			
		||||
    
 | 
			
		||||
    buff_start_ind = ADC_BUFF_SIZE/2;
 | 
			
		||||
    buff_end_ind = ADC_BUFF_SIZE;
 | 
			
		||||
    flag_parse_dma = 1;
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    flag_parse_dma = 0;
 | 
			
		||||
    TrackerCnt_Warn(adc->adc_err);
 | 
			
		||||
  }  
 | 
			
		||||
  
 | 
			
		||||
  __enable_irq();
 | 
			
		||||
  if(adc->f.enable_dmaBuffTransfer && flag_parse_dma)
 | 
			
		||||
  {
 | 
			
		||||
    int dma_ind = 0;
 | 
			
		||||
    for(int buff_ind = buff_start_ind; 
 | 
			
		||||
        buff_ind < buff_end_ind; 
 | 
			
		||||
        buff_ind++)
 | 
			
		||||
    {
 | 
			
		||||
      
 | 
			
		||||
      
 | 
			
		||||
      adc->chAdc.ADC_Buff[buff_ind] = ADC_DMA_HalfBuff[dma_ind];
 | 
			
		||||
      
 | 
			
		||||
      dma_ind += 1;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    printf_adc_it("\n%d: ADC DMA IT Done %d-half", uwTick, adc->f.dmaBufferHalfDone);
 | 
			
		||||
    adc->f.dmaHandlerbusy = 0;
 | 
			
		||||
    TrackerCnt_Ok(adc->adc_err);
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    TrackerCnt_Warn(adc->adc_err);
 | 
			
		||||
  }  
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void TESTER_ADC_StructInit(TESTER_ADCTypeDef *adc)
 | 
			
		||||
{
 | 
			
		||||
  ClearStruct(*adc);
 | 
			
		||||
  adc->hadc = &hadc1;
 | 
			
		||||
  adc->chAdc.pulse_width = 4;
 | 
			
		||||
  adc->filter.array_size = FOSTER_STUDENT_N;
 | 
			
		||||
  adc->chAdc.ChMask = ADC_MEASURE_CHANNEL_0;
 | 
			
		||||
  
 | 
			
		||||
#ifdef FOSTER_STUDENT_USER_T_CRITICAL
 | 
			
		||||
  adc->filter.t_critical = FOSTER_STUDENT_USER_T_CRITICAL;
 | 
			
		||||
#else
 | 
			
		||||
  adc->filter.precise_table_ind = 2;
 | 
			
		||||
#endif
 | 
			
		||||
//  adc->DMA_HalfBuff = ADC_DMA_HalfBuff;
 | 
			
		||||
//  adc->DMA_Buff = ADC_DMA_Buff;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
HAL_StatusTypeDef ADC_DMA_StartRead(TESTER_ADCTypeDef *adc)
 | 
			
		||||
{
 | 
			
		||||
  HAL_StatusTypeDef res;
 | 
			
		||||
  
 | 
			
		||||
  /* Очистка буферов каналов */
 | 
			
		||||
  ClearStruct(adc->chAdc.ADC_Buff);
 | 
			
		||||
  
 | 
			
		||||
  /* Очистка флага какая половина DMA уже готова */
 | 
			
		||||
  adc->f.dmaBufferHalfDone = 0; // никакая, данные DMA пока не готовы в принципе
 | 
			
		||||
  
 | 
			
		||||
  /* Разрешение заполнения буферов каналов */
 | 
			
		||||
  adc->f.enable_dmaBuffTransfer = 1;
 | 
			
		||||
  /* Выставления флага, что АЦП работает */
 | 
			
		||||
  adc->f.adc_running = 1;
 | 
			
		||||
 | 
			
		||||
  printf_adc("\n%d: ADC DMA Start", uwTick);
 | 
			
		||||
 | 
			
		||||
  /* Старт АЦП с DMA */
 | 
			
		||||
  res = HAL_ADC_Start_DMA(adc->hadc, (uint32_t *)ADC_DMA_Buff, ADC_DMA_BUFF_SIZE);
 | 
			
		||||
  
 | 
			
		||||
  /* Если старт неудачен - запрет заполнения буферов каналов */
 | 
			
		||||
  if(res != HAL_OK)
 | 
			
		||||
  {
 | 
			
		||||
    adc->f.enable_dmaBuffTransfer = 0;
 | 
			
		||||
    adc->f.adc_running = 0;
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  return res;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
HAL_StatusTypeDef ADC_DMA_StopRead(TESTER_ADCTypeDef *adc)
 | 
			
		||||
{
 | 
			
		||||
  HAL_StatusTypeDef res;
 | 
			
		||||
  if(adc->f.adc_running)
 | 
			
		||||
  {
 | 
			
		||||
    /* Остановка АЦП */
 | 
			
		||||
    res = HAL_ADC_Stop_DMA(adc->hadc);
 | 
			
		||||
    
 | 
			
		||||
    /* Очищение флагов АЦП */
 | 
			
		||||
    adc->f.adc_running = 0;
 | 
			
		||||
    adc->f.enable_dmaBuffTransfer = 0;
 | 
			
		||||
    adc->f.dmaHandlerbusy = 0;
 | 
			
		||||
   
 | 
			
		||||
 | 
			
		||||
    printf_adc("\n%d: ADC DMA Stop", uwTick);
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  return res;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ADC_DMA_Fuel_Cell_Reset(TESTER_ADCChannelTypeDef *adc_fc)
 | 
			
		||||
{
 | 
			
		||||
  adc_fc->ADC_Filtered = 0;
 | 
			
		||||
  adc_fc->ADC_Max = 0;
 | 
			
		||||
  adc_fc->ADC_Min = 0;
 | 
			
		||||
  adc_fc->max_value_ind = 0;
 | 
			
		||||
  adc_fc->state = 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ADC_DMA_Channels_Prepare(TESTER_ADCChannelTypeDef *adc_fuel_cells, uint8_t MaskForChannels, uint8_t state)
 | 
			
		||||
{
 | 
			
		||||
  for(int i = 0; i < 4; i++)
 | 
			
		||||
  {
 | 
			
		||||
    if(MaskForChannels&(1<<i))
 | 
			
		||||
    {
 | 
			
		||||
      ADC_DMA_Fuel_Cell_Reset(&adc_fuel_cells[i]);
 | 
			
		||||
      adc_fuel_cells[i].state = state;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//uint8_t FosterStudent(TESTER_ADCChannelTypeDef *adc_fc, TESTER_ADCFilterTypeDef *Filter, uint32_t ind)
 | 
			
		||||
//{
 | 
			
		||||
//#ifndef FOSTER_STUDENT_USER_T_CRITICAL
 | 
			
		||||
//  uint32_t t_critical[] = FOSTER_STUDENT_T_CRITICALS;
 | 
			
		||||
//#endif //FOSTER_STUDENT_USER_T_CRITICAL
 | 
			
		||||
//  uint8_t res = 0;
 | 
			
		||||
//  
 | 
			
		||||
//  uint8_t m = 0;
 | 
			
		||||
//  uint8_t l = 0;
 | 
			
		||||
//  
 | 
			
		||||
//  uint16_t max = adc_fc->ADC_Buff[ind];  
 | 
			
		||||
//  uint16_t min = adc_fc->ADC_Buff[ind]; 
 | 
			
		||||
//  
 | 
			
		||||
//  int16_t d_sum = 0;  
 | 
			
		||||
//  uint32_t t;  
 | 
			
		||||
//  
 | 
			
		||||
//  uint16_t arr_size;
 | 
			
		||||
//  if(ind < Filter->array_size)
 | 
			
		||||
//    return 0xFF;
 | 
			
		||||
//    
 | 
			
		||||
//  for(int i = ind; i > ind - Filter->array_size; i--)
 | 
			
		||||
//  {
 | 
			
		||||
//      
 | 
			
		||||
//    if(adc_fc->ADC_Buff[i] > max)
 | 
			
		||||
//    {
 | 
			
		||||
//      max = adc_fc->ADC_Buff[i];
 | 
			
		||||
//      m = 1;
 | 
			
		||||
//    }
 | 
			
		||||
//    else
 | 
			
		||||
//      m = 0;
 | 
			
		||||
//    if(adc_fc->ADC_Buff[i] < min)
 | 
			
		||||
//    {
 | 
			
		||||
//      min = adc_fc->ADC_Buff[i];
 | 
			
		||||
//      l = 1;
 | 
			
		||||
//    }
 | 
			
		||||
//    else
 | 
			
		||||
//      l = 0;
 | 
			
		||||
//    d_sum += (m-l);
 | 
			
		||||
//  }
 | 
			
		||||
//  
 | 
			
		||||
//#define fixed_base 1000
 | 
			
		||||
//  if(d_sum < 0)
 | 
			
		||||
//    d_sum = -d_sum;
 | 
			
		||||
//  t = d_sum*fixed_base*fixed_base/FOSTER_STUDENT_MSE;
 | 
			
		||||
//
 | 
			
		||||
//  Filter->t_current = t;  
 | 
			
		||||
//#ifndef FOSTER_STUDENT_USER_T_CRITICAL  
 | 
			
		||||
//  Filter->t_critical = t_critical[Filter->precise_table_ind];
 | 
			
		||||
//#endif //FOSTER_STUDENT_USER_T_CRITICAL
 | 
			
		||||
//  
 | 
			
		||||
//  
 | 
			
		||||
//  if(Filter->t_current > Filter->t_critical)
 | 
			
		||||
//  {
 | 
			
		||||
//    res = 1;
 | 
			
		||||
//  }
 | 
			
		||||
//  else
 | 
			
		||||
//  {
 | 
			
		||||
//    res = 0;
 | 
			
		||||
//  }
 | 
			
		||||
//  
 | 
			
		||||
//  
 | 
			
		||||
//  
 | 
			
		||||
//  return res;
 | 
			
		||||
//}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void ADC_DMA_WaitForStableVoltage(TESTER_ADCChannelTypeDef *adc_fc, TESTER_ADCFilterTypeDef *Filter, uint32_t ind)
 | 
			
		||||
{
 | 
			
		||||
//  if(FosterStudent(adc_fc, Filter, ind) == 0)
 | 
			
		||||
//  {
 | 
			
		||||
//    /* Сохраняем индекс еще стабильного напряжения */
 | 
			
		||||
//    adc_fc->stable_start_ind = ind - Filter->array_size/2;
 | 
			
		||||
//    /* Переключение на стабильное напряжение найдено */
 | 
			
		||||
//    adc_fc->state = WAIT_FOR_DROP;
 | 
			
		||||
//  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void ADC_DMA_WaitForDropVoltage(TESTER_ADCChannelTypeDef *adc_fc, TESTER_ADCFilterTypeDef *Filter, uint32_t ind)
 | 
			
		||||
{  
 | 
			
		||||
//  if(FosterStudent(adc_fc, Filter, ind) == 1)
 | 
			
		||||
//  {
 | 
			
		||||
//    /* Сохраняем индекс еще стабильного напряжения */
 | 
			
		||||
//    adc_fc->stable_end_ind = ind-Filter->array_size/2;
 | 
			
		||||
//    /* Переключение на стабильное напряжение найдено */
 | 
			
		||||
//    adc_fc->state = STABLE_FOUND;
 | 
			
		||||
//  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ADC_DMA_CalcStabilized(TESTER_ADCChannelTypeDef *adc_fc)
 | 
			
		||||
{
 | 
			
		||||
  uint16_t tmp_val = 0;
 | 
			
		||||
  uint32_t val_sum = 0;  
 | 
			
		||||
  
 | 
			
		||||
  adc_fc->ADC_Max = 0;
 | 
			
		||||
  adc_fc->ADC_Min = 0xFFFF;
 | 
			
		||||
  
 | 
			
		||||
  /* Просмотр стабильных значений в буфере */
 | 
			
		||||
  for(int i = 0; i < ADC_BUFF_SIZE; i++)
 | 
			
		||||
  {    
 | 
			
		||||
    tmp_val = adc_fc->ADC_Buff[i];
 | 
			
		||||
    /* Обновление максимального значения */
 | 
			
		||||
    if(tmp_val > adc_fc->ADC_Max)
 | 
			
		||||
    {
 | 
			
		||||
      adc_fc->ADC_Max = tmp_val;
 | 
			
		||||
      adc_fc->max_value_ind = i;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    /* Обновление минимального значения */
 | 
			
		||||
    if(tmp_val < adc_fc->ADC_Min)
 | 
			
		||||
    {
 | 
			
		||||
      adc_fc->ADC_Min = tmp_val;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  
 | 
			
		||||
  /* Расчет среднего значения в пике */
 | 
			
		||||
  for(int i = (adc_fc->max_value_ind - adc_fc->pulse_width)/2; i < (adc_fc->max_value_ind + adc_fc->pulse_width/2); i++)
 | 
			
		||||
  {
 | 
			
		||||
    tmp_val = adc_fc->ADC_Buff[i];
 | 
			
		||||
    /* Накопление значений для расчета среднего */
 | 
			
		||||
    val_sum += tmp_val;
 | 
			
		||||
  }  
 | 
			
		||||
  adc_fc->ADC_Filtered = val_sum/(adc_fc->pulse_width);
 | 
			
		||||
  
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ADC_DMA_ProcessSingleBuffer(TESTER_ADCChannelTypeDef *adc_fc)
 | 
			
		||||
{
 | 
			
		||||
  
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void ADC_DMA_ProcessBuffer(TESTER_ADCTypeDef *adc)
 | 
			
		||||
{  
 | 
			
		||||
  ADC_DMA_ProcessSingleBuffer(&adc->chAdc);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ADC_DMA_BufferHandler(TESTER_ADCChannelTypeDef *adc_fc, TESTER_ADCFilterTypeDef *Filter, uint32_t ind)
 | 
			
		||||
{
 | 
			
		||||
//  switch(adc_fc->state)
 | 
			
		||||
//  {
 | 
			
		||||
//    /* Канал не проверяется */
 | 
			
		||||
//    case NOT_CHECKING:
 | 
			
		||||
//      break;    
 | 
			
		||||
//    
 | 
			
		||||
//    /* Пока на каналах не зарядится кондер */
 | 
			
		||||
//    case WAIT_FOR_STABLE: 
 | 
			
		||||
////      ADC_DMA_WaitForStableVoltage(adc_fc, Filter, ind);
 | 
			
		||||
//      break;
 | 
			
		||||
//    
 | 
			
		||||
//    /* Проверка пока на первом канале не начнет разряжаться кондер */
 | 
			
		||||
//    case WAIT_FOR_DROP:  
 | 
			
		||||
////      ADC_DMA_WaitForDropVoltage(adc_fc, Filter, ind);
 | 
			
		||||
//      break;
 | 
			
		||||
//    
 | 
			
		||||
//    /* Стабильное напряжение найдено */
 | 
			
		||||
//    case STABLE_FOUND:
 | 
			
		||||
//    /* Стабильное напряжение НЕ найдено */
 | 
			
		||||
//    case STABLE_NOT_FOUND:
 | 
			
		||||
//    /* Конец стабильного напряжения НЕ найден */
 | 
			
		||||
//    case DROP_NOT_FOUND:
 | 
			
		||||
//      break;
 | 
			
		||||
//    
 | 
			
		||||
//    
 | 
			
		||||
//    /* Если состояние неопределенное */
 | 
			
		||||
//    default: 
 | 
			
		||||
//      adc_fc->state = NOT_CHECKING;
 | 
			
		||||
//      break;
 | 
			
		||||
//      
 | 
			
		||||
//  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief    Считывать АЦП до тех пор, пока буфер DMA не заполнится и не будет обработан
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef ADC_DMA_ReadWhileDMA(TESTER_ADCTypeDef *adc, uint32_t Timeout)
 | 
			
		||||
{
 | 
			
		||||
  uint32_t tickstart = HAL_GetTick();
 | 
			
		||||
  
 | 
			
		||||
  /* Проверка принятых параметров функции */
 | 
			
		||||
  if(adc == 0)
 | 
			
		||||
  {
 | 
			
		||||
    ADC_DMA_StopRead(adc);
 | 
			
		||||
    
 | 
			
		||||
    printf_adc_err("\n%d: Error ADC: Handle is NULL)", uwTick);
 | 
			
		||||
    return HAL_ERROR;
 | 
			
		||||
  }
 | 
			
		||||
  if(Timeout == 0)
 | 
			
		||||
  {
 | 
			
		||||
    ADC_DMA_StopRead(adc);
 | 
			
		||||
    
 | 
			
		||||
    printf_adc_err("\n%d: Error ADC: Read timeout is NULL)", uwTick);
 | 
			
		||||
    return HAL_ERROR;
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
 | 
			
		||||
  int adc_buff_ind = 1;
 | 
			
		||||
  uint16_t filter_halfend = ADC_BUFF_SIZE/2;
 | 
			
		||||
  uint16_t filter_end = ADC_BUFF_SIZE;
 | 
			
		||||
  uint8_t run_adc_check = 0;
 | 
			
		||||
  uint8_t expected_dmaBufferHalf = 1;
 | 
			
		||||
  
 | 
			
		||||
  /* Обработка АЦП */
 | 
			
		||||
  while(1)
 | 
			
		||||
  {
 | 
			
		||||
    /* Проверка на таймаут */
 | 
			
		||||
    if(HAL_GetTick() - tickstart > Timeout)
 | 
			
		||||
    {
 | 
			
		||||
      ADC_DMA_StopRead(adc);
 | 
			
		||||
 | 
			
		||||
      printf_adc_err("\n%d: Error ADC: Stable Not Found (Timeout)", uwTick);
 | 
			
		||||
      return HAL_TIMEOUT;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
    /* Запуск обработки данных из DMA буфера, когда они готовы */
 | 
			
		||||
    if( (expected_dmaBufferHalf == adc->f.dmaBufferHalfDone) && // Ожидаемая половина DMA буфера готова
 | 
			
		||||
        (run_adc_check == 0))                                 // Обработка предыдущей половины не активна
 | 
			
		||||
    {
 | 
			
		||||
      run_adc_check = 1;
 | 
			
		||||
 | 
			
		||||
      if(adc->f.dmaBufferHalfDone == 1)
 | 
			
		||||
        printf_adc_processing("\n%d: ADC Processing DMA start...", uwTick);
 | 
			
		||||
      else if(adc->f.dmaBufferHalfDone == 2)
 | 
			
		||||
        printf_adc_processing("\n%d: ADC Processing DMA 2-half start...", uwTick);
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
    /* Обработка буфера DMA */
 | 
			
		||||
    if(run_adc_check)
 | 
			
		||||
    { 
 | 
			
		||||
      /* Вызов обработчиков буфера DMA для каждого канала, если он выбран */
 | 
			
		||||
      ADC_DMA_BufferHandler(&adc->chAdc, &adc->filter, adc_buff_ind);
 | 
			
		||||
      
 | 
			
		||||
      
 | 
			
		||||
      
 | 
			
		||||
      /* Переход на следующие во времени значения каналов АЦП */
 | 
			
		||||
      adc_buff_ind++;      
 | 
			
		||||
      /* если это первая половина DMA буфера */
 | 
			
		||||
      if(expected_dmaBufferHalf == 1) 
 | 
			
		||||
      {
 | 
			
		||||
        if(adc_buff_ind > filter_halfend)   // Проверка первой половины закончена
 | 
			
		||||
        {
 | 
			
		||||
          adc_buff_ind = filter_halfend;    // Выставляем индекс на вторую половину
 | 
			
		||||
          run_adc_check = 0;                // Сбрасываем флаг проверки каналов
 | 
			
		||||
          expected_dmaBufferHalf = 2;       // Устанавливаем ожидание готовности второй половины данных DMA буфера
 | 
			
		||||
 | 
			
		||||
          printf_adc_processing("\n%d: ADC Processing 1-half DMA complete, wait for 2-half...", uwTick);
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      /* если это вторая половина DMA буфера */
 | 
			
		||||
      else if(expected_dmaBufferHalf == 2)
 | 
			
		||||
      {
 | 
			
		||||
        /* Если АЦП работает - останавливаем его */
 | 
			
		||||
        // note: пока без кольцевого режима, если за один цикл буфера ничего не удалось словить, вряд ли далее что-то появиться??
 | 
			
		||||
        if(adc->f.adc_running)
 | 
			
		||||
        {
 | 
			
		||||
          ADC_DMA_StopRead(adc);
 | 
			
		||||
          printf_adc_processing(": wait for processing complete...");
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        if(adc_buff_ind > filter_end)       // Проверка первой половины закончена
 | 
			
		||||
        {
 | 
			
		||||
          adc_buff_ind = 0;                 // Выставляем индекс на первую половину
 | 
			
		||||
          run_adc_check = 0;                // Сбрасываем флаг проверки каналов
 | 
			
		||||
          expected_dmaBufferHalf = 1;       // Устанавливаем ожидание готовности первой половины данных DMA буфера
 | 
			
		||||
 | 
			
		||||
          printf_adc_processing("\n%d: ADC Processing DMA complete", uwTick);
 | 
			
		||||
          break;
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      /* если это "никакая" половина DMA буфера */
 | 
			
		||||
      else
 | 
			
		||||
      { /* Сброс всего */
 | 
			
		||||
 | 
			
		||||
        printf_adc_err("\n%d: ADC Processing DMA unexcpected half", uwTick);
 | 
			
		||||
 | 
			
		||||
        adc_buff_ind = 0;
 | 
			
		||||
        run_adc_check = 0;
 | 
			
		||||
        expected_dmaBufferHalf = 1;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  ADC_DMA_CalcStabilized(&adc->chAdc);
 | 
			
		||||
  
 | 
			
		||||
  return HAL_OK;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										156
									
								
								diode_tester/Core/Tester_main/tester_adc_func.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										156
									
								
								diode_tester/Core/Tester_main/tester_adc_func.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,156 @@
 | 
			
		||||
/**
 | 
			
		||||
**************************************************************************
 | 
			
		||||
* @file tester_func.h
 | 
			
		||||
* @brief Заголовочный файл для функций МЗКТ.
 | 
			
		||||
**************************************************************************
 | 
			
		||||
@details
 | 
			
		||||
 | 
			
		||||
*************************************************************************/
 | 
			
		||||
 | 
			
		||||
	
 | 
			
		||||
#ifndef _TESTER_ADC_FUNC_H_
 | 
			
		||||
#define _TESTER_ADC_FUNC_H_
 | 
			
		||||
 | 
			
		||||
#include "mylibs_include.h"
 | 
			
		||||
 | 
			
		||||
#define ADC_MEASURE_CHANNEL_0_Pos   0x00
 | 
			
		||||
#define ADC_MEASURE_CHANNEL_1_Pos   0x01
 | 
			
		||||
#define ADC_MEASURE_CHANNEL_2_Pos   0x02
 | 
			
		||||
#define ADC_MEASURE_CHANNEL_3_Pos   0x03
 | 
			
		||||
 | 
			
		||||
#define ADC_MEASURE_CHANNEL_0   (0x01 << ADC_MEASURE_CHANNEL_0_Pos)
 | 
			
		||||
#define ADC_MEASURE_CHANNEL_1   (0x01 << ADC_MEASURE_CHANNEL_1_Pos)
 | 
			
		||||
#define ADC_MEASURE_CHANNEL_2   (0x01 << ADC_MEASURE_CHANNEL_2_Pos)
 | 
			
		||||
#define ADC_MEASURE_CHANNEL_3   (0x01 << ADC_MEASURE_CHANNEL_3_Pos)
 | 
			
		||||
#define ADC_CH_IGNORE           NULL // должно быть NULL!!!
 | 
			
		||||
 | 
			
		||||
#define Measure_Get_Channel(_chPtr_)          (_chPtr_)->Tadc->chAdc
 | 
			
		||||
#define Measure_Get_Voltage(_chPtr_)          ((_chPtr_)->Tadc->chAdc->U_Current)
 | 
			
		||||
#define Measure_Get_Zero(_chPtr_)             ((_chPtr_)->Tadc->chAdc->refADC_zero)
 | 
			
		||||
#define Measure_Get_Calibr(_chPtr_)           ((_chPtr_)->Tadc->chAdc->refADC_calibr)
 | 
			
		||||
#define Measure_Get_VoltStep(_chPtr_)         ((_chPtr_)->Tadc->chAdc->refU_step)
 | 
			
		||||
#define Measure_Get_Filtered(_chPtr_)         ((_chPtr_)->Tadc->chAdc->ADC_Filtered)
 | 
			
		||||
 | 
			
		||||
#define Measure_Calc_CalibrDiff(_chPtr_)      abs((int)Measure_Get_Calibr(_chPtr_) - Measure_Get_Zero(_chPtr_))
 | 
			
		||||
#define Measure_Calc_FilterDiff(_chPtr_)      abs((int)Measure_Get_Filtered(_chPtr_) - Measure_Get_Zero(_chPtr_))  
 | 
			
		||||
#define Measure_Calc_Voltage(_chPtr_)         ((float)Measure_Calc_FilterDiff(_chPtr_)*Measure_Get_VoltStep(_chPtr_))
 | 
			
		||||
  
 | 
			
		||||
//#define ADC_GetChannel(_AdcChPtr_)           (_AdcChPtr_)->Tadc->chAdc
 | 
			
		||||
////#define Measure_Get_Voltage(_AdcChPtr_)           ((_AdcChPtr_)->Tadc->chAdc->U_Current)
 | 
			
		||||
////#define Measure_Get_Zero(_AdcChPtr_)              ((_AdcChPtr_)->Tadc->chAdc->refADC_zero)
 | 
			
		||||
////#define Measure_Get_Calibr(_AdcChPtr_)            ((_AdcChPtr_)->Tadc->chAdc->refADC_calibr)
 | 
			
		||||
////#define Measure_Get_VoltStep(_AdcChPtr_)          ((_AdcChPtr_)->Tadc->chAdc->refU_step)
 | 
			
		||||
////#define Measure_Get_Filtered(_AdcChPtr_)          ((_AdcChPtr_)->Tadc->chAdc->ADC_Filtered)
 | 
			
		||||
 | 
			
		||||
//#define Channel_Calc_Diff(_AdcChPtr_, _value_)    ((int)(_value_) - (_AdcChPtr_)->refADC_zero)
 | 
			
		||||
//#define Channel_Calc_CalibrValue(_AdcChPtr_)      (abs(Channel_Calc_Diff((_AdcChPtr_), (_AdcChPtr_)->refADC_calibr)) )
 | 
			
		||||
//#define Channel_Calc_AdcValue(_AdcChPtr_)         (abs(Channel_Calc_Diff((_AdcChPtr_), (_AdcChPtr_)->ADC_Filtered)) )
 | 
			
		||||
//#define Channel_Calc_Voltage(_AdcChPtr_)          ((float)Channel_Calc_AdcValue(_AdcChPtr_)*(_AdcChPtr_)->refU_step)
 | 
			
		||||
 | 
			
		||||
typedef uint16_t ADC_BuffTypeDef[ADC_BUFF_SIZE];
 | 
			
		||||
 | 
			
		||||
typedef enum
 | 
			
		||||
{
 | 
			
		||||
  ADC_DISABLED              = 0,
 | 
			
		||||
  WAIT_FOR_FIRST_HALF       = 1,
 | 
			
		||||
  PROCESSING_FIRST_HALF     = 2,
 | 
			
		||||
  WAIT_FOR_SECOND_HALF      = 3,
 | 
			
		||||
  PROCESSING_SECOND_HALF    = 4,
 | 
			
		||||
  ADC_DONE                  = 5,
 | 
			
		||||
}ADC_ChannelState;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
typedef struct
 | 
			
		||||
{  
 | 
			
		||||
  ADC_BuffTypeDef ADC_Buff;
 | 
			
		||||
  uint16_t        ADC_Filtered;
 | 
			
		||||
  float           U_Current;
 | 
			
		||||
  
 | 
			
		||||
  
 | 
			
		||||
  
 | 
			
		||||
  
 | 
			
		||||
  /* Parameter for calc voltage */
 | 
			
		||||
  uint16_t        refADC_zero;
 | 
			
		||||
  uint16_t        refADC_calibr;
 | 
			
		||||
  float           refU_step;
 | 
			
		||||
  
 | 
			
		||||
  uint16_t        ADC_Max;
 | 
			
		||||
  uint16_t        ADC_Min;
 | 
			
		||||
   
 | 
			
		||||
  unsigned        pulse_width; 
 | 
			
		||||
  unsigned        max_value_ind; 
 | 
			
		||||
  
 | 
			
		||||
  uint8_t         ChMask;
 | 
			
		||||
  ADC_ChannelState state;
 | 
			
		||||
  
 | 
			
		||||
  ADCChannel_TrackerTypeDef   adc_ch_err;
 | 
			
		||||
}TESTER_ADCChannelTypeDef;
 | 
			
		||||
 | 
			
		||||
typedef struct
 | 
			
		||||
{
 | 
			
		||||
  int32_t t_current;
 | 
			
		||||
  int32_t t_critical;
 | 
			
		||||
  
 | 
			
		||||
#ifdef FOSTER_STUDENT_USER_T_CRITICAL
 | 
			
		||||
#else
 | 
			
		||||
  uint8_t precise_table_ind;  
 | 
			
		||||
#endif
 | 
			
		||||
  uint16_t array_size;
 | 
			
		||||
  
 | 
			
		||||
}TESTER_ADCFilterTypeDef;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
typedef struct
 | 
			
		||||
{
 | 
			
		||||
  TESTER_ADCChannelTypeDef chAdc;
 | 
			
		||||
  
 | 
			
		||||
  ADC_HandleTypeDef *hadc; 
 | 
			
		||||
 | 
			
		||||
  TESTER_ADCFilterTypeDef filter;
 | 
			
		||||
  
 | 
			
		||||
  struct
 | 
			
		||||
  {
 | 
			
		||||
    
 | 
			
		||||
    unsigned adc_running:1;
 | 
			
		||||
    unsigned enable_dmaBuffTransfer:1;
 | 
			
		||||
    unsigned dmaBufferHalfDone:2;
 | 
			
		||||
    unsigned dmaHandlerbusy:1;
 | 
			
		||||
  }f;
 | 
			
		||||
  ADC_TrackerTypeDef adc_err;
 | 
			
		||||
}TESTER_ADCTypeDef;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
extern TESTER_ADCTypeDef tester_adc;
 | 
			
		||||
extern uint16_t ADC_DMA_Buff[ADC_DMA_BUFF_SIZE];
 | 
			
		||||
extern uint16_t ADC_DMA_HalfBuff[ADC_DMA_BUFF_SIZE/2];
 | 
			
		||||
 | 
			
		||||
void TESTER_ADC_StructInit(TESTER_ADCTypeDef *adc);
 | 
			
		||||
 | 
			
		||||
void ADC_DMA_Handler(TESTER_ADCTypeDef *adc);
 | 
			
		||||
 | 
			
		||||
void ADC_DMA_ProcessBuffer(TESTER_ADCTypeDef *adc);
 | 
			
		||||
void ADC_DMA_Channels_Prepare(TESTER_ADCChannelTypeDef *adc_fuel_cells, uint8_t MaskForChannels, uint8_t state);
 | 
			
		||||
HAL_StatusTypeDef ADC_DMA_StartRead(TESTER_ADCTypeDef *adc);
 | 
			
		||||
HAL_StatusTypeDef ADC_DMA_ReadWhileDMA(TESTER_ADCTypeDef *adc, uint32_t Timeout);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifndef printf_adc_result
 | 
			
		||||
#define printf_adc_result(...)
 | 
			
		||||
#endif
 | 
			
		||||
#ifndef printf_adc_processing
 | 
			
		||||
#define printf_adc_processing(...)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef printf_adc_err
 | 
			
		||||
#define printf_adc_err(...)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef printf_adc_it
 | 
			
		||||
#define printf_adc_it(...)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef printf_adc
 | 
			
		||||
#define printf_adc(...)
 | 
			
		||||
#endif
 | 
			
		||||
#endif //_TESTER_ADC_FUNC_H_
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										67
									
								
								diode_tester/Core/Tester_main/tester_config.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										67
									
								
								diode_tester/Core/Tester_main/tester_config.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,67 @@
 | 
			
		||||
/**
 | 
			
		||||
**************************************************************************
 | 
			
		||||
* @file tester_config.h
 | 
			
		||||
* @brief Конфигурации для тестера диодов
 | 
			
		||||
**************************************************************************
 | 
			
		||||
* @defgroup    TESTER_CONFIGS    Configs for project
 | 
			
		||||
* @brief       Конфигурации для тестера диодов
 | 
			
		||||
* @details     
 | 
			
		||||
@{
 | 
			
		||||
*************************************************************************/
 | 
			
		||||
#ifndef _TESTER_CONFIG_H_
 | 
			
		||||
#define _TESTER_CONFIG_H_
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/** 
 | 
			
		||||
	* @addtogroup TESTER_ADC_CONFIG   Configs for ADC
 | 
			
		||||
	* @ingroup 		TESTER_CONFIGS
 | 
			
		||||
  * @brief      Конфигурации для АЦП
 | 
			
		||||
	@{
 | 
			
		||||
	*/
 | 
			
		||||
  
 | 
			
		||||
#define ADC_BUFF_SIZE                           (500)               ///< Размер буфера АЦП
 | 
			
		||||
#define ADC_DMA_BUFF_SIZE                       (ADC_BUFF_SIZE*4)   ///< Размер буфера ДМА (4 канала)
 | 
			
		||||
 | 
			
		||||
#define ADC_U_CALIBR                            ((float)1.1)        ///< Напряжение, которое подается при калибровке
 | 
			
		||||
  
 | 
			
		||||
#define ADC_READ_TIMEOUT_MS                     20    ///< Таймаут на ожидание разрядки конденсатора
 | 
			
		||||
#define ADC_ZERO_WAIT_TIMEOUS_MS                100   ///< Таймаут на ожидание нуля (при калибровке)
 | 
			
		||||
 | 
			
		||||
#define FOSTER_STUDENT_N                        40    ///< Выборка для определения начала разрядки конденсатора
 | 
			
		||||
#define FOSTER_STUDENT_MSE                      2561  /*!<  @brief Среднеквадратическая ошибка для выборки размером FOSTER_STUDENT_N, умноженная на 1000
 | 
			
		||||
                                                            @details Выражение для СКО: sqrt(2*ln(N) - 0,8456) 
 | 
			
		||||
                                                            URL: https://old.stgau.ru/company/personal/user/7750/files/lib/%D0%A1%D1%82%D0%B0%D1%82%D0%B8%D1%81%D1%82%D0%B8%D1%87%D0%B5%D1%81%D0%BA%D0%B8%D0%B5%20%D0%BC%D0%B5%D1%82%D0%BE%D0%B4%D1%8B%20%D0%BF%D1%80%D0%BE%D0%B3%D0%BD%D0%BE%D0%B7%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D1%8F/%D0%9F%D1%80%D0%B0%D0%BA%D1%82%D0%B8%D0%BA%D1%83%D0%BC_%D1%82%D0%B5%D0%BC%D0%B0%201.pdf
 | 
			
		||||
                                                            */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief    Критическое значение Стьюдента
 | 
			
		||||
  * @details  Используется для определения разрядки конденсатора.
 | 
			
		||||
  *           Записывается в единицах*1000
 | 
			
		||||
  * @note     Если закомментировать, то будет использоваться таблица указанная в @ref FOSTER_STUDENT_T_CRITICALS
 | 
			
		||||
              с индексом, указанным в @ref precise_table_ind
 | 
			
		||||
  */
 | 
			
		||||
#define FOSTER_STUDENT_USER_T_CRITICAL          1600//2650//2500
 | 
			
		||||
/**
 | 
			
		||||
  * @brief    Критическое значение Стьюдента для калибровки
 | 
			
		||||
  * @details  Используется для определения разрядки конденсатора при калибровке.
 | 
			
		||||
  *           Записывается в единицах*1000
 | 
			
		||||
  * @note     Если закомментировать, то будет использоваться значение указанное в @ref FOSTER_STUDENT_USER_T_CRITICAL
 | 
			
		||||
  */
 | 
			
		||||
//#define FOSTER_STUDENT_USER_T_CRITICAL_CALIBR   2600//2650//2500
 | 
			
		||||
/**
 | 
			
		||||
  * @brief    Таблица критических значений Стьюдента с разной погрешностью
 | 
			
		||||
  * @details  Используется для определения разрядки конденсатора при закомментированном
 | 
			
		||||
  *           @ref FOSTER_STUDENT_USER_T_CRITICAL
 | 
			
		||||
  */
 | 
			
		||||
#define FOSTER_STUDENT_T_CRITICALS              {257, 688, 1328, 1729, 2093, 2539}
 | 
			
		||||
/** TESTER_ADC_CONFIG
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/** TESTER_CONFIGS
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
#endif //_TESTER_CONFIG_H_
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,915 @@
 | 
			
		||||
/**
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  * @file    stm32f1xx_hal_uart.h
 | 
			
		||||
  * @author  MCD Application Team
 | 
			
		||||
  * @brief   Header file of UART HAL module.
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  * @attention
 | 
			
		||||
  *
 | 
			
		||||
  * Copyright (c) 2016 STMicroelectronics.
 | 
			
		||||
  * All rights reserved.
 | 
			
		||||
  *
 | 
			
		||||
  * This software is licensed under terms that can be found in the LICENSE file
 | 
			
		||||
  * in the root directory of this software component.
 | 
			
		||||
  * If no LICENSE file comes with this software, it is provided AS-IS.
 | 
			
		||||
  *
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/* Define to prevent recursive inclusion -------------------------------------*/
 | 
			
		||||
#ifndef __STM32F1xx_HAL_UART_H
 | 
			
		||||
#define __STM32F1xx_HAL_UART_H
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
extern "C" {
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/* Includes ------------------------------------------------------------------*/
 | 
			
		||||
#include "stm32f1xx_hal_def.h"
 | 
			
		||||
 | 
			
		||||
/** @addtogroup STM32F1xx_HAL_Driver
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @addtogroup UART
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/* Exported types ------------------------------------------------------------*/
 | 
			
		||||
/** @defgroup UART_Exported_Types UART Exported Types
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief UART Init Structure definition
 | 
			
		||||
  */
 | 
			
		||||
typedef struct
 | 
			
		||||
{
 | 
			
		||||
  uint32_t BaudRate;                  /*!< This member configures the UART communication baud rate.
 | 
			
		||||
                                           The baud rate is computed using the following formula:
 | 
			
		||||
                                           - IntegerDivider = ((PCLKx) / (16 * (huart->Init.BaudRate)))
 | 
			
		||||
                                           - FractionalDivider = ((IntegerDivider - ((uint32_t) IntegerDivider)) * 16) + 0.5 */
 | 
			
		||||
 | 
			
		||||
  uint32_t WordLength;                /*!< Specifies the number of data bits transmitted or received in a frame.
 | 
			
		||||
                                           This parameter can be a value of @ref UART_Word_Length */
 | 
			
		||||
 | 
			
		||||
  uint32_t StopBits;                  /*!< Specifies the number of stop bits transmitted.
 | 
			
		||||
                                           This parameter can be a value of @ref UART_Stop_Bits */
 | 
			
		||||
 | 
			
		||||
  uint32_t Parity;                    /*!< Specifies the parity mode.
 | 
			
		||||
                                           This parameter can be a value of @ref UART_Parity
 | 
			
		||||
                                           @note When parity is enabled, the computed parity is inserted
 | 
			
		||||
                                                 at the MSB position of the transmitted data (9th bit when
 | 
			
		||||
                                                 the word length is set to 9 data bits; 8th bit when the
 | 
			
		||||
                                                 word length is set to 8 data bits). */
 | 
			
		||||
 | 
			
		||||
  uint32_t Mode;                      /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.
 | 
			
		||||
                                           This parameter can be a value of @ref UART_Mode */
 | 
			
		||||
 | 
			
		||||
  uint32_t HwFlowCtl;                 /*!< Specifies whether the hardware flow control mode is enabled or disabled.
 | 
			
		||||
                                           This parameter can be a value of @ref UART_Hardware_Flow_Control */
 | 
			
		||||
 | 
			
		||||
  uint32_t OverSampling;              /*!< Specifies whether the Over sampling 8 is enabled or disabled, to achieve higher speed (up to fPCLK/8).
 | 
			
		||||
                                           This parameter can be a value of @ref UART_Over_Sampling. This feature is only available
 | 
			
		||||
                                           on STM32F100xx family, so OverSampling parameter should always be set to 16. */
 | 
			
		||||
} UART_InitTypeDef;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief HAL UART State structures definition
 | 
			
		||||
  * @note  HAL UART State value is a combination of 2 different substates: gState and RxState.
 | 
			
		||||
  *        - gState contains UART state information related to global Handle management
 | 
			
		||||
  *          and also information related to Tx operations.
 | 
			
		||||
  *          gState value coding follow below described bitmap :
 | 
			
		||||
  *          b7-b6  Error information
 | 
			
		||||
  *             00 : No Error
 | 
			
		||||
  *             01 : (Not Used)
 | 
			
		||||
  *             10 : Timeout
 | 
			
		||||
  *             11 : Error
 | 
			
		||||
  *          b5     Peripheral initialization status
 | 
			
		||||
  *             0  : Reset (Peripheral not initialized)
 | 
			
		||||
  *             1  : Init done (Peripheral initialized. HAL UART Init function already called)
 | 
			
		||||
  *          b4-b3  (not used)
 | 
			
		||||
  *             xx : Should be set to 00
 | 
			
		||||
  *          b2     Intrinsic process state
 | 
			
		||||
  *             0  : Ready
 | 
			
		||||
  *             1  : Busy (Peripheral busy with some configuration or internal operations)
 | 
			
		||||
  *          b1     (not used)
 | 
			
		||||
  *             x  : Should be set to 0
 | 
			
		||||
  *          b0     Tx state
 | 
			
		||||
  *             0  : Ready (no Tx operation ongoing)
 | 
			
		||||
  *             1  : Busy (Tx operation ongoing)
 | 
			
		||||
  *        - RxState contains information related to Rx operations.
 | 
			
		||||
  *          RxState value coding follow below described bitmap :
 | 
			
		||||
  *          b7-b6  (not used)
 | 
			
		||||
  *             xx : Should be set to 00
 | 
			
		||||
  *          b5     Peripheral initialization status
 | 
			
		||||
  *             0  : Reset (Peripheral not initialized)
 | 
			
		||||
  *             1  : Init done (Peripheral initialized)
 | 
			
		||||
  *          b4-b2  (not used)
 | 
			
		||||
  *            xxx : Should be set to 000
 | 
			
		||||
  *          b1     Rx state
 | 
			
		||||
  *             0  : Ready (no Rx operation ongoing)
 | 
			
		||||
  *             1  : Busy (Rx operation ongoing)
 | 
			
		||||
  *          b0     (not used)
 | 
			
		||||
  *             x  : Should be set to 0.
 | 
			
		||||
  */
 | 
			
		||||
typedef enum
 | 
			
		||||
{
 | 
			
		||||
  HAL_UART_STATE_RESET             = 0x00U,    /*!< Peripheral is not yet Initialized
 | 
			
		||||
                                                   Value is allowed for gState and RxState */
 | 
			
		||||
  HAL_UART_STATE_READY             = 0x20U,    /*!< Peripheral Initialized and ready for use
 | 
			
		||||
                                                   Value is allowed for gState and RxState */
 | 
			
		||||
  HAL_UART_STATE_BUSY              = 0x24U,    /*!< an internal process is ongoing
 | 
			
		||||
                                                   Value is allowed for gState only */
 | 
			
		||||
  HAL_UART_STATE_BUSY_TX           = 0x21U,    /*!< Data Transmission process is ongoing
 | 
			
		||||
                                                   Value is allowed for gState only */
 | 
			
		||||
  HAL_UART_STATE_BUSY_RX           = 0x22U,    /*!< Data Reception process is ongoing
 | 
			
		||||
                                                   Value is allowed for RxState only */
 | 
			
		||||
  HAL_UART_STATE_BUSY_TX_RX        = 0x23U,    /*!< Data Transmission and Reception process is ongoing
 | 
			
		||||
                                                   Not to be used for neither gState nor RxState.
 | 
			
		||||
                                                   Value is result of combination (Or) between gState and RxState values */
 | 
			
		||||
  HAL_UART_STATE_TIMEOUT           = 0xA0U,    /*!< Timeout state
 | 
			
		||||
                                                   Value is allowed for gState only */
 | 
			
		||||
  HAL_UART_STATE_ERROR             = 0xE0U     /*!< Error
 | 
			
		||||
                                                   Value is allowed for gState only */
 | 
			
		||||
} HAL_UART_StateTypeDef;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief HAL UART Reception type definition
 | 
			
		||||
  * @note  HAL UART Reception type value aims to identify which type of Reception is ongoing.
 | 
			
		||||
  *        This parameter can be a value of @ref UART_Reception_Type_Values :
 | 
			
		||||
  *           HAL_UART_RECEPTION_STANDARD         = 0x00U,
 | 
			
		||||
  *           HAL_UART_RECEPTION_TOIDLE           = 0x01U,
 | 
			
		||||
  */
 | 
			
		||||
typedef uint32_t HAL_UART_RxTypeTypeDef;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief HAL UART Rx Event type definition
 | 
			
		||||
  * @note  HAL UART Rx Event type value aims to identify which type of Event has occurred
 | 
			
		||||
  *        leading to call of the RxEvent callback.
 | 
			
		||||
  *        This parameter can be a value of @ref UART_RxEvent_Type_Values :
 | 
			
		||||
  *           HAL_UART_RXEVENT_TC                 = 0x00U,
 | 
			
		||||
  *           HAL_UART_RXEVENT_HT                 = 0x01U,
 | 
			
		||||
  *           HAL_UART_RXEVENT_IDLE               = 0x02U,
 | 
			
		||||
  */
 | 
			
		||||
typedef uint32_t HAL_UART_RxEventTypeTypeDef;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  UART handle Structure definition
 | 
			
		||||
  */
 | 
			
		||||
typedef struct __UART_HandleTypeDef
 | 
			
		||||
{
 | 
			
		||||
  USART_TypeDef                 *Instance;        /*!< UART registers base address        */
 | 
			
		||||
 | 
			
		||||
  UART_InitTypeDef              Init;             /*!< UART communication parameters      */
 | 
			
		||||
 | 
			
		||||
  const uint8_t                 *pTxBuffPtr;      /*!< Pointer to UART Tx transfer Buffer */
 | 
			
		||||
 | 
			
		||||
  uint16_t                      TxXferSize;       /*!< UART Tx Transfer size              */
 | 
			
		||||
 | 
			
		||||
  __IO uint16_t                 TxXferCount;      /*!< UART Tx Transfer Counter           */
 | 
			
		||||
 | 
			
		||||
  uint8_t                       *pRxBuffPtr;      /*!< Pointer to UART Rx transfer Buffer */
 | 
			
		||||
 | 
			
		||||
  uint16_t                      RxXferSize;       /*!< UART Rx Transfer size              */
 | 
			
		||||
 | 
			
		||||
  __IO uint16_t                 RxXferCount;      /*!< UART Rx Transfer Counter           */
 | 
			
		||||
 | 
			
		||||
  __IO HAL_UART_RxTypeTypeDef ReceptionType;      /*!< Type of ongoing reception          */
 | 
			
		||||
 | 
			
		||||
  __IO HAL_UART_RxEventTypeTypeDef RxEventType;   /*!< Type of Rx Event                   */
 | 
			
		||||
 | 
			
		||||
  DMA_HandleTypeDef             *hdmatx;          /*!< UART Tx DMA Handle parameters      */
 | 
			
		||||
 | 
			
		||||
  DMA_HandleTypeDef             *hdmarx;          /*!< UART Rx DMA Handle parameters      */
 | 
			
		||||
 | 
			
		||||
  HAL_LockTypeDef               Lock;             /*!< Locking object                     */
 | 
			
		||||
 | 
			
		||||
  __IO HAL_UART_StateTypeDef    gState;           /*!< UART state information related to global Handle management
 | 
			
		||||
                                                       and also related to Tx operations.
 | 
			
		||||
                                                       This parameter can be a value of @ref HAL_UART_StateTypeDef */
 | 
			
		||||
 | 
			
		||||
  __IO HAL_UART_StateTypeDef    RxState;          /*!< UART state information related to Rx operations.
 | 
			
		||||
                                                       This parameter can be a value of @ref HAL_UART_StateTypeDef */
 | 
			
		||||
 | 
			
		||||
  __IO uint32_t                 ErrorCode;        /*!< UART Error code                    */
 | 
			
		||||
 | 
			
		||||
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
 | 
			
		||||
  void (* TxHalfCpltCallback)(struct __UART_HandleTypeDef *huart);        /*!< UART Tx Half Complete Callback        */
 | 
			
		||||
  void (* TxCpltCallback)(struct __UART_HandleTypeDef *huart);            /*!< UART Tx Complete Callback             */
 | 
			
		||||
  void (* RxHalfCpltCallback)(struct __UART_HandleTypeDef *huart);        /*!< UART Rx Half Complete Callback        */
 | 
			
		||||
  void (* RxCpltCallback)(struct __UART_HandleTypeDef *huart);            /*!< UART Rx Complete Callback             */
 | 
			
		||||
  void (* ErrorCallback)(struct __UART_HandleTypeDef *huart);             /*!< UART Error Callback                   */
 | 
			
		||||
  void (* AbortCpltCallback)(struct __UART_HandleTypeDef *huart);         /*!< UART Abort Complete Callback          */
 | 
			
		||||
  void (* AbortTransmitCpltCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Abort Transmit Complete Callback */
 | 
			
		||||
  void (* AbortReceiveCpltCallback)(struct __UART_HandleTypeDef *huart);  /*!< UART Abort Receive Complete Callback  */
 | 
			
		||||
  void (* WakeupCallback)(struct __UART_HandleTypeDef *huart);            /*!< UART Wakeup Callback                  */
 | 
			
		||||
  void (* RxEventCallback)(struct __UART_HandleTypeDef *huart, uint16_t Pos); /*!< UART Reception Event Callback     */
 | 
			
		||||
 | 
			
		||||
  void (* MspInitCallback)(struct __UART_HandleTypeDef *huart);           /*!< UART Msp Init callback                */
 | 
			
		||||
  void (* MspDeInitCallback)(struct __UART_HandleTypeDef *huart);         /*!< UART Msp DeInit callback              */
 | 
			
		||||
#endif  /* USE_HAL_UART_REGISTER_CALLBACKS */
 | 
			
		||||
 | 
			
		||||
} UART_HandleTypeDef;
 | 
			
		||||
 | 
			
		||||
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  HAL UART Callback ID enumeration definition
 | 
			
		||||
  */
 | 
			
		||||
typedef enum
 | 
			
		||||
{
 | 
			
		||||
  HAL_UART_TX_HALFCOMPLETE_CB_ID         = 0x00U,    /*!< UART Tx Half Complete Callback ID        */
 | 
			
		||||
  HAL_UART_TX_COMPLETE_CB_ID             = 0x01U,    /*!< UART Tx Complete Callback ID             */
 | 
			
		||||
  HAL_UART_RX_HALFCOMPLETE_CB_ID         = 0x02U,    /*!< UART Rx Half Complete Callback ID        */
 | 
			
		||||
  HAL_UART_RX_COMPLETE_CB_ID             = 0x03U,    /*!< UART Rx Complete Callback ID             */
 | 
			
		||||
  HAL_UART_ERROR_CB_ID                   = 0x04U,    /*!< UART Error Callback ID                   */
 | 
			
		||||
  HAL_UART_ABORT_COMPLETE_CB_ID          = 0x05U,    /*!< UART Abort Complete Callback ID          */
 | 
			
		||||
  HAL_UART_ABORT_TRANSMIT_COMPLETE_CB_ID = 0x06U,    /*!< UART Abort Transmit Complete Callback ID */
 | 
			
		||||
  HAL_UART_ABORT_RECEIVE_COMPLETE_CB_ID  = 0x07U,    /*!< UART Abort Receive Complete Callback ID  */
 | 
			
		||||
  HAL_UART_WAKEUP_CB_ID                  = 0x08U,    /*!< UART Wakeup Callback ID                  */
 | 
			
		||||
 | 
			
		||||
  HAL_UART_MSPINIT_CB_ID                 = 0x0BU,    /*!< UART MspInit callback ID                 */
 | 
			
		||||
  HAL_UART_MSPDEINIT_CB_ID               = 0x0CU     /*!< UART MspDeInit callback ID               */
 | 
			
		||||
 | 
			
		||||
} HAL_UART_CallbackIDTypeDef;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  HAL UART Callback pointer definition
 | 
			
		||||
  */
 | 
			
		||||
typedef  void (*pUART_CallbackTypeDef)(UART_HandleTypeDef *huart);  /*!< pointer to an UART callback function */
 | 
			
		||||
typedef  void (*pUART_RxEventCallbackTypeDef)(struct __UART_HandleTypeDef *huart, uint16_t Pos);   /*!< pointer to a UART Rx Event specific callback function */
 | 
			
		||||
 | 
			
		||||
#endif /* USE_HAL_UART_REGISTER_CALLBACKS */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/* Exported constants --------------------------------------------------------*/
 | 
			
		||||
/** @defgroup UART_Exported_Constants UART Exported Constants
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup UART_Error_Code UART Error Code
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
#define HAL_UART_ERROR_NONE              0x00000000U   /*!< No error            */
 | 
			
		||||
#define HAL_UART_ERROR_PE                0x00000001U   /*!< Parity error        */
 | 
			
		||||
#define HAL_UART_ERROR_NE                0x00000002U   /*!< Noise error         */
 | 
			
		||||
#define HAL_UART_ERROR_FE                0x00000004U   /*!< Frame error         */
 | 
			
		||||
#define HAL_UART_ERROR_ORE               0x00000008U   /*!< Overrun error       */
 | 
			
		||||
#define HAL_UART_ERROR_DMA               0x00000010U   /*!< DMA transfer error  */
 | 
			
		||||
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
 | 
			
		||||
#define  HAL_UART_ERROR_INVALID_CALLBACK 0x00000020U   /*!< Invalid Callback error  */
 | 
			
		||||
#endif /* USE_HAL_UART_REGISTER_CALLBACKS */
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup UART_Word_Length UART Word Length
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
#define UART_WORDLENGTH_8B                  0x00000000U
 | 
			
		||||
#define UART_WORDLENGTH_9B                  ((uint32_t)USART_CR1_M)
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup UART_Stop_Bits UART Number of Stop Bits
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
#define UART_STOPBITS_1                     0x00000000U
 | 
			
		||||
#define UART_STOPBITS_2                     ((uint32_t)USART_CR2_STOP_1)
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup UART_Parity UART Parity
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
#define UART_PARITY_NONE                    0x00000000U
 | 
			
		||||
#define UART_PARITY_EVEN                    ((uint32_t)USART_CR1_PCE)
 | 
			
		||||
#define UART_PARITY_ODD                     ((uint32_t)(USART_CR1_PCE | USART_CR1_PS))
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup UART_Hardware_Flow_Control UART Hardware Flow Control
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
#define UART_HWCONTROL_NONE                  0x00000000U
 | 
			
		||||
#define UART_HWCONTROL_RTS                   ((uint32_t)USART_CR3_RTSE)
 | 
			
		||||
#define UART_HWCONTROL_CTS                   ((uint32_t)USART_CR3_CTSE)
 | 
			
		||||
#define UART_HWCONTROL_RTS_CTS               ((uint32_t)(USART_CR3_RTSE | USART_CR3_CTSE))
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup UART_Mode UART Transfer Mode
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
#define UART_MODE_RX                        ((uint32_t)USART_CR1_RE)
 | 
			
		||||
#define UART_MODE_TX                        ((uint32_t)USART_CR1_TE)
 | 
			
		||||
#define UART_MODE_TX_RX                     ((uint32_t)(USART_CR1_TE | USART_CR1_RE))
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup UART_State UART State
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
#define UART_STATE_DISABLE                  0x00000000U
 | 
			
		||||
#define UART_STATE_ENABLE                   ((uint32_t)USART_CR1_UE)
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup UART_Over_Sampling UART Over Sampling
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
#define UART_OVERSAMPLING_16                    0x00000000U
 | 
			
		||||
#if defined(USART_CR1_OVER8)
 | 
			
		||||
#define UART_OVERSAMPLING_8                     ((uint32_t)USART_CR1_OVER8)
 | 
			
		||||
#endif /* USART_CR1_OVER8 */
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup UART_LIN_Break_Detection_Length  UART LIN Break Detection Length
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
#define UART_LINBREAKDETECTLENGTH_10B      0x00000000U
 | 
			
		||||
#define UART_LINBREAKDETECTLENGTH_11B      ((uint32_t)USART_CR2_LBDL)
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup UART_WakeUp_functions  UART Wakeup Functions
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
#define UART_WAKEUPMETHOD_IDLELINE                0x00000000U
 | 
			
		||||
#define UART_WAKEUPMETHOD_ADDRESSMARK             ((uint32_t)USART_CR1_WAKE)
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup UART_Flags   UART FLags
 | 
			
		||||
  *        Elements values convention: 0xXXXX
 | 
			
		||||
  *           - 0xXXXX  : Flag mask in the SR register
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
#define UART_FLAG_CTS                       ((uint32_t)USART_SR_CTS)
 | 
			
		||||
#define UART_FLAG_LBD                       ((uint32_t)USART_SR_LBD)
 | 
			
		||||
#define UART_FLAG_TXE                       ((uint32_t)USART_SR_TXE)
 | 
			
		||||
#define UART_FLAG_TC                        ((uint32_t)USART_SR_TC)
 | 
			
		||||
#define UART_FLAG_RXNE                      ((uint32_t)USART_SR_RXNE)
 | 
			
		||||
#define UART_FLAG_IDLE                      ((uint32_t)USART_SR_IDLE)
 | 
			
		||||
#define UART_FLAG_ORE                       ((uint32_t)USART_SR_ORE)
 | 
			
		||||
#define UART_FLAG_NE                        ((uint32_t)USART_SR_NE)
 | 
			
		||||
#define UART_FLAG_FE                        ((uint32_t)USART_SR_FE)
 | 
			
		||||
#define UART_FLAG_PE                        ((uint32_t)USART_SR_PE)
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup UART_Interrupt_definition  UART Interrupt Definitions
 | 
			
		||||
  *        Elements values convention: 0xY000XXXX
 | 
			
		||||
  *           - XXXX  : Interrupt mask (16 bits) in the Y register
 | 
			
		||||
  *           - Y  : Interrupt source register (2bits)
 | 
			
		||||
  *                   - 0001: CR1 register
 | 
			
		||||
  *                   - 0010: CR2 register
 | 
			
		||||
  *                   - 0011: CR3 register
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
#define UART_IT_PE                       ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_PEIE))
 | 
			
		||||
#define UART_IT_TXE                      ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_TXEIE))
 | 
			
		||||
#define UART_IT_TC                       ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_TCIE))
 | 
			
		||||
#define UART_IT_RXNE                     ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_RXNEIE))
 | 
			
		||||
#define UART_IT_IDLE                     ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_IDLEIE))
 | 
			
		||||
 | 
			
		||||
#define UART_IT_LBD                      ((uint32_t)(UART_CR2_REG_INDEX << 28U | USART_CR2_LBDIE))
 | 
			
		||||
 | 
			
		||||
#define UART_IT_CTS                      ((uint32_t)(UART_CR3_REG_INDEX << 28U | USART_CR3_CTSIE))
 | 
			
		||||
#define UART_IT_ERR                      ((uint32_t)(UART_CR3_REG_INDEX << 28U | USART_CR3_EIE))
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup UART_Reception_Type_Values  UART Reception type values
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
#define HAL_UART_RECEPTION_STANDARD          (0x00000000U)             /*!< Standard reception                       */
 | 
			
		||||
#define HAL_UART_RECEPTION_TOIDLE            (0x00000001U)             /*!< Reception till completion or IDLE event  */
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup UART_RxEvent_Type_Values  UART RxEvent type values
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
#define HAL_UART_RXEVENT_TC                  (0x00000000U)             /*!< RxEvent linked to Transfer Complete event */
 | 
			
		||||
#define HAL_UART_RXEVENT_HT                  (0x00000001U)             /*!< RxEvent linked to Half Transfer event     */
 | 
			
		||||
#define HAL_UART_RXEVENT_IDLE                (0x00000002U)
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/* Exported macro ------------------------------------------------------------*/
 | 
			
		||||
/** @defgroup UART_Exported_Macros UART Exported Macros
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @brief Reset UART handle gstate & RxState
 | 
			
		||||
  * @param  __HANDLE__ specifies the UART Handle.
 | 
			
		||||
  *         UART Handle selects the USARTx or UARTy peripheral
 | 
			
		||||
  *         (USART,UART availability and x,y values depending on device).
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
 | 
			
		||||
#define __HAL_UART_RESET_HANDLE_STATE(__HANDLE__)  do{                                                   \
 | 
			
		||||
                                                       (__HANDLE__)->gState = HAL_UART_STATE_RESET;      \
 | 
			
		||||
                                                       (__HANDLE__)->RxState = HAL_UART_STATE_RESET;     \
 | 
			
		||||
                                                       (__HANDLE__)->MspInitCallback = NULL;             \
 | 
			
		||||
                                                       (__HANDLE__)->MspDeInitCallback = NULL;           \
 | 
			
		||||
                                                     } while(0U)
 | 
			
		||||
#else
 | 
			
		||||
#define __HAL_UART_RESET_HANDLE_STATE(__HANDLE__)  do{                                                   \
 | 
			
		||||
                                                       (__HANDLE__)->gState = HAL_UART_STATE_RESET;      \
 | 
			
		||||
                                                       (__HANDLE__)->RxState = HAL_UART_STATE_RESET;     \
 | 
			
		||||
                                                     } while(0U)
 | 
			
		||||
#endif /*USE_HAL_UART_REGISTER_CALLBACKS */
 | 
			
		||||
 | 
			
		||||
/** @brief  Flushes the UART DR register
 | 
			
		||||
  * @param  __HANDLE__ specifies the UART Handle.
 | 
			
		||||
  *         UART Handle selects the USARTx or UARTy peripheral
 | 
			
		||||
  *         (USART,UART availability and x,y values depending on device).
 | 
			
		||||
  */
 | 
			
		||||
#define __HAL_UART_FLUSH_DRREGISTER(__HANDLE__) ((__HANDLE__)->Instance->DR)
 | 
			
		||||
 | 
			
		||||
/** @brief  Checks whether the specified UART flag is set or not.
 | 
			
		||||
  * @param  __HANDLE__ specifies the UART Handle.
 | 
			
		||||
  *         UART Handle selects the USARTx or UARTy peripheral
 | 
			
		||||
  *         (USART,UART availability and x,y values depending on device).
 | 
			
		||||
  * @param  __FLAG__ specifies the flag to check.
 | 
			
		||||
  *        This parameter can be one of the following values:
 | 
			
		||||
  *            @arg UART_FLAG_CTS:  CTS Change flag (not available for UART4 and UART5)
 | 
			
		||||
  *            @arg UART_FLAG_LBD:  LIN Break detection flag
 | 
			
		||||
  *            @arg UART_FLAG_TXE:  Transmit data register empty flag
 | 
			
		||||
  *            @arg UART_FLAG_TC:   Transmission Complete flag
 | 
			
		||||
  *            @arg UART_FLAG_RXNE: Receive data register not empty flag
 | 
			
		||||
  *            @arg UART_FLAG_IDLE: Idle Line detection flag
 | 
			
		||||
  *            @arg UART_FLAG_ORE:  Overrun Error flag
 | 
			
		||||
  *            @arg UART_FLAG_NE:   Noise Error flag
 | 
			
		||||
  *            @arg UART_FLAG_FE:   Framing Error flag
 | 
			
		||||
  *            @arg UART_FLAG_PE:   Parity Error flag
 | 
			
		||||
  * @retval The new state of __FLAG__ (TRUE or FALSE).
 | 
			
		||||
  */
 | 
			
		||||
#define __HAL_UART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
 | 
			
		||||
 | 
			
		||||
/** @brief  Clears the specified UART pending flag.
 | 
			
		||||
  * @param  __HANDLE__ specifies the UART Handle.
 | 
			
		||||
  *         UART Handle selects the USARTx or UARTy peripheral
 | 
			
		||||
  *         (USART,UART availability and x,y values depending on device).
 | 
			
		||||
  * @param  __FLAG__ specifies the flag to check.
 | 
			
		||||
  *          This parameter can be any combination of the following values:
 | 
			
		||||
  *            @arg UART_FLAG_CTS:  CTS Change flag (not available for UART4 and UART5).
 | 
			
		||||
  *            @arg UART_FLAG_LBD:  LIN Break detection flag.
 | 
			
		||||
  *            @arg UART_FLAG_TC:   Transmission Complete flag.
 | 
			
		||||
  *            @arg UART_FLAG_RXNE: Receive data register not empty flag.
 | 
			
		||||
  *
 | 
			
		||||
  * @note   PE (Parity error), FE (Framing error), NE (Noise error), ORE (Overrun
 | 
			
		||||
  *          error) and IDLE (Idle line detected) flags are cleared by software
 | 
			
		||||
  *          sequence: a read operation to USART_SR register followed by a read
 | 
			
		||||
  *          operation to USART_DR register.
 | 
			
		||||
  * @note   RXNE flag can be also cleared by a read to the USART_DR register.
 | 
			
		||||
  * @note   TC flag can be also cleared by software sequence: a read operation to
 | 
			
		||||
  *          USART_SR register followed by a write operation to USART_DR register.
 | 
			
		||||
  * @note   TXE flag is cleared only by a write to the USART_DR register.
 | 
			
		||||
  *
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
#define __HAL_UART_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__))
 | 
			
		||||
 | 
			
		||||
/** @brief  Clears the UART PE pending flag.
 | 
			
		||||
  * @param  __HANDLE__ specifies the UART Handle.
 | 
			
		||||
  *         UART Handle selects the USARTx or UARTy peripheral
 | 
			
		||||
  *         (USART,UART availability and x,y values depending on device).
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
#define __HAL_UART_CLEAR_PEFLAG(__HANDLE__)     \
 | 
			
		||||
  do{                                           \
 | 
			
		||||
    __IO uint32_t tmpreg = 0x00U;               \
 | 
			
		||||
    tmpreg = (__HANDLE__)->Instance->SR;        \
 | 
			
		||||
    tmpreg = (__HANDLE__)->Instance->DR;        \
 | 
			
		||||
    UNUSED(tmpreg);                             \
 | 
			
		||||
  } while(0U)
 | 
			
		||||
 | 
			
		||||
/** @brief  Clears the UART FE pending flag.
 | 
			
		||||
  * @param  __HANDLE__ specifies the UART Handle.
 | 
			
		||||
  *         UART Handle selects the USARTx or UARTy peripheral
 | 
			
		||||
  *         (USART,UART availability and x,y values depending on device).
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
#define __HAL_UART_CLEAR_FEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
 | 
			
		||||
 | 
			
		||||
/** @brief  Clears the UART NE pending flag.
 | 
			
		||||
  * @param  __HANDLE__ specifies the UART Handle.
 | 
			
		||||
  *         UART Handle selects the USARTx or UARTy peripheral
 | 
			
		||||
  *         (USART,UART availability and x,y values depending on device).
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
#define __HAL_UART_CLEAR_NEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
 | 
			
		||||
 | 
			
		||||
/** @brief  Clears the UART ORE pending flag.
 | 
			
		||||
  * @param  __HANDLE__ specifies the UART Handle.
 | 
			
		||||
  *         UART Handle selects the USARTx or UARTy peripheral
 | 
			
		||||
  *         (USART,UART availability and x,y values depending on device).
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
#define __HAL_UART_CLEAR_OREFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
 | 
			
		||||
 | 
			
		||||
/** @brief  Clears the UART IDLE pending flag.
 | 
			
		||||
  * @param  __HANDLE__ specifies the UART Handle.
 | 
			
		||||
  *         UART Handle selects the USARTx or UARTy peripheral
 | 
			
		||||
  *         (USART,UART availability and x,y values depending on device).
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
#define __HAL_UART_CLEAR_IDLEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
 | 
			
		||||
 | 
			
		||||
/** @brief  Enable the specified UART interrupt.
 | 
			
		||||
  * @param  __HANDLE__ specifies the UART Handle.
 | 
			
		||||
  *         UART Handle selects the USARTx or UARTy peripheral
 | 
			
		||||
  *         (USART,UART availability and x,y values depending on device).
 | 
			
		||||
  * @param  __INTERRUPT__ specifies the UART interrupt source to enable.
 | 
			
		||||
  *          This parameter can be one of the following values:
 | 
			
		||||
  *            @arg UART_IT_CTS:  CTS change interrupt
 | 
			
		||||
  *            @arg UART_IT_LBD:  LIN Break detection interrupt
 | 
			
		||||
  *            @arg UART_IT_TXE:  Transmit Data Register empty interrupt
 | 
			
		||||
  *            @arg UART_IT_TC:   Transmission complete interrupt
 | 
			
		||||
  *            @arg UART_IT_RXNE: Receive Data register not empty interrupt
 | 
			
		||||
  *            @arg UART_IT_IDLE: Idle line detection interrupt
 | 
			
		||||
  *            @arg UART_IT_PE:   Parity Error interrupt
 | 
			
		||||
  *            @arg UART_IT_ERR:  Error interrupt(Frame error, noise error, overrun error)
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
#define __HAL_UART_ENABLE_IT(__HANDLE__, __INTERRUPT__)   ((((__INTERRUPT__) >> 28U) == UART_CR1_REG_INDEX)? ((__HANDLE__)->Instance->CR1 |= ((__INTERRUPT__) & UART_IT_MASK)): \
 | 
			
		||||
                                                           (((__INTERRUPT__) >> 28U) == UART_CR2_REG_INDEX)? ((__HANDLE__)->Instance->CR2 |= ((__INTERRUPT__) & UART_IT_MASK)): \
 | 
			
		||||
                                                           ((__HANDLE__)->Instance->CR3 |= ((__INTERRUPT__) & UART_IT_MASK)))
 | 
			
		||||
 | 
			
		||||
/** @brief  Disable the specified UART interrupt.
 | 
			
		||||
  * @param  __HANDLE__ specifies the UART Handle.
 | 
			
		||||
  *         UART Handle selects the USARTx or UARTy peripheral
 | 
			
		||||
  *         (USART,UART availability and x,y values depending on device).
 | 
			
		||||
  * @param  __INTERRUPT__ specifies the UART interrupt source to disable.
 | 
			
		||||
  *          This parameter can be one of the following values:
 | 
			
		||||
  *            @arg UART_IT_CTS:  CTS change interrupt
 | 
			
		||||
  *            @arg UART_IT_LBD:  LIN Break detection interrupt
 | 
			
		||||
  *            @arg UART_IT_TXE:  Transmit Data Register empty interrupt
 | 
			
		||||
  *            @arg UART_IT_TC:   Transmission complete interrupt
 | 
			
		||||
  *            @arg UART_IT_RXNE: Receive Data register not empty interrupt
 | 
			
		||||
  *            @arg UART_IT_IDLE: Idle line detection interrupt
 | 
			
		||||
  *            @arg UART_IT_PE:   Parity Error interrupt
 | 
			
		||||
  *            @arg UART_IT_ERR:  Error interrupt(Frame error, noise error, overrun error)
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
#define __HAL_UART_DISABLE_IT(__HANDLE__, __INTERRUPT__)  ((((__INTERRUPT__) >> 28U) == UART_CR1_REG_INDEX)? ((__HANDLE__)->Instance->CR1 &= ~((__INTERRUPT__) & UART_IT_MASK)): \
 | 
			
		||||
                                                           (((__INTERRUPT__) >> 28U) == UART_CR2_REG_INDEX)? ((__HANDLE__)->Instance->CR2 &= ~((__INTERRUPT__) & UART_IT_MASK)): \
 | 
			
		||||
                                                           ((__HANDLE__)->Instance->CR3 &= ~ ((__INTERRUPT__) & UART_IT_MASK)))
 | 
			
		||||
 | 
			
		||||
/** @brief  Checks whether the specified UART interrupt source is enabled or not.
 | 
			
		||||
  * @param  __HANDLE__ specifies the UART Handle.
 | 
			
		||||
  *         UART Handle selects the USARTx or UARTy peripheral
 | 
			
		||||
  *         (USART,UART availability and x,y values depending on device).
 | 
			
		||||
  * @param  __IT__ specifies the UART interrupt source to check.
 | 
			
		||||
  *          This parameter can be one of the following values:
 | 
			
		||||
  *            @arg UART_IT_CTS: CTS change interrupt (not available for UART4 and UART5)
 | 
			
		||||
  *            @arg UART_IT_LBD: LIN Break detection interrupt
 | 
			
		||||
  *            @arg UART_IT_TXE: Transmit Data Register empty interrupt
 | 
			
		||||
  *            @arg UART_IT_TC:  Transmission complete interrupt
 | 
			
		||||
  *            @arg UART_IT_RXNE: Receive Data register not empty interrupt
 | 
			
		||||
  *            @arg UART_IT_IDLE: Idle line detection interrupt
 | 
			
		||||
  *            @arg UART_IT_ERR: Error interrupt
 | 
			
		||||
  * @retval The new state of __IT__ (TRUE or FALSE).
 | 
			
		||||
  */
 | 
			
		||||
#define __HAL_UART_GET_IT_SOURCE(__HANDLE__, __IT__) (((((__IT__) >> 28U) == UART_CR1_REG_INDEX)? (__HANDLE__)->Instance->CR1:(((((uint32_t)(__IT__)) >> 28U) == UART_CR2_REG_INDEX)? \
 | 
			
		||||
                                                       (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & (((uint32_t)(__IT__)) & UART_IT_MASK))
 | 
			
		||||
 | 
			
		||||
/** @brief  Enable CTS flow control
 | 
			
		||||
  * @note   This macro allows to enable CTS hardware flow control for a given UART instance,
 | 
			
		||||
  *         without need to call HAL_UART_Init() function.
 | 
			
		||||
  *         As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
 | 
			
		||||
  * @note   As macro is expected to be used for modifying CTS Hw flow control feature activation, without need
 | 
			
		||||
  *         for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
 | 
			
		||||
  *           - UART instance should have already been initialised (through call of HAL_UART_Init() )
 | 
			
		||||
  *           - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
 | 
			
		||||
  *             and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)).
 | 
			
		||||
  * @param  __HANDLE__ specifies the UART Handle.
 | 
			
		||||
  *         The Handle Instance can be any USARTx (supporting the HW Flow control feature).
 | 
			
		||||
  *         It is used to select the USART peripheral (USART availability and x value depending on device).
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
#define __HAL_UART_HWCONTROL_CTS_ENABLE(__HANDLE__)        \
 | 
			
		||||
  do{                                                      \
 | 
			
		||||
    ATOMIC_SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE);  \
 | 
			
		||||
    (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_CTSE;        \
 | 
			
		||||
  } while(0U)
 | 
			
		||||
 | 
			
		||||
/** @brief  Disable CTS flow control
 | 
			
		||||
  * @note   This macro allows to disable CTS hardware flow control for a given UART instance,
 | 
			
		||||
  *         without need to call HAL_UART_Init() function.
 | 
			
		||||
  *         As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
 | 
			
		||||
  * @note   As macro is expected to be used for modifying CTS Hw flow control feature activation, without need
 | 
			
		||||
  *         for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
 | 
			
		||||
  *           - UART instance should have already been initialised (through call of HAL_UART_Init() )
 | 
			
		||||
  *           - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
 | 
			
		||||
  *             and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)).
 | 
			
		||||
  * @param  __HANDLE__ specifies the UART Handle.
 | 
			
		||||
  *         The Handle Instance can be any USARTx (supporting the HW Flow control feature).
 | 
			
		||||
  *         It is used to select the USART peripheral (USART availability and x value depending on device).
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
#define __HAL_UART_HWCONTROL_CTS_DISABLE(__HANDLE__)        \
 | 
			
		||||
  do{                                                       \
 | 
			
		||||
    ATOMIC_CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE); \
 | 
			
		||||
    (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_CTSE);      \
 | 
			
		||||
  } while(0U)
 | 
			
		||||
 | 
			
		||||
/** @brief  Enable RTS flow control
 | 
			
		||||
  *         This macro allows to enable RTS hardware flow control for a given UART instance,
 | 
			
		||||
  *         without need to call HAL_UART_Init() function.
 | 
			
		||||
  *         As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
 | 
			
		||||
  * @note   As macro is expected to be used for modifying RTS Hw flow control feature activation, without need
 | 
			
		||||
  *         for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
 | 
			
		||||
  *           - UART instance should have already been initialised (through call of HAL_UART_Init() )
 | 
			
		||||
  *           - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
 | 
			
		||||
  *             and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)).
 | 
			
		||||
  * @param  __HANDLE__ specifies the UART Handle.
 | 
			
		||||
  *         The Handle Instance can be any USARTx (supporting the HW Flow control feature).
 | 
			
		||||
  *         It is used to select the USART peripheral (USART availability and x value depending on device).
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
#define __HAL_UART_HWCONTROL_RTS_ENABLE(__HANDLE__)       \
 | 
			
		||||
  do{                                                     \
 | 
			
		||||
    ATOMIC_SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE); \
 | 
			
		||||
    (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_RTSE;       \
 | 
			
		||||
  } while(0U)
 | 
			
		||||
 | 
			
		||||
/** @brief  Disable RTS flow control
 | 
			
		||||
  *         This macro allows to disable RTS hardware flow control for a given UART instance,
 | 
			
		||||
  *         without need to call HAL_UART_Init() function.
 | 
			
		||||
  *         As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
 | 
			
		||||
  * @note   As macro is expected to be used for modifying RTS Hw flow control feature activation, without need
 | 
			
		||||
  *         for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
 | 
			
		||||
  *           - UART instance should have already been initialised (through call of HAL_UART_Init() )
 | 
			
		||||
  *           - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
 | 
			
		||||
  *             and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)).
 | 
			
		||||
  * @param  __HANDLE__ specifies the UART Handle.
 | 
			
		||||
  *         The Handle Instance can be any USARTx (supporting the HW Flow control feature).
 | 
			
		||||
  *         It is used to select the USART peripheral (USART availability and x value depending on device).
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
#define __HAL_UART_HWCONTROL_RTS_DISABLE(__HANDLE__)       \
 | 
			
		||||
  do{                                                      \
 | 
			
		||||
    ATOMIC_CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE);\
 | 
			
		||||
    (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_RTSE);     \
 | 
			
		||||
  } while(0U)
 | 
			
		||||
#if defined(USART_CR3_ONEBIT)
 | 
			
		||||
 | 
			
		||||
/** @brief  Macro to enable the UART's one bit sample method
 | 
			
		||||
  * @param  __HANDLE__ specifies the UART Handle.
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
#define __HAL_UART_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
 | 
			
		||||
 | 
			
		||||
/** @brief  Macro to disable the UART's one bit sample method
 | 
			
		||||
  * @param  __HANDLE__ specifies the UART Handle.
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
#define __HAL_UART_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3\
 | 
			
		||||
                                                       &= (uint16_t)~((uint16_t)USART_CR3_ONEBIT))
 | 
			
		||||
#endif /* UART_ONE_BIT_SAMPLE_Feature */
 | 
			
		||||
 | 
			
		||||
/** @brief  Enable UART
 | 
			
		||||
  * @param  __HANDLE__ specifies the UART Handle.
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
#define __HAL_UART_ENABLE(__HANDLE__)               ((__HANDLE__)->Instance->CR1 |=  USART_CR1_UE)
 | 
			
		||||
 | 
			
		||||
/** @brief  Disable UART
 | 
			
		||||
  * @param  __HANDLE__ specifies the UART Handle.
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
#define __HAL_UART_DISABLE(__HANDLE__)              ((__HANDLE__)->Instance->CR1 &=  ~USART_CR1_UE)
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/* Exported functions --------------------------------------------------------*/
 | 
			
		||||
/** @addtogroup UART_Exported_Functions
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @addtogroup UART_Exported_Functions_Group1 Initialization and de-initialization functions
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/* Initialization/de-initialization functions  **********************************/
 | 
			
		||||
HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart);
 | 
			
		||||
HAL_StatusTypeDef HAL_HalfDuplex_Init(UART_HandleTypeDef *huart);
 | 
			
		||||
HAL_StatusTypeDef HAL_LIN_Init(UART_HandleTypeDef *huart, uint32_t BreakDetectLength);
 | 
			
		||||
HAL_StatusTypeDef HAL_MultiProcessor_Init(UART_HandleTypeDef *huart, uint8_t Address, uint32_t WakeUpMethod);
 | 
			
		||||
HAL_StatusTypeDef HAL_UART_DeInit(UART_HandleTypeDef *huart);
 | 
			
		||||
void HAL_UART_MspInit(UART_HandleTypeDef *huart);
 | 
			
		||||
void HAL_UART_MspDeInit(UART_HandleTypeDef *huart);
 | 
			
		||||
 | 
			
		||||
/* Callbacks Register/UnRegister functions  ***********************************/
 | 
			
		||||
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
 | 
			
		||||
HAL_StatusTypeDef HAL_UART_RegisterCallback(UART_HandleTypeDef *huart, HAL_UART_CallbackIDTypeDef CallbackID,
 | 
			
		||||
                                            pUART_CallbackTypeDef pCallback);
 | 
			
		||||
HAL_StatusTypeDef HAL_UART_UnRegisterCallback(UART_HandleTypeDef *huart, HAL_UART_CallbackIDTypeDef CallbackID);
 | 
			
		||||
 | 
			
		||||
HAL_StatusTypeDef HAL_UART_RegisterRxEventCallback(UART_HandleTypeDef *huart, pUART_RxEventCallbackTypeDef pCallback);
 | 
			
		||||
HAL_StatusTypeDef HAL_UART_UnRegisterRxEventCallback(UART_HandleTypeDef *huart);
 | 
			
		||||
#endif /* USE_HAL_UART_REGISTER_CALLBACKS */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @addtogroup UART_Exported_Functions_Group2 IO operation functions
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/* IO operation functions *******************************************************/
 | 
			
		||||
HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, const uint8_t *pData, uint16_t Size, uint32_t Timeout);
 | 
			
		||||
HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);
 | 
			
		||||
HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, const uint8_t *pData, uint16_t Size);
 | 
			
		||||
HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
 | 
			
		||||
HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, const uint8_t *pData, uint16_t Size);
 | 
			
		||||
HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
 | 
			
		||||
HAL_StatusTypeDef HAL_UART_DMAPause(UART_HandleTypeDef *huart);
 | 
			
		||||
HAL_StatusTypeDef HAL_UART_DMAResume(UART_HandleTypeDef *huart);
 | 
			
		||||
HAL_StatusTypeDef HAL_UART_DMAStop(UART_HandleTypeDef *huart);
 | 
			
		||||
 | 
			
		||||
HAL_StatusTypeDef HAL_UARTEx_ReceiveToIdle(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint16_t *RxLen,
 | 
			
		||||
                                           uint32_t Timeout);
 | 
			
		||||
HAL_StatusTypeDef HAL_UARTEx_ReceiveToIdle_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
 | 
			
		||||
HAL_StatusTypeDef HAL_UARTEx_ReceiveToIdle_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
 | 
			
		||||
 | 
			
		||||
HAL_UART_RxEventTypeTypeDef HAL_UARTEx_GetRxEventType(UART_HandleTypeDef *huart);
 | 
			
		||||
 | 
			
		||||
/* Transfer Abort functions */
 | 
			
		||||
HAL_StatusTypeDef HAL_UART_Abort(UART_HandleTypeDef *huart);
 | 
			
		||||
HAL_StatusTypeDef HAL_UART_AbortTransmit(UART_HandleTypeDef *huart);
 | 
			
		||||
HAL_StatusTypeDef HAL_UART_AbortReceive(UART_HandleTypeDef *huart);
 | 
			
		||||
HAL_StatusTypeDef HAL_UART_Abort_IT(UART_HandleTypeDef *huart);
 | 
			
		||||
HAL_StatusTypeDef HAL_UART_AbortTransmit_IT(UART_HandleTypeDef *huart);
 | 
			
		||||
HAL_StatusTypeDef HAL_UART_AbortReceive_IT(UART_HandleTypeDef *huart);
 | 
			
		||||
 | 
			
		||||
void HAL_UART_IRQHandler(UART_HandleTypeDef *huart);
 | 
			
		||||
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart);
 | 
			
		||||
void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart);
 | 
			
		||||
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart);
 | 
			
		||||
void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart);
 | 
			
		||||
void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart);
 | 
			
		||||
void HAL_UART_AbortCpltCallback(UART_HandleTypeDef *huart);
 | 
			
		||||
void HAL_UART_AbortTransmitCpltCallback(UART_HandleTypeDef *huart);
 | 
			
		||||
void HAL_UART_AbortReceiveCpltCallback(UART_HandleTypeDef *huart);
 | 
			
		||||
 | 
			
		||||
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @addtogroup UART_Exported_Functions_Group3
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
/* Peripheral Control functions  ************************************************/
 | 
			
		||||
HAL_StatusTypeDef HAL_LIN_SendBreak(UART_HandleTypeDef *huart);
 | 
			
		||||
HAL_StatusTypeDef HAL_MultiProcessor_EnterMuteMode(UART_HandleTypeDef *huart);
 | 
			
		||||
HAL_StatusTypeDef HAL_MultiProcessor_ExitMuteMode(UART_HandleTypeDef *huart);
 | 
			
		||||
HAL_StatusTypeDef HAL_HalfDuplex_EnableTransmitter(UART_HandleTypeDef *huart);
 | 
			
		||||
HAL_StatusTypeDef HAL_HalfDuplex_EnableReceiver(UART_HandleTypeDef *huart);
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @addtogroup UART_Exported_Functions_Group4
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
/* Peripheral State functions  **************************************************/
 | 
			
		||||
HAL_UART_StateTypeDef HAL_UART_GetState(const UART_HandleTypeDef *huart);
 | 
			
		||||
uint32_t              HAL_UART_GetError(const UART_HandleTypeDef *huart);
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
/* Private types -------------------------------------------------------------*/
 | 
			
		||||
/* Private variables ---------------------------------------------------------*/
 | 
			
		||||
/* Private constants ---------------------------------------------------------*/
 | 
			
		||||
/** @defgroup UART_Private_Constants UART Private Constants
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
/** @brief UART interruptions flag mask
 | 
			
		||||
  *
 | 
			
		||||
  */
 | 
			
		||||
#define UART_IT_MASK                     0x0000FFFFU
 | 
			
		||||
 | 
			
		||||
#define UART_CR1_REG_INDEX               1U
 | 
			
		||||
#define UART_CR2_REG_INDEX               2U
 | 
			
		||||
#define UART_CR3_REG_INDEX               3U
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/* Private macros ------------------------------------------------------------*/
 | 
			
		||||
/** @defgroup UART_Private_Macros UART Private Macros
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
#define IS_UART_WORD_LENGTH(LENGTH) (((LENGTH) == UART_WORDLENGTH_8B) || \
 | 
			
		||||
                                     ((LENGTH) == UART_WORDLENGTH_9B))
 | 
			
		||||
#define IS_UART_LIN_WORD_LENGTH(LENGTH) (((LENGTH) == UART_WORDLENGTH_8B))
 | 
			
		||||
#define IS_UART_STOPBITS(STOPBITS) (((STOPBITS) == UART_STOPBITS_1) || \
 | 
			
		||||
                                    ((STOPBITS) == UART_STOPBITS_2))
 | 
			
		||||
#define IS_UART_PARITY(PARITY) (((PARITY) == UART_PARITY_NONE) || \
 | 
			
		||||
                                ((PARITY) == UART_PARITY_EVEN) || \
 | 
			
		||||
                                ((PARITY) == UART_PARITY_ODD))
 | 
			
		||||
#define IS_UART_HARDWARE_FLOW_CONTROL(CONTROL)\
 | 
			
		||||
                              (((CONTROL) == UART_HWCONTROL_NONE) || \
 | 
			
		||||
                               ((CONTROL) == UART_HWCONTROL_RTS) || \
 | 
			
		||||
                               ((CONTROL) == UART_HWCONTROL_CTS) || \
 | 
			
		||||
                               ((CONTROL) == UART_HWCONTROL_RTS_CTS))
 | 
			
		||||
#define IS_UART_MODE(MODE) ((((MODE) & 0x0000FFF3U) == 0x00U) && ((MODE) != 0x00U))
 | 
			
		||||
#define IS_UART_STATE(STATE) (((STATE) == UART_STATE_DISABLE) || \
 | 
			
		||||
                              ((STATE) == UART_STATE_ENABLE))
 | 
			
		||||
#if defined(USART_CR1_OVER8)
 | 
			
		||||
#define IS_UART_OVERSAMPLING(SAMPLING) (((SAMPLING) == UART_OVERSAMPLING_16) || \
 | 
			
		||||
                                        ((SAMPLING) == UART_OVERSAMPLING_8))
 | 
			
		||||
#endif /* USART_CR1_OVER8 */
 | 
			
		||||
#define IS_UART_LIN_OVERSAMPLING(SAMPLING) (((SAMPLING) == UART_OVERSAMPLING_16))
 | 
			
		||||
#define IS_UART_LIN_BREAK_DETECT_LENGTH(LENGTH) (((LENGTH) == UART_LINBREAKDETECTLENGTH_10B) || \
 | 
			
		||||
                                                 ((LENGTH) == UART_LINBREAKDETECTLENGTH_11B))
 | 
			
		||||
#define IS_UART_WAKEUPMETHOD(WAKEUP) (((WAKEUP) == UART_WAKEUPMETHOD_IDLELINE) || \
 | 
			
		||||
                                      ((WAKEUP) == UART_WAKEUPMETHOD_ADDRESSMARK))
 | 
			
		||||
#define IS_UART_BAUDRATE(BAUDRATE) ((BAUDRATE) <= 4500000U)
 | 
			
		||||
#define IS_UART_ADDRESS(ADDRESS) ((ADDRESS) <= 0x0FU)
 | 
			
		||||
 | 
			
		||||
#define UART_DIV_SAMPLING16(_PCLK_, _BAUD_)            (((_PCLK_)*25U)/(4U*(_BAUD_)))
 | 
			
		||||
#define UART_DIVMANT_SAMPLING16(_PCLK_, _BAUD_)        (UART_DIV_SAMPLING16((_PCLK_), (_BAUD_))/100U)
 | 
			
		||||
#define UART_DIVFRAQ_SAMPLING16(_PCLK_, _BAUD_)        ((((UART_DIV_SAMPLING16((_PCLK_), (_BAUD_)) - (UART_DIVMANT_SAMPLING16((_PCLK_), (_BAUD_)) * 100U)) * 16U)\
 | 
			
		||||
                                                         + 50U) / 100U)
 | 
			
		||||
/* UART BRR = mantissa + overflow + fraction
 | 
			
		||||
            = (UART DIVMANT << 4) + (UART DIVFRAQ & 0xF0) + (UART DIVFRAQ & 0x0FU) */
 | 
			
		||||
#define UART_BRR_SAMPLING16(_PCLK_, _BAUD_)            (((UART_DIVMANT_SAMPLING16((_PCLK_), (_BAUD_)) << 4U) + \
 | 
			
		||||
                                                         (UART_DIVFRAQ_SAMPLING16((_PCLK_), (_BAUD_)) & 0xF0U)) + \
 | 
			
		||||
                                                        (UART_DIVFRAQ_SAMPLING16((_PCLK_), (_BAUD_)) & 0x0FU))
 | 
			
		||||
 | 
			
		||||
#define UART_DIV_SAMPLING8(_PCLK_, _BAUD_)             (((_PCLK_)*25U)/(2U*(_BAUD_)))
 | 
			
		||||
#define UART_DIVMANT_SAMPLING8(_PCLK_, _BAUD_)         (UART_DIV_SAMPLING8((_PCLK_), (_BAUD_))/100U)
 | 
			
		||||
#define UART_DIVFRAQ_SAMPLING8(_PCLK_, _BAUD_)         ((((UART_DIV_SAMPLING8((_PCLK_), (_BAUD_)) - (UART_DIVMANT_SAMPLING8((_PCLK_), (_BAUD_)) * 100U)) * 8U)\
 | 
			
		||||
                                                         + 50U) / 100U)
 | 
			
		||||
/* UART BRR = mantissa + overflow + fraction
 | 
			
		||||
            = (UART DIVMANT << 4) + ((UART DIVFRAQ & 0xF8) << 1) + (UART DIVFRAQ & 0x07U) */
 | 
			
		||||
#define UART_BRR_SAMPLING8(_PCLK_, _BAUD_)             (((UART_DIVMANT_SAMPLING8((_PCLK_), (_BAUD_)) << 4U) + \
 | 
			
		||||
                                                         ((UART_DIVFRAQ_SAMPLING8((_PCLK_), (_BAUD_)) & 0xF8U) << 1U)) + \
 | 
			
		||||
                                                        (UART_DIVFRAQ_SAMPLING8((_PCLK_), (_BAUD_)) & 0x07U))
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/* Private functions ---------------------------------------------------------*/
 | 
			
		||||
/** @defgroup UART_Private_Functions UART Private Functions
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
HAL_StatusTypeDef UART_Start_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
 | 
			
		||||
HAL_StatusTypeDef UART_Start_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#endif /* __STM32F1xx_HAL_UART_H */
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										2569
									
								
								diode_tester/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_usart.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2569
									
								
								diode_tester/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_usart.h
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										3771
									
								
								diode_tester/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3771
									
								
								diode_tester/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										9
									
								
								diode_tester/MDK-ARM/EventRecorderStub.scvd
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								diode_tester/MDK-ARM/EventRecorderStub.scvd
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,9 @@
 | 
			
		||||
<?xml version="1.0" encoding="utf-8"?>
 | 
			
		||||
 | 
			
		||||
<component_viewer schemaVersion="0.1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="Component_Viewer.xsd">
 | 
			
		||||
 | 
			
		||||
<component name="EventRecorderStub" version="1.0.0"/>       <!--name and version of the component-->
 | 
			
		||||
  <events>
 | 
			
		||||
  </events>
 | 
			
		||||
 | 
			
		||||
</component_viewer>
 | 
			
		||||
@ -117,6 +117,26 @@
 | 
			
		||||
        <pMon>STLink\ST-LINKIII-KEIL_SWO.dll</pMon>
 | 
			
		||||
      </DebugOpt>
 | 
			
		||||
      <TargetDriverDllRegistry>
 | 
			
		||||
        <SetRegEntry>
 | 
			
		||||
          <Number>0</Number>
 | 
			
		||||
          <Key>ARMRTXEVENTFLAGS</Key>
 | 
			
		||||
          <Name>-L70 -Z18 -C0 -M0 -T1</Name>
 | 
			
		||||
        </SetRegEntry>
 | 
			
		||||
        <SetRegEntry>
 | 
			
		||||
          <Number>0</Number>
 | 
			
		||||
          <Key>DLGTARM</Key>
 | 
			
		||||
          <Name>(1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)</Name>
 | 
			
		||||
        </SetRegEntry>
 | 
			
		||||
        <SetRegEntry>
 | 
			
		||||
          <Number>0</Number>
 | 
			
		||||
          <Key>ARMDBGFLAGS</Key>
 | 
			
		||||
          <Name></Name>
 | 
			
		||||
        </SetRegEntry>
 | 
			
		||||
        <SetRegEntry>
 | 
			
		||||
          <Number>0</Number>
 | 
			
		||||
          <Key>DLGUARM</Key>
 | 
			
		||||
          <Name>(105=-1,-1,-1,-1,0)</Name>
 | 
			
		||||
        </SetRegEntry>
 | 
			
		||||
        <SetRegEntry>
 | 
			
		||||
          <Number>0</Number>
 | 
			
		||||
          <Key>UL2CM3</Key>
 | 
			
		||||
@ -125,10 +145,34 @@
 | 
			
		||||
        <SetRegEntry>
 | 
			
		||||
          <Number>0</Number>
 | 
			
		||||
          <Key>ST-LINKIII-KEIL_SWO</Key>
 | 
			
		||||
          <Name>-U-O142 -O2254 -S0 -C0 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC800 -FN1 -FF0STM32F10x_128 -FS08000000 -FL08000 -FP0($$Device:STM32F103C6$Flash\STM32F10x_128.FLM)</Name>
 | 
			
		||||
          <Name>-U53FF72064980555724221187 -O2254 -SF10000 -C0 -A0 -I0 -HNlocalhost -HP7184 -P1 -N00("ARM CoreSight SW-DP (ARM Core") -D00(1BA01477) -L00(0) -TO131090 -TC10000000 -TT10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC800 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL08000 -FP0($$Device:STM32F103C6$Flash\STM32F10x_128.FLM) -WA0 -WE0 -WVCE4 -WS2710 -WM0 -WP2</Name>
 | 
			
		||||
        </SetRegEntry>
 | 
			
		||||
      </TargetDriverDllRegistry>
 | 
			
		||||
      <Breakpoint/>
 | 
			
		||||
      <WatchWindow1>
 | 
			
		||||
        <Ww>
 | 
			
		||||
          <count>0</count>
 | 
			
		||||
          <WinNumber>1</WinNumber>
 | 
			
		||||
          <ItemText>tester_adc,0x10</ItemText>
 | 
			
		||||
        </Ww>
 | 
			
		||||
        <Ww>
 | 
			
		||||
          <count>1</count>
 | 
			
		||||
          <WinNumber>1</WinNumber>
 | 
			
		||||
          <ItemText>ADC_DMA_HalfBuff,0x0A</ItemText>
 | 
			
		||||
        </Ww>
 | 
			
		||||
      </WatchWindow1>
 | 
			
		||||
      <WatchWindow2>
 | 
			
		||||
        <Ww>
 | 
			
		||||
          <count>0</count>
 | 
			
		||||
          <WinNumber>2</WinNumber>
 | 
			
		||||
          <ItemText>before_pulse_delay</ItemText>
 | 
			
		||||
        </Ww>
 | 
			
		||||
        <Ww>
 | 
			
		||||
          <count>1</count>
 | 
			
		||||
          <WinNumber>2</WinNumber>
 | 
			
		||||
          <ItemText>pulse_delay</ItemText>
 | 
			
		||||
        </Ww>
 | 
			
		||||
      </WatchWindow2>
 | 
			
		||||
      <Tracepoint>
 | 
			
		||||
        <THDelay>0</THDelay>
 | 
			
		||||
      </Tracepoint>
 | 
			
		||||
@ -171,6 +215,24 @@
 | 
			
		||||
      <pszMrulep></pszMrulep>
 | 
			
		||||
      <pSingCmdsp></pSingCmdsp>
 | 
			
		||||
      <pMultCmdsp></pMultCmdsp>
 | 
			
		||||
      <SystemViewers>
 | 
			
		||||
        <Entry>
 | 
			
		||||
          <Name>System Viewer\ADC1</Name>
 | 
			
		||||
          <WinId>35903</WinId>
 | 
			
		||||
        </Entry>
 | 
			
		||||
        <Entry>
 | 
			
		||||
          <Name>System Viewer\DMA1</Name>
 | 
			
		||||
          <WinId>35902</WinId>
 | 
			
		||||
        </Entry>
 | 
			
		||||
        <Entry>
 | 
			
		||||
          <Name>System Viewer\GPIOA</Name>
 | 
			
		||||
          <WinId>35904</WinId>
 | 
			
		||||
        </Entry>
 | 
			
		||||
        <Entry>
 | 
			
		||||
          <Name>System Viewer\GPIOC</Name>
 | 
			
		||||
          <WinId>35905</WinId>
 | 
			
		||||
        </Entry>
 | 
			
		||||
      </SystemViewers>
 | 
			
		||||
      <DebugDescription>
 | 
			
		||||
        <Enable>1</Enable>
 | 
			
		||||
        <EnableFlashSeq>0</EnableFlashSeq>
 | 
			
		||||
@ -182,14 +244,250 @@
 | 
			
		||||
  </Target>
 | 
			
		||||
 | 
			
		||||
  <Group>
 | 
			
		||||
    <GroupName>Application/MDK-ARM</GroupName>
 | 
			
		||||
    <tvExp>0</tvExp>
 | 
			
		||||
    <GroupName>Configs</GroupName>
 | 
			
		||||
    <tvExp>1</tvExp>
 | 
			
		||||
    <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
    <cbSel>0</cbSel>
 | 
			
		||||
    <RteFlg>0</RteFlg>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>1</GroupNumber>
 | 
			
		||||
      <FileNumber>1</FileNumber>
 | 
			
		||||
      <FileType>5</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
      <bDave2>0</bDave2>
 | 
			
		||||
      <PathWithFileName>..\Core\MyLibs\mylibs_config.h</PathWithFileName>
 | 
			
		||||
      <FilenameWithoutPath>mylibs_config.h</FilenameWithoutPath>
 | 
			
		||||
      <RteFlg>0</RteFlg>
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>1</GroupNumber>
 | 
			
		||||
      <FileNumber>2</FileNumber>
 | 
			
		||||
      <FileType>5</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
      <bDave2>0</bDave2>
 | 
			
		||||
      <PathWithFileName>..\Core\Interfaces\interface_config.h</PathWithFileName>
 | 
			
		||||
      <FilenameWithoutPath>interface_config.h</FilenameWithoutPath>
 | 
			
		||||
      <RteFlg>0</RteFlg>
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>1</GroupNumber>
 | 
			
		||||
      <FileNumber>3</FileNumber>
 | 
			
		||||
      <FileType>5</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
      <bDave2>0</bDave2>
 | 
			
		||||
      <PathWithFileName>..\Core\MyLibs\mylibs_include.h</PathWithFileName>
 | 
			
		||||
      <FilenameWithoutPath>mylibs_include.h</FilenameWithoutPath>
 | 
			
		||||
      <RteFlg>0</RteFlg>
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>1</GroupNumber>
 | 
			
		||||
      <FileNumber>4</FileNumber>
 | 
			
		||||
      <FileType>5</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
      <bDave2>0</bDave2>
 | 
			
		||||
      <PathWithFileName>..\Core\Tester_main\tester_config.h</PathWithFileName>
 | 
			
		||||
      <FilenameWithoutPath>tester_config.h</FilenameWithoutPath>
 | 
			
		||||
      <RteFlg>0</RteFlg>
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
  </Group>
 | 
			
		||||
 | 
			
		||||
  <Group>
 | 
			
		||||
    <GroupName>Tester Main</GroupName>
 | 
			
		||||
    <tvExp>1</tvExp>
 | 
			
		||||
    <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
    <cbSel>0</cbSel>
 | 
			
		||||
    <RteFlg>0</RteFlg>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>2</GroupNumber>
 | 
			
		||||
      <FileNumber>5</FileNumber>
 | 
			
		||||
      <FileType>1</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
      <bDave2>0</bDave2>
 | 
			
		||||
      <PathWithFileName>..\Core\Tester_main\tester_adc_func.c</PathWithFileName>
 | 
			
		||||
      <FilenameWithoutPath>tester_adc_func.c</FilenameWithoutPath>
 | 
			
		||||
      <RteFlg>0</RteFlg>
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>2</GroupNumber>
 | 
			
		||||
      <FileNumber>6</FileNumber>
 | 
			
		||||
      <FileType>5</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
      <bDave2>0</bDave2>
 | 
			
		||||
      <PathWithFileName>..\Core\Tester_main\tester_adc_func.h</PathWithFileName>
 | 
			
		||||
      <FilenameWithoutPath>tester_adc_func.h</FilenameWithoutPath>
 | 
			
		||||
      <RteFlg>0</RteFlg>
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
  </Group>
 | 
			
		||||
 | 
			
		||||
  <Group>
 | 
			
		||||
    <GroupName>Interfaces</GroupName>
 | 
			
		||||
    <tvExp>1</tvExp>
 | 
			
		||||
    <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
    <cbSel>0</cbSel>
 | 
			
		||||
    <RteFlg>0</RteFlg>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>3</GroupNumber>
 | 
			
		||||
      <FileNumber>7</FileNumber>
 | 
			
		||||
      <FileType>1</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
      <bDave2>0</bDave2>
 | 
			
		||||
      <PathWithFileName>..\Core\Interfaces\crc_algs.c</PathWithFileName>
 | 
			
		||||
      <FilenameWithoutPath>crc_algs.c</FilenameWithoutPath>
 | 
			
		||||
      <RteFlg>0</RteFlg>
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>3</GroupNumber>
 | 
			
		||||
      <FileNumber>8</FileNumber>
 | 
			
		||||
      <FileType>5</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
      <bDave2>0</bDave2>
 | 
			
		||||
      <PathWithFileName>..\Core\Interfaces\crc_algs.h</PathWithFileName>
 | 
			
		||||
      <FilenameWithoutPath>crc_algs.h</FilenameWithoutPath>
 | 
			
		||||
      <RteFlg>0</RteFlg>
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>3</GroupNumber>
 | 
			
		||||
      <FileNumber>9</FileNumber>
 | 
			
		||||
      <FileType>1</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
      <bDave2>0</bDave2>
 | 
			
		||||
      <PathWithFileName>..\Core\Interfaces\modbus.c</PathWithFileName>
 | 
			
		||||
      <FilenameWithoutPath>modbus.c</FilenameWithoutPath>
 | 
			
		||||
      <RteFlg>0</RteFlg>
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>3</GroupNumber>
 | 
			
		||||
      <FileNumber>10</FileNumber>
 | 
			
		||||
      <FileType>5</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
      <bDave2>0</bDave2>
 | 
			
		||||
      <PathWithFileName>..\Core\Interfaces\modbus.h</PathWithFileName>
 | 
			
		||||
      <FilenameWithoutPath>modbus.h</FilenameWithoutPath>
 | 
			
		||||
      <RteFlg>0</RteFlg>
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>3</GroupNumber>
 | 
			
		||||
      <FileNumber>11</FileNumber>
 | 
			
		||||
      <FileType>5</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
      <bDave2>0</bDave2>
 | 
			
		||||
      <PathWithFileName>..\Core\Interfaces\modbus_data.h</PathWithFileName>
 | 
			
		||||
      <FilenameWithoutPath>modbus_data.h</FilenameWithoutPath>
 | 
			
		||||
      <RteFlg>0</RteFlg>
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>3</GroupNumber>
 | 
			
		||||
      <FileNumber>12</FileNumber>
 | 
			
		||||
      <FileType>1</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
      <bDave2>0</bDave2>
 | 
			
		||||
      <PathWithFileName>..\Core\Interfaces\rs_message.c</PathWithFileName>
 | 
			
		||||
      <FilenameWithoutPath>rs_message.c</FilenameWithoutPath>
 | 
			
		||||
      <RteFlg>0</RteFlg>
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>3</GroupNumber>
 | 
			
		||||
      <FileNumber>13</FileNumber>
 | 
			
		||||
      <FileType>5</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
      <bDave2>0</bDave2>
 | 
			
		||||
      <PathWithFileName>..\Core\Interfaces\rs_message.h</PathWithFileName>
 | 
			
		||||
      <FilenameWithoutPath>rs_message.h</FilenameWithoutPath>
 | 
			
		||||
      <RteFlg>0</RteFlg>
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
  </Group>
 | 
			
		||||
 | 
			
		||||
  <Group>
 | 
			
		||||
    <GroupName>MyLibs</GroupName>
 | 
			
		||||
    <tvExp>0</tvExp>
 | 
			
		||||
    <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
    <cbSel>0</cbSel>
 | 
			
		||||
    <RteFlg>0</RteFlg>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>4</GroupNumber>
 | 
			
		||||
      <FileNumber>14</FileNumber>
 | 
			
		||||
      <FileType>5</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
      <bDave2>0</bDave2>
 | 
			
		||||
      <PathWithFileName>..\Core\MyLibs\bit_access.h</PathWithFileName>
 | 
			
		||||
      <FilenameWithoutPath>bit_access.h</FilenameWithoutPath>
 | 
			
		||||
      <RteFlg>0</RteFlg>
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>4</GroupNumber>
 | 
			
		||||
      <FileNumber>15</FileNumber>
 | 
			
		||||
      <FileType>5</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
      <bDave2>0</bDave2>
 | 
			
		||||
      <PathWithFileName>..\Core\MyLibs\mylibs_defs.h</PathWithFileName>
 | 
			
		||||
      <FilenameWithoutPath>mylibs_defs.h</FilenameWithoutPath>
 | 
			
		||||
      <RteFlg>0</RteFlg>
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>4</GroupNumber>
 | 
			
		||||
      <FileNumber>16</FileNumber>
 | 
			
		||||
      <FileType>5</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
      <bDave2>0</bDave2>
 | 
			
		||||
      <PathWithFileName>..\Core\MyLibs\trace.h</PathWithFileName>
 | 
			
		||||
      <FilenameWithoutPath>trace.h</FilenameWithoutPath>
 | 
			
		||||
      <RteFlg>0</RteFlg>
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>4</GroupNumber>
 | 
			
		||||
      <FileNumber>17</FileNumber>
 | 
			
		||||
      <FileType>5</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
      <bDave2>0</bDave2>
 | 
			
		||||
      <PathWithFileName>..\Core\MyLibs\trackers.h</PathWithFileName>
 | 
			
		||||
      <FilenameWithoutPath>trackers.h</FilenameWithoutPath>
 | 
			
		||||
      <RteFlg>0</RteFlg>
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
  </Group>
 | 
			
		||||
 | 
			
		||||
  <Group>
 | 
			
		||||
    <GroupName>Application/MDK-ARM</GroupName>
 | 
			
		||||
    <tvExp>0</tvExp>
 | 
			
		||||
    <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
    <cbSel>0</cbSel>
 | 
			
		||||
    <RteFlg>0</RteFlg>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>5</GroupNumber>
 | 
			
		||||
      <FileNumber>18</FileNumber>
 | 
			
		||||
      <FileType>2</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
@ -208,8 +506,8 @@
 | 
			
		||||
    <cbSel>0</cbSel>
 | 
			
		||||
    <RteFlg>0</RteFlg>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>2</GroupNumber>
 | 
			
		||||
      <FileNumber>2</FileNumber>
 | 
			
		||||
      <GroupNumber>6</GroupNumber>
 | 
			
		||||
      <FileNumber>19</FileNumber>
 | 
			
		||||
      <FileType>1</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
@ -220,8 +518,8 @@
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>2</GroupNumber>
 | 
			
		||||
      <FileNumber>3</FileNumber>
 | 
			
		||||
      <GroupNumber>6</GroupNumber>
 | 
			
		||||
      <FileNumber>20</FileNumber>
 | 
			
		||||
      <FileType>1</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
@ -232,8 +530,8 @@
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>2</GroupNumber>
 | 
			
		||||
      <FileNumber>4</FileNumber>
 | 
			
		||||
      <GroupNumber>6</GroupNumber>
 | 
			
		||||
      <FileNumber>21</FileNumber>
 | 
			
		||||
      <FileType>1</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
@ -244,8 +542,8 @@
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>2</GroupNumber>
 | 
			
		||||
      <FileNumber>5</FileNumber>
 | 
			
		||||
      <GroupNumber>6</GroupNumber>
 | 
			
		||||
      <FileNumber>22</FileNumber>
 | 
			
		||||
      <FileType>1</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
@ -256,8 +554,8 @@
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>2</GroupNumber>
 | 
			
		||||
      <FileNumber>6</FileNumber>
 | 
			
		||||
      <GroupNumber>6</GroupNumber>
 | 
			
		||||
      <FileNumber>23</FileNumber>
 | 
			
		||||
      <FileType>1</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
@ -268,8 +566,20 @@
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>2</GroupNumber>
 | 
			
		||||
      <FileNumber>7</FileNumber>
 | 
			
		||||
      <GroupNumber>6</GroupNumber>
 | 
			
		||||
      <FileNumber>24</FileNumber>
 | 
			
		||||
      <FileType>1</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
      <bDave2>0</bDave2>
 | 
			
		||||
      <PathWithFileName>../Core/Src/usart.c</PathWithFileName>
 | 
			
		||||
      <FilenameWithoutPath>usart.c</FilenameWithoutPath>
 | 
			
		||||
      <RteFlg>0</RteFlg>
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>6</GroupNumber>
 | 
			
		||||
      <FileNumber>25</FileNumber>
 | 
			
		||||
      <FileType>1</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
@ -280,8 +590,8 @@
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>2</GroupNumber>
 | 
			
		||||
      <FileNumber>8</FileNumber>
 | 
			
		||||
      <GroupNumber>6</GroupNumber>
 | 
			
		||||
      <FileNumber>26</FileNumber>
 | 
			
		||||
      <FileType>1</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
@ -300,8 +610,8 @@
 | 
			
		||||
    <cbSel>0</cbSel>
 | 
			
		||||
    <RteFlg>0</RteFlg>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>3</GroupNumber>
 | 
			
		||||
      <FileNumber>9</FileNumber>
 | 
			
		||||
      <GroupNumber>7</GroupNumber>
 | 
			
		||||
      <FileNumber>27</FileNumber>
 | 
			
		||||
      <FileType>1</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
@ -312,8 +622,8 @@
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>3</GroupNumber>
 | 
			
		||||
      <FileNumber>10</FileNumber>
 | 
			
		||||
      <GroupNumber>7</GroupNumber>
 | 
			
		||||
      <FileNumber>28</FileNumber>
 | 
			
		||||
      <FileType>1</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
@ -324,8 +634,8 @@
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>3</GroupNumber>
 | 
			
		||||
      <FileNumber>11</FileNumber>
 | 
			
		||||
      <GroupNumber>7</GroupNumber>
 | 
			
		||||
      <FileNumber>29</FileNumber>
 | 
			
		||||
      <FileType>1</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
@ -336,8 +646,8 @@
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>3</GroupNumber>
 | 
			
		||||
      <FileNumber>12</FileNumber>
 | 
			
		||||
      <GroupNumber>7</GroupNumber>
 | 
			
		||||
      <FileNumber>30</FileNumber>
 | 
			
		||||
      <FileType>1</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
@ -348,8 +658,8 @@
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>3</GroupNumber>
 | 
			
		||||
      <FileNumber>13</FileNumber>
 | 
			
		||||
      <GroupNumber>7</GroupNumber>
 | 
			
		||||
      <FileNumber>31</FileNumber>
 | 
			
		||||
      <FileType>1</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
@ -360,8 +670,8 @@
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>3</GroupNumber>
 | 
			
		||||
      <FileNumber>14</FileNumber>
 | 
			
		||||
      <GroupNumber>7</GroupNumber>
 | 
			
		||||
      <FileNumber>32</FileNumber>
 | 
			
		||||
      <FileType>1</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
@ -372,8 +682,8 @@
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>3</GroupNumber>
 | 
			
		||||
      <FileNumber>15</FileNumber>
 | 
			
		||||
      <GroupNumber>7</GroupNumber>
 | 
			
		||||
      <FileNumber>33</FileNumber>
 | 
			
		||||
      <FileType>1</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
@ -384,8 +694,8 @@
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>3</GroupNumber>
 | 
			
		||||
      <FileNumber>16</FileNumber>
 | 
			
		||||
      <GroupNumber>7</GroupNumber>
 | 
			
		||||
      <FileNumber>34</FileNumber>
 | 
			
		||||
      <FileType>1</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
@ -396,8 +706,8 @@
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>3</GroupNumber>
 | 
			
		||||
      <FileNumber>17</FileNumber>
 | 
			
		||||
      <GroupNumber>7</GroupNumber>
 | 
			
		||||
      <FileNumber>35</FileNumber>
 | 
			
		||||
      <FileType>1</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
@ -408,8 +718,8 @@
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>3</GroupNumber>
 | 
			
		||||
      <FileNumber>18</FileNumber>
 | 
			
		||||
      <GroupNumber>7</GroupNumber>
 | 
			
		||||
      <FileNumber>36</FileNumber>
 | 
			
		||||
      <FileType>1</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
@ -420,8 +730,8 @@
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>3</GroupNumber>
 | 
			
		||||
      <FileNumber>19</FileNumber>
 | 
			
		||||
      <GroupNumber>7</GroupNumber>
 | 
			
		||||
      <FileNumber>37</FileNumber>
 | 
			
		||||
      <FileType>1</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
@ -432,8 +742,8 @@
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>3</GroupNumber>
 | 
			
		||||
      <FileNumber>20</FileNumber>
 | 
			
		||||
      <GroupNumber>7</GroupNumber>
 | 
			
		||||
      <FileNumber>38</FileNumber>
 | 
			
		||||
      <FileType>1</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
@ -444,8 +754,8 @@
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>3</GroupNumber>
 | 
			
		||||
      <FileNumber>21</FileNumber>
 | 
			
		||||
      <GroupNumber>7</GroupNumber>
 | 
			
		||||
      <FileNumber>39</FileNumber>
 | 
			
		||||
      <FileType>1</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
@ -456,8 +766,8 @@
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>3</GroupNumber>
 | 
			
		||||
      <FileNumber>22</FileNumber>
 | 
			
		||||
      <GroupNumber>7</GroupNumber>
 | 
			
		||||
      <FileNumber>40</FileNumber>
 | 
			
		||||
      <FileType>1</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
@ -468,8 +778,8 @@
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>3</GroupNumber>
 | 
			
		||||
      <FileNumber>23</FileNumber>
 | 
			
		||||
      <GroupNumber>7</GroupNumber>
 | 
			
		||||
      <FileNumber>41</FileNumber>
 | 
			
		||||
      <FileType>1</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
@ -479,6 +789,18 @@
 | 
			
		||||
      <RteFlg>0</RteFlg>
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>7</GroupNumber>
 | 
			
		||||
      <FileNumber>42</FileNumber>
 | 
			
		||||
      <FileType>1</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
      <bDave2>0</bDave2>
 | 
			
		||||
      <PathWithFileName>../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c</PathWithFileName>
 | 
			
		||||
      <FilenameWithoutPath>stm32f1xx_hal_uart.c</FilenameWithoutPath>
 | 
			
		||||
      <RteFlg>0</RteFlg>
 | 
			
		||||
      <bShared>0</bShared>
 | 
			
		||||
    </File>
 | 
			
		||||
  </Group>
 | 
			
		||||
 | 
			
		||||
  <Group>
 | 
			
		||||
@ -488,8 +810,8 @@
 | 
			
		||||
    <cbSel>0</cbSel>
 | 
			
		||||
    <RteFlg>0</RteFlg>
 | 
			
		||||
    <File>
 | 
			
		||||
      <GroupNumber>4</GroupNumber>
 | 
			
		||||
      <FileNumber>24</FileNumber>
 | 
			
		||||
      <GroupNumber>8</GroupNumber>
 | 
			
		||||
      <FileNumber>43</FileNumber>
 | 
			
		||||
      <FileType>1</FileType>
 | 
			
		||||
      <tvExp>0</tvExp>
 | 
			
		||||
      <tvExpOptDlg>0</tvExpOptDlg>
 | 
			
		||||
 | 
			
		||||
@ -82,7 +82,7 @@
 | 
			
		||||
          </BeforeMake>
 | 
			
		||||
          <AfterMake>
 | 
			
		||||
            <RunUserProg1>0</RunUserProg1>
 | 
			
		||||
            <RunUserProg2>0</RunUserProg2>
 | 
			
		||||
            <RunUserProg2>1</RunUserProg2>
 | 
			
		||||
            <UserProg1Name></UserProg1Name>
 | 
			
		||||
            <UserProg2Name></UserProg2Name>
 | 
			
		||||
            <UserProg1Dos16Mode>0</UserProg1Dos16Mode>
 | 
			
		||||
@ -341,7 +341,7 @@
 | 
			
		||||
              <MiscControls></MiscControls>
 | 
			
		||||
              <Define>USE_HAL_DRIVER,STM32F103x6</Define>
 | 
			
		||||
              <Undefine></Undefine>
 | 
			
		||||
              <IncludePath>../Core/Inc;../Drivers/STM32F1xx_HAL_Driver/Inc;../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy;../Drivers/CMSIS/Device/ST/STM32F1xx/Include;../Drivers/CMSIS/Include</IncludePath>
 | 
			
		||||
              <IncludePath>../Core/Inc;../Drivers/STM32F1xx_HAL_Driver/Inc;../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy;../Drivers/CMSIS/Device/ST/STM32F1xx/Include;../Drivers/CMSIS/Include;../Core/MyLibs;../Core/Interfaces;../Core/Tester_main</IncludePath>
 | 
			
		||||
            </VariousControls>
 | 
			
		||||
          </Cads>
 | 
			
		||||
          <Aads>
 | 
			
		||||
@ -382,6 +382,111 @@
 | 
			
		||||
        </TargetArmAds>
 | 
			
		||||
      </TargetOption>
 | 
			
		||||
      <Groups>
 | 
			
		||||
        <Group>
 | 
			
		||||
          <GroupName>Configs</GroupName>
 | 
			
		||||
          <Files>
 | 
			
		||||
            <File>
 | 
			
		||||
              <FileName>mylibs_config.h</FileName>
 | 
			
		||||
              <FileType>5</FileType>
 | 
			
		||||
              <FilePath>..\Core\MyLibs\mylibs_config.h</FilePath>
 | 
			
		||||
            </File>
 | 
			
		||||
            <File>
 | 
			
		||||
              <FileName>interface_config.h</FileName>
 | 
			
		||||
              <FileType>5</FileType>
 | 
			
		||||
              <FilePath>..\Core\Interfaces\interface_config.h</FilePath>
 | 
			
		||||
            </File>
 | 
			
		||||
            <File>
 | 
			
		||||
              <FileName>mylibs_include.h</FileName>
 | 
			
		||||
              <FileType>5</FileType>
 | 
			
		||||
              <FilePath>..\Core\MyLibs\mylibs_include.h</FilePath>
 | 
			
		||||
            </File>
 | 
			
		||||
            <File>
 | 
			
		||||
              <FileName>tester_config.h</FileName>
 | 
			
		||||
              <FileType>5</FileType>
 | 
			
		||||
              <FilePath>..\Core\Tester_main\tester_config.h</FilePath>
 | 
			
		||||
            </File>
 | 
			
		||||
          </Files>
 | 
			
		||||
        </Group>
 | 
			
		||||
        <Group>
 | 
			
		||||
          <GroupName>Tester Main</GroupName>
 | 
			
		||||
          <Files>
 | 
			
		||||
            <File>
 | 
			
		||||
              <FileName>tester_adc_func.c</FileName>
 | 
			
		||||
              <FileType>1</FileType>
 | 
			
		||||
              <FilePath>..\Core\Tester_main\tester_adc_func.c</FilePath>
 | 
			
		||||
            </File>
 | 
			
		||||
            <File>
 | 
			
		||||
              <FileName>tester_adc_func.h</FileName>
 | 
			
		||||
              <FileType>5</FileType>
 | 
			
		||||
              <FilePath>..\Core\Tester_main\tester_adc_func.h</FilePath>
 | 
			
		||||
            </File>
 | 
			
		||||
          </Files>
 | 
			
		||||
        </Group>
 | 
			
		||||
        <Group>
 | 
			
		||||
          <GroupName>Interfaces</GroupName>
 | 
			
		||||
          <Files>
 | 
			
		||||
            <File>
 | 
			
		||||
              <FileName>crc_algs.c</FileName>
 | 
			
		||||
              <FileType>1</FileType>
 | 
			
		||||
              <FilePath>..\Core\Interfaces\crc_algs.c</FilePath>
 | 
			
		||||
            </File>
 | 
			
		||||
            <File>
 | 
			
		||||
              <FileName>crc_algs.h</FileName>
 | 
			
		||||
              <FileType>5</FileType>
 | 
			
		||||
              <FilePath>..\Core\Interfaces\crc_algs.h</FilePath>
 | 
			
		||||
            </File>
 | 
			
		||||
            <File>
 | 
			
		||||
              <FileName>modbus.c</FileName>
 | 
			
		||||
              <FileType>1</FileType>
 | 
			
		||||
              <FilePath>..\Core\Interfaces\modbus.c</FilePath>
 | 
			
		||||
            </File>
 | 
			
		||||
            <File>
 | 
			
		||||
              <FileName>modbus.h</FileName>
 | 
			
		||||
              <FileType>5</FileType>
 | 
			
		||||
              <FilePath>..\Core\Interfaces\modbus.h</FilePath>
 | 
			
		||||
            </File>
 | 
			
		||||
            <File>
 | 
			
		||||
              <FileName>modbus_data.h</FileName>
 | 
			
		||||
              <FileType>5</FileType>
 | 
			
		||||
              <FilePath>..\Core\Interfaces\modbus_data.h</FilePath>
 | 
			
		||||
            </File>
 | 
			
		||||
            <File>
 | 
			
		||||
              <FileName>rs_message.c</FileName>
 | 
			
		||||
              <FileType>1</FileType>
 | 
			
		||||
              <FilePath>..\Core\Interfaces\rs_message.c</FilePath>
 | 
			
		||||
            </File>
 | 
			
		||||
            <File>
 | 
			
		||||
              <FileName>rs_message.h</FileName>
 | 
			
		||||
              <FileType>5</FileType>
 | 
			
		||||
              <FilePath>..\Core\Interfaces\rs_message.h</FilePath>
 | 
			
		||||
            </File>
 | 
			
		||||
          </Files>
 | 
			
		||||
        </Group>
 | 
			
		||||
        <Group>
 | 
			
		||||
          <GroupName>MyLibs</GroupName>
 | 
			
		||||
          <Files>
 | 
			
		||||
            <File>
 | 
			
		||||
              <FileName>bit_access.h</FileName>
 | 
			
		||||
              <FileType>5</FileType>
 | 
			
		||||
              <FilePath>..\Core\MyLibs\bit_access.h</FilePath>
 | 
			
		||||
            </File>
 | 
			
		||||
            <File>
 | 
			
		||||
              <FileName>mylibs_defs.h</FileName>
 | 
			
		||||
              <FileType>5</FileType>
 | 
			
		||||
              <FilePath>..\Core\MyLibs\mylibs_defs.h</FilePath>
 | 
			
		||||
            </File>
 | 
			
		||||
            <File>
 | 
			
		||||
              <FileName>trace.h</FileName>
 | 
			
		||||
              <FileType>5</FileType>
 | 
			
		||||
              <FilePath>..\Core\MyLibs\trace.h</FilePath>
 | 
			
		||||
            </File>
 | 
			
		||||
            <File>
 | 
			
		||||
              <FileName>trackers.h</FileName>
 | 
			
		||||
              <FileType>5</FileType>
 | 
			
		||||
              <FilePath>..\Core\MyLibs\trackers.h</FilePath>
 | 
			
		||||
            </File>
 | 
			
		||||
          </Files>
 | 
			
		||||
        </Group>
 | 
			
		||||
        <Group>
 | 
			
		||||
          <GroupName>Application/MDK-ARM</GroupName>
 | 
			
		||||
          <Files>
 | 
			
		||||
@ -522,6 +627,62 @@
 | 
			
		||||
                </FileArmAds>
 | 
			
		||||
              </FileOption>
 | 
			
		||||
            </File>
 | 
			
		||||
            <File>
 | 
			
		||||
              <FileName>usart.c</FileName>
 | 
			
		||||
              <FileType>1</FileType>
 | 
			
		||||
              <FilePath>../Core/Src/usart.c</FilePath>
 | 
			
		||||
              <FileOption>
 | 
			
		||||
                <CommonProperty>
 | 
			
		||||
                  <UseCPPCompiler>2</UseCPPCompiler>
 | 
			
		||||
                  <RVCTCodeConst>0</RVCTCodeConst>
 | 
			
		||||
                  <RVCTZI>0</RVCTZI>
 | 
			
		||||
                  <RVCTOtherData>0</RVCTOtherData>
 | 
			
		||||
                  <ModuleSelection>0</ModuleSelection>
 | 
			
		||||
                  <IncludeInBuild>1</IncludeInBuild>
 | 
			
		||||
                  <AlwaysBuild>2</AlwaysBuild>
 | 
			
		||||
                  <GenerateAssemblyFile>2</GenerateAssemblyFile>
 | 
			
		||||
                  <AssembleAssemblyFile>2</AssembleAssemblyFile>
 | 
			
		||||
                  <PublicsOnly>2</PublicsOnly>
 | 
			
		||||
                  <StopOnExitCode>11</StopOnExitCode>
 | 
			
		||||
                  <CustomArgument></CustomArgument>
 | 
			
		||||
                  <IncludeLibraryModules></IncludeLibraryModules>
 | 
			
		||||
                  <ComprImg>1</ComprImg>
 | 
			
		||||
                </CommonProperty>
 | 
			
		||||
                <FileArmAds>
 | 
			
		||||
                  <Cads>
 | 
			
		||||
                    <interw>2</interw>
 | 
			
		||||
                    <Optim>0</Optim>
 | 
			
		||||
                    <oTime>2</oTime>
 | 
			
		||||
                    <SplitLS>2</SplitLS>
 | 
			
		||||
                    <OneElfS>2</OneElfS>
 | 
			
		||||
                    <Strict>2</Strict>
 | 
			
		||||
                    <EnumInt>2</EnumInt>
 | 
			
		||||
                    <PlainCh>2</PlainCh>
 | 
			
		||||
                    <Ropi>2</Ropi>
 | 
			
		||||
                    <Rwpi>2</Rwpi>
 | 
			
		||||
                    <wLevel>0</wLevel>
 | 
			
		||||
                    <uThumb>2</uThumb>
 | 
			
		||||
                    <uSurpInc>2</uSurpInc>
 | 
			
		||||
                    <uC99>2</uC99>
 | 
			
		||||
                    <uGnu>2</uGnu>
 | 
			
		||||
                    <useXO>2</useXO>
 | 
			
		||||
                    <v6Lang>0</v6Lang>
 | 
			
		||||
                    <v6LangP>0</v6LangP>
 | 
			
		||||
                    <vShortEn>2</vShortEn>
 | 
			
		||||
                    <vShortWch>2</vShortWch>
 | 
			
		||||
                    <v6Lto>2</v6Lto>
 | 
			
		||||
                    <v6WtE>2</v6WtE>
 | 
			
		||||
                    <v6Rtti>2</v6Rtti>
 | 
			
		||||
                    <VariousControls>
 | 
			
		||||
                      <MiscControls></MiscControls>
 | 
			
		||||
                      <Define></Define>
 | 
			
		||||
                      <Undefine></Undefine>
 | 
			
		||||
                      <IncludePath></IncludePath>
 | 
			
		||||
                    </VariousControls>
 | 
			
		||||
                  </Cads>
 | 
			
		||||
                </FileArmAds>
 | 
			
		||||
              </FileOption>
 | 
			
		||||
            </File>
 | 
			
		||||
            <File>
 | 
			
		||||
              <FileName>stm32f1xx_it.c</FileName>
 | 
			
		||||
              <FileType>1</FileType>
 | 
			
		||||
@ -612,6 +773,62 @@
 | 
			
		||||
              <FileType>1</FileType>
 | 
			
		||||
              <FilePath>../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c</FilePath>
 | 
			
		||||
            </File>
 | 
			
		||||
            <File>
 | 
			
		||||
              <FileName>stm32f1xx_hal_uart.c</FileName>
 | 
			
		||||
              <FileType>1</FileType>
 | 
			
		||||
              <FilePath>../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c</FilePath>
 | 
			
		||||
              <FileOption>
 | 
			
		||||
                <CommonProperty>
 | 
			
		||||
                  <UseCPPCompiler>2</UseCPPCompiler>
 | 
			
		||||
                  <RVCTCodeConst>0</RVCTCodeConst>
 | 
			
		||||
                  <RVCTZI>0</RVCTZI>
 | 
			
		||||
                  <RVCTOtherData>0</RVCTOtherData>
 | 
			
		||||
                  <ModuleSelection>0</ModuleSelection>
 | 
			
		||||
                  <IncludeInBuild>1</IncludeInBuild>
 | 
			
		||||
                  <AlwaysBuild>2</AlwaysBuild>
 | 
			
		||||
                  <GenerateAssemblyFile>2</GenerateAssemblyFile>
 | 
			
		||||
                  <AssembleAssemblyFile>2</AssembleAssemblyFile>
 | 
			
		||||
                  <PublicsOnly>2</PublicsOnly>
 | 
			
		||||
                  <StopOnExitCode>11</StopOnExitCode>
 | 
			
		||||
                  <CustomArgument></CustomArgument>
 | 
			
		||||
                  <IncludeLibraryModules></IncludeLibraryModules>
 | 
			
		||||
                  <ComprImg>1</ComprImg>
 | 
			
		||||
                </CommonProperty>
 | 
			
		||||
                <FileArmAds>
 | 
			
		||||
                  <Cads>
 | 
			
		||||
                    <interw>2</interw>
 | 
			
		||||
                    <Optim>0</Optim>
 | 
			
		||||
                    <oTime>2</oTime>
 | 
			
		||||
                    <SplitLS>2</SplitLS>
 | 
			
		||||
                    <OneElfS>2</OneElfS>
 | 
			
		||||
                    <Strict>2</Strict>
 | 
			
		||||
                    <EnumInt>2</EnumInt>
 | 
			
		||||
                    <PlainCh>2</PlainCh>
 | 
			
		||||
                    <Ropi>2</Ropi>
 | 
			
		||||
                    <Rwpi>2</Rwpi>
 | 
			
		||||
                    <wLevel>0</wLevel>
 | 
			
		||||
                    <uThumb>2</uThumb>
 | 
			
		||||
                    <uSurpInc>2</uSurpInc>
 | 
			
		||||
                    <uC99>2</uC99>
 | 
			
		||||
                    <uGnu>2</uGnu>
 | 
			
		||||
                    <useXO>2</useXO>
 | 
			
		||||
                    <v6Lang>0</v6Lang>
 | 
			
		||||
                    <v6LangP>0</v6LangP>
 | 
			
		||||
                    <vShortEn>2</vShortEn>
 | 
			
		||||
                    <vShortWch>2</vShortWch>
 | 
			
		||||
                    <v6Lto>2</v6Lto>
 | 
			
		||||
                    <v6WtE>2</v6WtE>
 | 
			
		||||
                    <v6Rtti>2</v6Rtti>
 | 
			
		||||
                    <VariousControls>
 | 
			
		||||
                      <MiscControls></MiscControls>
 | 
			
		||||
                      <Define></Define>
 | 
			
		||||
                      <Undefine></Undefine>
 | 
			
		||||
                      <IncludePath></IncludePath>
 | 
			
		||||
                    </VariousControls>
 | 
			
		||||
                  </Cads>
 | 
			
		||||
                </FileArmAds>
 | 
			
		||||
              </FileOption>
 | 
			
		||||
            </File>
 | 
			
		||||
          </Files>
 | 
			
		||||
        </Group>
 | 
			
		||||
        <Group>
 | 
			
		||||
 | 
			
		||||
@ -1,7 +1,8 @@
 | 
			
		||||
#MicroXplorer Configuration settings - do not modify
 | 
			
		||||
ADC1.Channel-3\#ChannelRegularConversion=ADC_CHANNEL_0
 | 
			
		||||
ADC1.ExternalTrigConv=ADC_EXTERNALTRIGCONV_T3_TRGO
 | 
			
		||||
ADC1.IPParameters=Rank-3\#ChannelRegularConversion,Channel-3\#ChannelRegularConversion,SamplingTime-3\#ChannelRegularConversion,NbrOfConversionFlag,master,ExternalTrigConv
 | 
			
		||||
ADC1.ContinuousConvMode=ENABLE
 | 
			
		||||
ADC1.ExternalTrigConv=ADC_SOFTWARE_START
 | 
			
		||||
ADC1.IPParameters=Rank-3\#ChannelRegularConversion,Channel-3\#ChannelRegularConversion,SamplingTime-3\#ChannelRegularConversion,NbrOfConversionFlag,master,ExternalTrigConv,ContinuousConvMode
 | 
			
		||||
ADC1.NbrOfConversionFlag=1
 | 
			
		||||
ADC1.Rank-3\#ChannelRegularConversion=1
 | 
			
		||||
ADC1.SamplingTime-3\#ChannelRegularConversion=ADC_SAMPLETIME_1CYCLE_5
 | 
			
		||||
@ -13,7 +14,7 @@ Dma.ADC1.0.Direction=DMA_PERIPH_TO_MEMORY
 | 
			
		||||
Dma.ADC1.0.Instance=DMA1_Channel1
 | 
			
		||||
Dma.ADC1.0.MemDataAlignment=DMA_MDATAALIGN_HALFWORD
 | 
			
		||||
Dma.ADC1.0.MemInc=DMA_MINC_ENABLE
 | 
			
		||||
Dma.ADC1.0.Mode=DMA_NORMAL
 | 
			
		||||
Dma.ADC1.0.Mode=DMA_CIRCULAR
 | 
			
		||||
Dma.ADC1.0.PeriphDataAlignment=DMA_PDATAALIGN_HALFWORD
 | 
			
		||||
Dma.ADC1.0.PeriphInc=DMA_PINC_DISABLE
 | 
			
		||||
Dma.ADC1.0.Priority=DMA_PRIORITY_LOW
 | 
			
		||||
@ -30,18 +31,24 @@ Mcu.IP1=DMA
 | 
			
		||||
Mcu.IP2=NVIC
 | 
			
		||||
Mcu.IP3=RCC
 | 
			
		||||
Mcu.IP4=SYS
 | 
			
		||||
Mcu.IP5=TIM3
 | 
			
		||||
Mcu.IPNb=6
 | 
			
		||||
Mcu.IP5=TIM2
 | 
			
		||||
Mcu.IP6=TIM3
 | 
			
		||||
Mcu.IP7=USART1
 | 
			
		||||
Mcu.IPNb=8
 | 
			
		||||
Mcu.Name=STM32F103C(4-6)Tx
 | 
			
		||||
Mcu.Package=LQFP48
 | 
			
		||||
Mcu.Pin0=PD0-OSC_IN
 | 
			
		||||
Mcu.Pin1=PD1-OSC_OUT
 | 
			
		||||
Mcu.Pin2=PA0-WKUP
 | 
			
		||||
Mcu.Pin3=PA13
 | 
			
		||||
Mcu.Pin4=PA14
 | 
			
		||||
Mcu.Pin5=VP_SYS_VS_Systick
 | 
			
		||||
Mcu.Pin6=VP_TIM3_VS_ClockSourceINT
 | 
			
		||||
Mcu.PinsNb=7
 | 
			
		||||
Mcu.Pin0=PC13-TAMPER-RTC
 | 
			
		||||
Mcu.Pin1=PD0-OSC_IN
 | 
			
		||||
Mcu.Pin10=VP_TIM3_VS_ClockSourceINT
 | 
			
		||||
Mcu.Pin2=PD1-OSC_OUT
 | 
			
		||||
Mcu.Pin3=PA0-WKUP
 | 
			
		||||
Mcu.Pin4=PA9
 | 
			
		||||
Mcu.Pin5=PA10
 | 
			
		||||
Mcu.Pin6=PA13
 | 
			
		||||
Mcu.Pin7=PA14
 | 
			
		||||
Mcu.Pin8=VP_SYS_VS_Systick
 | 
			
		||||
Mcu.Pin9=VP_TIM2_VS_ClockSourceINT
 | 
			
		||||
Mcu.PinsNb=11
 | 
			
		||||
Mcu.ThirdPartyNb=0
 | 
			
		||||
Mcu.UserConstants=
 | 
			
		||||
Mcu.UserName=STM32F103C6Tx
 | 
			
		||||
@ -58,13 +65,21 @@ NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
 | 
			
		||||
NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4
 | 
			
		||||
NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
 | 
			
		||||
NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:false
 | 
			
		||||
NVIC.TIM2_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
 | 
			
		||||
NVIC.TIM3_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
 | 
			
		||||
NVIC.USART1_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
 | 
			
		||||
NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
 | 
			
		||||
PA0-WKUP.Signal=ADCx_IN0
 | 
			
		||||
PA10.Mode=Asynchronous
 | 
			
		||||
PA10.Signal=USART1_RX
 | 
			
		||||
PA13.Mode=Serial_Wire
 | 
			
		||||
PA13.Signal=SYS_JTMS-SWDIO
 | 
			
		||||
PA14.Mode=Serial_Wire
 | 
			
		||||
PA14.Signal=SYS_JTCK-SWCLK
 | 
			
		||||
PA9.Mode=Asynchronous
 | 
			
		||||
PA9.Signal=USART1_TX
 | 
			
		||||
PC13-TAMPER-RTC.Locked=true
 | 
			
		||||
PC13-TAMPER-RTC.Signal=GPIO_Output
 | 
			
		||||
PD0-OSC_IN.Mode=HSE-External-Oscillator
 | 
			
		||||
PD0-OSC_IN.Signal=RCC_OSC_IN
 | 
			
		||||
PD1-OSC_OUT.Mode=HSE-External-Oscillator
 | 
			
		||||
@ -100,7 +115,7 @@ ProjectManager.ToolChainLocation=
 | 
			
		||||
ProjectManager.UAScriptAfterPath=
 | 
			
		||||
ProjectManager.UAScriptBeforePath=
 | 
			
		||||
ProjectManager.UnderRoot=false
 | 
			
		||||
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_ADC1_Init-ADC1-false-HAL-true,5-MX_TIM3_Init-TIM3-false-HAL-true
 | 
			
		||||
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_ADC1_Init-ADC1-false-HAL-true,5-MX_TIM3_Init-TIM3-false-HAL-true,6-MX_USART1_UART_Init-USART1-false-HAL-true,7-MX_TIM2_Init-TIM2-false-HAL-true
 | 
			
		||||
RCC.ADCFreqValue=12000000
 | 
			
		||||
RCC.ADCPresc=RCC_ADCPCLK2_DIV6
 | 
			
		||||
RCC.AHBFreq_Value=72000000
 | 
			
		||||
@ -129,8 +144,12 @@ TIM3.IPParameters=Period,Prescaler,TIM_MasterOutputTrigger
 | 
			
		||||
TIM3.Period=8999
 | 
			
		||||
TIM3.Prescaler=0
 | 
			
		||||
TIM3.TIM_MasterOutputTrigger=TIM_TRGO_UPDATE
 | 
			
		||||
USART1.IPParameters=VirtualMode
 | 
			
		||||
USART1.VirtualMode=VM_ASYNC
 | 
			
		||||
VP_SYS_VS_Systick.Mode=SysTick
 | 
			
		||||
VP_SYS_VS_Systick.Signal=SYS_VS_Systick
 | 
			
		||||
VP_TIM2_VS_ClockSourceINT.Mode=Internal
 | 
			
		||||
VP_TIM2_VS_ClockSourceINT.Signal=TIM2_VS_ClockSourceINT
 | 
			
		||||
VP_TIM3_VS_ClockSourceINT.Mode=Internal
 | 
			
		||||
VP_TIM3_VS_ClockSourceINT.Signal=TIM3_VS_ClockSourceINT
 | 
			
		||||
board=custom
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user