├── .gitignore
├── Bsp
├── board.h
├── bsp.c
├── bsp.h
└── irq_callback.c
├── EWARM
├── .DS_Store
├── .gitignore
├── Project.eww
├── freemodbus_master.dep
├── freemodbus_master.ewd
├── freemodbus_master.ewp
├── freemodbus_master.ewt
├── settings
│ ├── Project.wsdt
│ ├── Project_EditorBookmarks.xml
│ ├── freemodbus_master.crun
│ ├── freemodbus_master.dbgdt
│ ├── freemodbus_master.dnx
│ ├── freemodbus_master.freemodbus_master.cspy.bat
│ ├── freemodbus_master.freemodbus_master.cspy.ps1
│ ├── freemodbus_master.freemodbus_master.driver.xcl
│ └── freemodbus_master.freemodbus_master.general.xcl
├── startup_stm32f103xb.s
├── stm32f103xb_flash.icf
└── stm32f103xb_sram.icf
├── Inc
├── gpio.h
├── main.h
├── stm32f1xx_hal_conf.h
├── stm32f1xx_it.h
├── tim.h
└── usart.h
├── MIddleware
├── .DS_Store
└── FreeModbus
│ ├── .DS_Store
│ ├── modbus
│ ├── ascii
│ │ ├── mbascii.c
│ │ └── mbascii.h
│ ├── functions
│ │ ├── mbfunccoils.c
│ │ ├── mbfunccoils_m.c
│ │ ├── mbfuncdiag.c
│ │ ├── mbfuncdisc.c
│ │ ├── mbfuncdisc_m.c
│ │ ├── mbfuncholding.c
│ │ ├── mbfuncholding_m.c
│ │ ├── mbfuncinput.c
│ │ ├── mbfuncinput_m.c
│ │ ├── mbfuncother.c
│ │ └── mbutils.c
│ ├── include
│ │ ├── mb.h
│ │ ├── mb_m.h
│ │ ├── mbconfig.h
│ │ ├── mbframe.h
│ │ ├── mbfunc.h
│ │ ├── mbport.h
│ │ ├── mbproto.h
│ │ └── mbutils.h
│ ├── mb.c
│ ├── mb_m.c
│ ├── rtu
│ │ ├── mbcrc.c
│ │ ├── mbcrc.h
│ │ ├── mbrtu.c
│ │ ├── mbrtu.h
│ │ └── mbrtu_m.c
│ └── tcp
│ │ ├── mbtcp.c
│ │ └── mbtcp.h
│ └── port
│ ├── no_os
│ ├── port.c
│ ├── portevent.c
│ ├── portevent_m.c
│ ├── portserial.c
│ ├── portserial_m.c
│ ├── porttimer.c
│ └── porttimer_m.c
│ ├── port.h
│ ├── rtt
│ ├── port.c
│ ├── portevent.c
│ ├── portevent_m.c
│ ├── portserial.c
│ ├── portserial_m.c
│ ├── porttimer.c
│ └── porttimer_m.c
│ ├── user_mb_app.c
│ ├── user_mb_app.h
│ └── user_mb_app_m.c
├── README.md
├── Src
├── gpio.c
├── main.c
├── stm32f1xx_hal_msp.c
├── stm32f1xx_it.c
├── system_stm32f1xx.c
├── tim.c
└── usart.c
└── freemodbus_master.ioc
/.gitignore:
--------------------------------------------------------------------------------
1 | /Drivers
--------------------------------------------------------------------------------
/Bsp/board.h:
--------------------------------------------------------------------------------
1 | #ifndef STEP_BOARD_H
2 | #define STEP_BOARD_H
3 |
4 | #include "stm32f1xx_hal.h"
5 |
6 |
7 | #define LED_R_PORT GPIOB
8 | #define LED_R_PIN GPIO_PIN_3
9 |
10 | #define LED_G_PORT GPIOB
11 | #define LED_G_PIN GPIO_PIN_4
12 |
13 | #define LED_B_PORT GPIOA
14 | #define LED_B_PIN GPIO_PIN_15
15 |
16 | #define M485_EN_PORT GPIOA
17 | #define M485_EN_PIN GPIO_PIN_8
18 |
19 | #ifdef STEP_TFT
20 |
21 | #define TFT_CS_PORT GPIOA
22 | #define TFT_CS_PIN GPIO_PIN_0
23 |
24 | #define TFT_RST_PORT GPIOA
25 | #define TFT_RST_PIN GPIO_PIN_1
26 |
27 | #define TFT_DC_PORT GPIOB
28 | #define TFT_DC_PIN GPIO_PIN_0
29 |
30 | #endif
31 |
32 | #ifdef STEP_TOUCH
33 |
34 |
35 | #define TOUCH_CS_PORT GPIOB
36 | #define TOUCH_CS_PIN GPIO_PIN_1
37 |
38 | #define TOUCH_BUSY_PORT GPIOB
39 | #define TOUCH_BUSY_PIN GPIO_PIN_13
40 |
41 | #define TOUCH_IRQ_PORT GPIOB
42 | #define TOUCH_IRQ_PIN GPIO_PIN_14
43 |
44 |
45 | #endif
46 |
47 |
48 |
49 |
50 |
51 |
52 | #endif
53 |
--------------------------------------------------------------------------------
/Bsp/bsp.c:
--------------------------------------------------------------------------------
1 | #include "bsp.h"
2 | #ifdef STEP_TFT
3 | #include "tft.h"
4 | #endif
5 | #ifdef STEP_TOUCH
6 | #include "touch.h"
7 | #endif
8 |
9 |
10 | uint8_t system_init=0;
11 |
12 | void bsp_init(){
13 | //close led
14 | HAL_GPIO_WritePin(LED_R_PORT, LED_R_PIN, GPIO_PIN_SET);
15 | HAL_GPIO_WritePin(LED_G_PORT, LED_G_PIN, GPIO_PIN_SET);
16 | HAL_GPIO_WritePin(LED_B_PORT, LED_B_PIN, GPIO_PIN_SET);
17 | #ifdef STEP_TFT
18 | tft_init();
19 | #endif
20 | #ifdef STEP_TOUCH
21 | touch_init();
22 | #endif
23 |
24 |
25 | system_init=1;
26 | }
27 |
--------------------------------------------------------------------------------
/Bsp/bsp.h:
--------------------------------------------------------------------------------
1 | #ifndef BSP_H
2 | #define BSP_H
3 |
4 |
5 |
6 | #include "board.h"
7 | #include "stm32f1xx_hal.h"
8 |
9 |
10 | extern uint8_t system_init;
11 |
12 | void bsp_init(void);
13 |
14 |
15 |
16 |
17 |
18 | #endif
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/Bsp/irq_callback.c:
--------------------------------------------------------------------------------
1 | #include "stm32f1xx_hal.h"
2 | #include "mbport.h"
3 | #include "mb_m.h"
4 |
5 |
6 |
7 |
8 | void HAL_SYSTICK_Callback(void){
9 | #if MB_MASTER_RTU_ENABLED > 0 || MB_MASTER_ASCII_ENABLED > 0
10 | eMBMasterPoll();
11 | #endif
12 | #if MB_SLAVE_RTU_ENABLED>0 || MB_SLAVE_ASCII_ENABLED>0
13 | eMBPoll();
14 | #endif
15 | }
16 | //void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart){
17 | //#if MB_MASTER_RTU_ENABLED > 0 || MB_MASTER_ASCII_ENABLED > 0
18 | // pxMBMasterFrameCBTransmitterEmpty();
19 | //#endif
20 | //#if MB_SLAVE_RTU_ENABLED>0 || MB_SLAVE_ASCII_ENABLED>0
21 | // pxMBFrameCBTransmitterEmpty();
22 | //#endif
23 | //
24 | //}
25 | //void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart){
26 | //
27 | //#if MB_MASTER_RTU_ENABLED > 0 || MB_MASTER_ASCII_ENABLED > 0
28 | // pxMBMasterFrameCBByteReceived();
29 | //#endif
30 | //
31 | //#if MB_SLAVE_RTU_ENABLED>0 || MB_SLAVE_ASCII_ENABLED>0
32 | // pxMBFrameCBByteReceived();
33 | //#endif
34 | //
35 | //}
36 | void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim){
37 | #if MB_MASTER_RTU_ENABLED > 0 || MB_MASTER_ASCII_ENABLED > 0
38 | (void) pxMBMasterPortCBTimerExpired();
39 | #endif
40 | #if MB_SLAVE_RTU_ENABLED>0 || MB_SLAVE_ASCII_ENABLED>0
41 | (void )pxMBPortCBTimerExpired( );
42 | #endif
43 | }
--------------------------------------------------------------------------------
/EWARM/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whyengineer/FreeModbus_Slave-Master-NOOS-STM32/fbbf7e462afed18c981176fa4e050e2a42ff6a24/EWARM/.DS_Store
--------------------------------------------------------------------------------
/EWARM/.gitignore:
--------------------------------------------------------------------------------
1 | /freemodbus_master
2 |
--------------------------------------------------------------------------------
/EWARM/Project.eww:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $WS_DIR$\freemodbus_master.ewp
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/EWARM/settings/Project_EditorBookmarks.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | C:\Users\Administrator\Desktop\bacheng\demo\freemodbus_demo\freemodbus_master\MIddleware\FreeModbus\modbus\rtu\mbrtu_m.c
5 | 331
6 |
7 |
8 |
--------------------------------------------------------------------------------
/EWARM/settings/freemodbus_master.crun:
--------------------------------------------------------------------------------
1 |
2 |
3 | 1
4 |
5 |
6 | *
7 | *
8 | *
9 | 0
10 | 1
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/EWARM/settings/freemodbus_master.dnx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 0
5 | 1
6 | 90
7 | 1
8 | 1
9 | 1
10 | main
11 | 0
12 | 50
13 |
14 |
15 | 30303031
16 |
17 | 0
18 | 3
19 | _ 0
20 | _ 0
21 |
22 |
23 | 3321314893
24 |
25 |
26 | _ 0
27 | _ 0
28 |
29 |
30 | _ 0
31 |
32 |
33 | 1
34 | 0
35 |
36 |
37 | 0
38 |
39 |
40 | 0
41 | 64000000
42 | 0
43 | 2000000
44 | 2000000
45 | 32
46 | 0
47 | 0
48 | 1
49 | 15
50 | 0
51 | 0
52 | 0
53 | 0
54 | 0
55 | $PROJ_DIR$\ITM.log
56 |
57 |
58 | USHORT[100] 4 0
59 |
60 |
61 | {W}42:eQueuedEvent 4 0
62 | {W}42:usMRegHoldBuf 4 4
63 |
64 |
65 | 0
66 | 0
67 |
68 |
69 | 0
70 | 0
71 | 0
72 | 0
73 | 0
74 | 0
75 | 0
76 | 0
77 |
78 |
79 | 0
80 | 0
81 | 1
82 | 0
83 | 1
84 |
85 |
86 | 0
87 | 0
88 | 1
89 | 0
90 | 1
91 | 0
92 |
93 |
94 | Ch3
95 | 0 0 1
96 | Ch2
97 | 0 0 1
98 | Ch1
99 | 0 0 1
100 | Ch0
101 | 0 0 1
102 | 0
103 | 0
104 | 1
105 | 0
106 | 1
107 | 0
108 |
109 |
110 | _ 0
111 | _ ""
112 | _ 0
113 |
114 |
115 | _ 0
116 | _ ""
117 |
118 |
119 | 0
120 | 3
121 | 0
122 | 0
123 |
124 |
125 |
126 | 0
127 |
128 |
129 | 1
130 |
131 |
132 | 0
133 |
134 |
135 | _ 0 "EMUL_CODE" "{$PROJ_DIR$\..\MIddleware\FreeModbus\port\no_os\port.c}.26.80" 0 0 1 "" 0 "" 0
136 | _ 0 "EMUL_CODE" "{$PROJ_DIR$\..\MIddleware\FreeModbus\modbus\rtu\mbrtu_m.c}.338.14" 0 0 1 "" 0 "" 0
137 | 2
138 |
139 |
140 | 0
141 | 0
142 |
143 |
144 |
--------------------------------------------------------------------------------
/EWARM/settings/freemodbus_master.freemodbus_master.cspy.bat:
--------------------------------------------------------------------------------
1 | @REM This batch file has been generated by the IAR Embedded Workbench
2 | @REM C-SPY Debugger, as an aid to preparing a command line for running
3 | @REM the cspybat command line utility using the appropriate settings.
4 | @REM
5 | @REM Note that this file is generated every time a new debug session
6 | @REM is initialized, so you may want to move or rename the file before
7 | @REM making changes.
8 | @REM
9 | @REM You can launch cspybat by typing the name of this batch file followed
10 | @REM by the name of the debug file (usually an ELF/DWARF or UBROF file).
11 | @REM
12 | @REM Read about available command line parameters in the C-SPY Debugging
13 | @REM Guide. Hints about additional command line parameters that may be
14 | @REM useful in specific cases:
15 | @REM --download_only Downloads a code image without starting a debug
16 | @REM session afterwards.
17 | @REM --silent Omits the sign-on message.
18 | @REM --timeout Limits the maximum allowed execution time.
19 | @REM
20 |
21 |
22 | @echo off
23 |
24 | if not "%~1" == "" goto debugFile
25 |
26 | @echo on
27 |
28 | "D:\\common\bin\cspybat" -f "C:\Users\Administrator\Desktop\bacheng\demo\freemodbus_demo\freemodbus_master\EWARM\settings\freemodbus_master.freemodbus_master.general.xcl" --backend -f "C:\Users\Administrator\Desktop\bacheng\demo\freemodbus_demo\freemodbus_master\EWARM\settings\freemodbus_master.freemodbus_master.driver.xcl"
29 |
30 | @echo off
31 | goto end
32 |
33 | :debugFile
34 |
35 | @echo on
36 |
37 | "D:\\common\bin\cspybat" -f "C:\Users\Administrator\Desktop\bacheng\demo\freemodbus_demo\freemodbus_master\EWARM\settings\freemodbus_master.freemodbus_master.general.xcl" "--debug_file=%~1" --backend -f "C:\Users\Administrator\Desktop\bacheng\demo\freemodbus_demo\freemodbus_master\EWARM\settings\freemodbus_master.freemodbus_master.driver.xcl"
38 |
39 | @echo off
40 | :end
--------------------------------------------------------------------------------
/EWARM/settings/freemodbus_master.freemodbus_master.cspy.ps1:
--------------------------------------------------------------------------------
1 | param([String]$debugfile = "");
2 |
3 | # This powershell file has been generated by the IAR Embedded Workbench
4 | # C - SPY Debugger, as an aid to preparing a command line for running
5 | # the cspybat command line utility using the appropriate settings.
6 | #
7 | # Note that this file is generated every time a new debug session
8 | # is initialized, so you may want to move or rename the file before
9 | # making changes.
10 | #
11 | # You can launch cspybat by typing Powershell.exe -File followed by the name of this batch file, followed
12 | # by the name of the debug file (usually an ELF / DWARF or UBROF file).
13 | #
14 | # Read about available command line parameters in the C - SPY Debugging
15 | # Guide. Hints about additional command line parameters that may be
16 | # useful in specific cases :
17 | # --download_only Downloads a code image without starting a debug
18 | # session afterwards.
19 | # --silent Omits the sign - on message.
20 | # --timeout Limits the maximum allowed execution time.
21 | #
22 |
23 |
24 | if ($debugfile -eq "")
25 | {
26 | & "D:\\common\bin\cspybat" -f "C:\Users\Administrator\Desktop\bacheng\demo\freemodbus_demo\freemodbus_master\EWARM\settings\freemodbus_master.freemodbus_master.general.xcl" --backend -f "C:\Users\Administrator\Desktop\bacheng\demo\freemodbus_demo\freemodbus_master\EWARM\settings\freemodbus_master.freemodbus_master.driver.xcl"
27 | }
28 | else
29 | {
30 | & "D:\\common\bin\cspybat" -f "C:\Users\Administrator\Desktop\bacheng\demo\freemodbus_demo\freemodbus_master\EWARM\settings\freemodbus_master.freemodbus_master.general.xcl" --debug_file=$debugfile --backend -f "C:\Users\Administrator\Desktop\bacheng\demo\freemodbus_demo\freemodbus_master\EWARM\settings\freemodbus_master.freemodbus_master.driver.xcl"
31 | }
32 |
--------------------------------------------------------------------------------
/EWARM/settings/freemodbus_master.freemodbus_master.driver.xcl:
--------------------------------------------------------------------------------
1 | "--endian=little"
2 |
3 | "--cpu=Cortex-M3"
4 |
5 | "--fpu=None"
6 |
7 | "-p"
8 |
9 | "D:\arm\CONFIG\debugger\ST\STM32F103C8.ddf"
10 |
11 | "--drv_verify_download"
12 |
13 | "--semihosting"
14 |
15 | "--device=STM32F103C8"
16 |
17 | "--drv_interface=SWD"
18 |
19 | "--stlink_reset_strategy=0,2"
20 |
21 | "--drv_swo_clock_setup=64000000,0,2000000"
22 |
23 | "--drv_catch_exceptions=0x000"
24 |
25 | "--drv_debug_ap=0"
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/EWARM/settings/freemodbus_master.freemodbus_master.general.xcl:
--------------------------------------------------------------------------------
1 | "D:\arm\bin\armproc.dll"
2 |
3 | "D:\arm\bin\armstlink2.dll"
4 |
5 | "C:\Users\Administrator\Desktop\bacheng\demo\freemodbus_demo\freemodbus_master\EWARM\freemodbus_master\Exe\freemodbus_master.out"
6 |
7 | --plugin "D:\arm\bin\armbat.dll"
8 |
9 | --device_macro "D:\arm\config\debugger\ST\STM32F1xx_XL.dmac"
10 |
11 | --flash_loader "D:\arm\config\flashloader\ST\FlashSTM32F10xx8.board"
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/EWARM/stm32f103xb_flash.icf:
--------------------------------------------------------------------------------
1 | /*###ICF### Section handled by ICF editor, don't touch! ****/
2 | /*-Editor annotation file-*/
3 | /* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
4 | /*-Specials-*/
5 | define symbol __ICFEDIT_intvec_start__ = 0x08000000;
6 | /*-Memory Regions-*/
7 | define symbol __ICFEDIT_region_ROM_start__ = 0x08000000 ;
8 | define symbol __ICFEDIT_region_ROM_end__ = 0x0801FFFF;
9 | define symbol __ICFEDIT_region_RAM_start__ = 0x20000000;
10 | define symbol __ICFEDIT_region_RAM_end__ = 0x20004FFF;
11 | /*-Sizes-*/
12 | define symbol __ICFEDIT_size_cstack__ = 0x400;
13 | define symbol __ICFEDIT_size_heap__ = 0x200;
14 | /**** End of ICF editor section. ###ICF###*/
15 |
16 |
17 | define memory mem with size = 4G;
18 | define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__];
19 | define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__];
20 |
21 | define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { };
22 | define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { };
23 |
24 | initialize by copy { readwrite };
25 | do not initialize { section .noinit };
26 |
27 | place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };
28 |
29 | place in ROM_region { readonly };
30 | place in RAM_region { readwrite,
31 | block CSTACK, block HEAP };
32 |
--------------------------------------------------------------------------------
/EWARM/stm32f103xb_sram.icf:
--------------------------------------------------------------------------------
1 | /*###ICF### Section handled by ICF editor, don't touch! ****/
2 | /*-Editor annotation file-*/
3 | /* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
4 | /*-Specials-*/
5 | define symbol __ICFEDIT_intvec_start__ = 0x20000000;
6 | /*-Memory Regions-*/
7 | define symbol __ICFEDIT_region_ROM_start__ = 0x20000000 ;
8 | define symbol __ICFEDIT_region_ROM_end__ = 0x200013FF;
9 | define symbol __ICFEDIT_region_RAM_start__ = 0x20001400;
10 | define symbol __ICFEDIT_region_RAM_end__ = 0x20004FFF;
11 | /*-Sizes-*/
12 | define symbol __ICFEDIT_size_cstack__ = 0x400;
13 | define symbol __ICFEDIT_size_heap__ = 0x200;
14 | /**** End of ICF editor section. ###ICF###*/
15 |
16 |
17 | define memory mem with size = 4G;
18 | define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__];
19 | define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__];
20 |
21 | define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { };
22 | define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { };
23 |
24 | initialize by copy { readwrite };
25 | do not initialize { section .noinit };
26 |
27 | place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };
28 |
29 | place in ROM_region { readonly };
30 | place in RAM_region { readwrite,
31 | block CSTACK, block HEAP };
32 |
--------------------------------------------------------------------------------
/Inc/gpio.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * File Name : gpio.h
4 | * Description : This file contains all the functions prototypes for
5 | * the gpio
6 | ******************************************************************************
7 | ** This notice applies to any and all portions of this file
8 | * that are not between comment pairs USER CODE BEGIN and
9 | * USER CODE END. Other portions of this file, whether
10 | * inserted by the user or by software development tools
11 | * are owned by their respective copyright owners.
12 | *
13 | * COPYRIGHT(c) 2018 STMicroelectronics
14 | *
15 | * Redistribution and use in source and binary forms, with or without modification,
16 | * are permitted provided that the following conditions are met:
17 | * 1. Redistributions of source code must retain the above copyright notice,
18 | * this list of conditions and the following disclaimer.
19 | * 2. Redistributions in binary form must reproduce the above copyright notice,
20 | * this list of conditions and the following disclaimer in the documentation
21 | * and/or other materials provided with the distribution.
22 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
23 | * may be used to endorse or promote products derived from this software
24 | * without specific prior written permission.
25 | *
26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
34 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | ******************************************************************************
38 | */
39 |
40 | /* Define to prevent recursive inclusion -------------------------------------*/
41 | #ifndef __gpio_H
42 | #define __gpio_H
43 | #ifdef __cplusplus
44 | extern "C" {
45 | #endif
46 |
47 | /* Includes ------------------------------------------------------------------*/
48 | #include "stm32f1xx_hal.h"
49 | #include "main.h"
50 |
51 | /* USER CODE BEGIN Includes */
52 |
53 | /* USER CODE END Includes */
54 |
55 | /* USER CODE BEGIN Private defines */
56 |
57 | /* USER CODE END Private defines */
58 |
59 | void MX_GPIO_Init(void);
60 |
61 | /* USER CODE BEGIN Prototypes */
62 |
63 | /* USER CODE END Prototypes */
64 |
65 | #ifdef __cplusplus
66 | }
67 | #endif
68 | #endif /*__ pinoutConfig_H */
69 |
70 | /**
71 | * @}
72 | */
73 |
74 | /**
75 | * @}
76 | */
77 |
78 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
79 |
--------------------------------------------------------------------------------
/Inc/main.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file : main.h
4 | * @brief : Header for main.c file.
5 | * This file contains the common defines of the application.
6 | ******************************************************************************
7 | ** This notice applies to any and all portions of this file
8 | * that are not between comment pairs USER CODE BEGIN and
9 | * USER CODE END. Other portions of this file, whether
10 | * inserted by the user or by software development tools
11 | * are owned by their respective copyright owners.
12 | *
13 | * COPYRIGHT(c) 2018 STMicroelectronics
14 | *
15 | * Redistribution and use in source and binary forms, with or without modification,
16 | * are permitted provided that the following conditions are met:
17 | * 1. Redistributions of source code must retain the above copyright notice,
18 | * this list of conditions and the following disclaimer.
19 | * 2. Redistributions in binary form must reproduce the above copyright notice,
20 | * this list of conditions and the following disclaimer in the documentation
21 | * and/or other materials provided with the distribution.
22 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
23 | * may be used to endorse or promote products derived from this software
24 | * without specific prior written permission.
25 | *
26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
34 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | ******************************************************************************
38 | */
39 |
40 | /* Define to prevent recursive inclusion -------------------------------------*/
41 | #ifndef __MAIN_H__
42 | #define __MAIN_H__
43 |
44 | /* Includes ------------------------------------------------------------------*/
45 |
46 | /* USER CODE BEGIN Includes */
47 |
48 | /* USER CODE END Includes */
49 |
50 | /* Private define ------------------------------------------------------------*/
51 |
52 | /* ########################## Assert Selection ############################## */
53 | /**
54 | * @brief Uncomment the line below to expanse the "assert_param" macro in the
55 | * HAL drivers code
56 | */
57 | /* #define USE_FULL_ASSERT 1U */
58 |
59 | /* USER CODE BEGIN Private defines */
60 |
61 | /* USER CODE END Private defines */
62 |
63 | #ifdef __cplusplus
64 | extern "C" {
65 | #endif
66 | void _Error_Handler(char *, int);
67 |
68 | #define Error_Handler() _Error_Handler(__FILE__, __LINE__)
69 | #ifdef __cplusplus
70 | }
71 | #endif
72 |
73 | #endif /* __MAIN_H__ */
74 |
75 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
76 |
--------------------------------------------------------------------------------
/Inc/stm32f1xx_it.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f1xx_it.h
4 | * @brief This file contains the headers of the interrupt handlers.
5 | ******************************************************************************
6 | *
7 | * COPYRIGHT(c) 2018 STMicroelectronics
8 | *
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | * 1. Redistributions of source code must retain the above copyright notice,
12 | * this list of conditions and the following disclaimer.
13 | * 2. Redistributions in binary form must reproduce the above copyright notice,
14 | * this list of conditions and the following disclaimer in the documentation
15 | * and/or other materials provided with the distribution.
16 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
17 | * may be used to endorse or promote products derived from this software
18 | * without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 | *
31 | ******************************************************************************
32 | */
33 |
34 | /* Define to prevent recursive inclusion -------------------------------------*/
35 | #ifndef __STM32F1xx_IT_H
36 | #define __STM32F1xx_IT_H
37 |
38 | #ifdef __cplusplus
39 | extern "C" {
40 | #endif
41 |
42 | /* Includes ------------------------------------------------------------------*/
43 | #include "stm32f1xx_hal.h"
44 | #include "main.h"
45 | /* Exported types ------------------------------------------------------------*/
46 | /* Exported constants --------------------------------------------------------*/
47 | /* Exported macro ------------------------------------------------------------*/
48 | /* Exported functions ------------------------------------------------------- */
49 |
50 | void NMI_Handler(void);
51 | void HardFault_Handler(void);
52 | void MemManage_Handler(void);
53 | void BusFault_Handler(void);
54 | void UsageFault_Handler(void);
55 | void SVC_Handler(void);
56 | void DebugMon_Handler(void);
57 | void PendSV_Handler(void);
58 | void SysTick_Handler(void);
59 | void TIM3_IRQHandler(void);
60 | void USART1_IRQHandler(void);
61 |
62 | #ifdef __cplusplus
63 | }
64 | #endif
65 |
66 | #endif /* __STM32F1xx_IT_H */
67 |
68 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
69 |
--------------------------------------------------------------------------------
/Inc/tim.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * File Name : TIM.h
4 | * Description : This file provides code for the configuration
5 | * of the TIM instances.
6 | ******************************************************************************
7 | ** This notice applies to any and all portions of this file
8 | * that are not between comment pairs USER CODE BEGIN and
9 | * USER CODE END. Other portions of this file, whether
10 | * inserted by the user or by software development tools
11 | * are owned by their respective copyright owners.
12 | *
13 | * COPYRIGHT(c) 2018 STMicroelectronics
14 | *
15 | * Redistribution and use in source and binary forms, with or without modification,
16 | * are permitted provided that the following conditions are met:
17 | * 1. Redistributions of source code must retain the above copyright notice,
18 | * this list of conditions and the following disclaimer.
19 | * 2. Redistributions in binary form must reproduce the above copyright notice,
20 | * this list of conditions and the following disclaimer in the documentation
21 | * and/or other materials provided with the distribution.
22 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
23 | * may be used to endorse or promote products derived from this software
24 | * without specific prior written permission.
25 | *
26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
34 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | ******************************************************************************
38 | */
39 | /* Define to prevent recursive inclusion -------------------------------------*/
40 | #ifndef __tim_H
41 | #define __tim_H
42 | #ifdef __cplusplus
43 | extern "C" {
44 | #endif
45 |
46 | /* Includes ------------------------------------------------------------------*/
47 | #include "stm32f1xx_hal.h"
48 | #include "main.h"
49 |
50 | /* USER CODE BEGIN Includes */
51 |
52 | /* USER CODE END Includes */
53 |
54 | extern TIM_HandleTypeDef htim3;
55 |
56 | /* USER CODE BEGIN Private defines */
57 |
58 | /* USER CODE END Private defines */
59 |
60 | extern void _Error_Handler(char *, int);
61 |
62 | void MX_TIM3_Init(void);
63 |
64 | /* USER CODE BEGIN Prototypes */
65 |
66 | /* USER CODE END Prototypes */
67 |
68 | #ifdef __cplusplus
69 | }
70 | #endif
71 | #endif /*__ tim_H */
72 |
73 | /**
74 | * @}
75 | */
76 |
77 | /**
78 | * @}
79 | */
80 |
81 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
82 |
--------------------------------------------------------------------------------
/Inc/usart.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * File Name : USART.h
4 | * Description : This file provides code for the configuration
5 | * of the USART instances.
6 | ******************************************************************************
7 | ** This notice applies to any and all portions of this file
8 | * that are not between comment pairs USER CODE BEGIN and
9 | * USER CODE END. Other portions of this file, whether
10 | * inserted by the user or by software development tools
11 | * are owned by their respective copyright owners.
12 | *
13 | * COPYRIGHT(c) 2018 STMicroelectronics
14 | *
15 | * Redistribution and use in source and binary forms, with or without modification,
16 | * are permitted provided that the following conditions are met:
17 | * 1. Redistributions of source code must retain the above copyright notice,
18 | * this list of conditions and the following disclaimer.
19 | * 2. Redistributions in binary form must reproduce the above copyright notice,
20 | * this list of conditions and the following disclaimer in the documentation
21 | * and/or other materials provided with the distribution.
22 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
23 | * may be used to endorse or promote products derived from this software
24 | * without specific prior written permission.
25 | *
26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
34 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | ******************************************************************************
38 | */
39 | /* Define to prevent recursive inclusion -------------------------------------*/
40 | #ifndef __usart_H
41 | #define __usart_H
42 | #ifdef __cplusplus
43 | extern "C" {
44 | #endif
45 |
46 | /* Includes ------------------------------------------------------------------*/
47 | #include "stm32f1xx_hal.h"
48 | #include "main.h"
49 |
50 | /* USER CODE BEGIN Includes */
51 |
52 | /* USER CODE END Includes */
53 |
54 | extern UART_HandleTypeDef huart1;
55 |
56 | /* USER CODE BEGIN Private defines */
57 |
58 | /* USER CODE END Private defines */
59 |
60 | extern void _Error_Handler(char *, int);
61 |
62 | void MX_USART1_UART_Init(void);
63 |
64 | /* USER CODE BEGIN Prototypes */
65 |
66 | /* USER CODE END Prototypes */
67 |
68 | #ifdef __cplusplus
69 | }
70 | #endif
71 | #endif /*__ usart_H */
72 |
73 | /**
74 | * @}
75 | */
76 |
77 | /**
78 | * @}
79 | */
80 |
81 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
82 |
--------------------------------------------------------------------------------
/MIddleware/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whyengineer/FreeModbus_Slave-Master-NOOS-STM32/fbbf7e462afed18c981176fa4e050e2a42ff6a24/MIddleware/.DS_Store
--------------------------------------------------------------------------------
/MIddleware/FreeModbus/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whyengineer/FreeModbus_Slave-Master-NOOS-STM32/fbbf7e462afed18c981176fa4e050e2a42ff6a24/MIddleware/FreeModbus/.DS_Store
--------------------------------------------------------------------------------
/MIddleware/FreeModbus/modbus/ascii/mbascii.h:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
3 | * Copyright (c) 2006 Christian Walter
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions
8 | * are met:
9 | * 1. Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | * 2. Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | * 3. The name of the author may not be used to endorse or promote products
15 | * derived from this software without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | *
28 | * File: $Id: mbascii.h,v 1.8 2006/12/07 22:10:34 wolti Exp $
29 | */
30 |
31 | #ifndef _MB_ASCII_H
32 | #define _MB_ASCII_H
33 |
34 | #ifdef __cplusplus
35 | PR_BEGIN_EXTERN_C
36 | #endif
37 |
38 | #if MB_SLAVE_ASCII_ENABLED > 0
39 | eMBErrorCode eMBASCIIInit( UCHAR slaveAddress, UCHAR ucPort,
40 | ULONG ulBaudRate, eMBParity eParity );
41 | void eMBASCIIStart( void );
42 | void eMBASCIIStop( void );
43 |
44 | eMBErrorCode eMBASCIIReceive( UCHAR * pucRcvAddress, UCHAR ** pucFrame,
45 | USHORT * pusLength );
46 | eMBErrorCode eMBASCIISend( UCHAR slaveAddress, const UCHAR * pucFrame,
47 | USHORT usLength );
48 | BOOL xMBASCIIReceiveFSM( void );
49 | BOOL xMBASCIITransmitFSM( void );
50 | BOOL xMBASCIITimerT1SExpired( void );
51 | #endif
52 |
53 | #ifdef __cplusplus
54 | PR_END_EXTERN_C
55 | #endif
56 | #endif
57 |
--------------------------------------------------------------------------------
/MIddleware/FreeModbus/modbus/functions/mbfuncdiag.c:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
3 | * Copyright (c) 2006 Christian Walter
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions
8 | * are met:
9 | * 1. Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | * 2. Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | * 3. The name of the author may not be used to endorse or promote products
15 | * derived from this software without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | *
28 | * File: $Id: mbfuncdiag.c,v 1.3 2006/12/07 22:10:34 wolti Exp $
29 | */
30 |
--------------------------------------------------------------------------------
/MIddleware/FreeModbus/modbus/functions/mbfuncdisc.c:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeRTOS Modbus Libary: A Modbus serial implementation for FreeRTOS
3 | * Copyright (C) 2006 Christian Walter
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | */
19 |
20 |
21 |
22 | /* ----------------------- System includes ----------------------------------*/
23 | #include "stdlib.h"
24 | #include "string.h"
25 |
26 | /* ----------------------- Platform includes --------------------------------*/
27 | #include "port.h"
28 |
29 | /* ----------------------- Modbus includes ----------------------------------*/
30 | #include "mb.h"
31 | #include "mbframe.h"
32 | #include "mbproto.h"
33 | #include "mbconfig.h"
34 |
35 | /* ----------------------- Defines ------------------------------------------*/
36 | #define MB_PDU_FUNC_READ_ADDR_OFF ( MB_PDU_DATA_OFF )
37 | #define MB_PDU_FUNC_READ_DISCCNT_OFF ( MB_PDU_DATA_OFF + 2 )
38 | #define MB_PDU_FUNC_READ_SIZE ( 4 )
39 | #define MB_PDU_FUNC_READ_DISCCNT_MAX ( 0x07D0 )
40 |
41 | /* ----------------------- Static functions ---------------------------------*/
42 | eMBException prveMBError2Exception( eMBErrorCode eErrorCode );
43 |
44 | /* ----------------------- Start implementation -----------------------------*/
45 |
46 | #if MB_FUNC_READ_COILS_ENABLED > 0
47 |
48 | eMBException
49 | eMBFuncReadDiscreteInputs( UCHAR * pucFrame, USHORT * usLen )
50 | {
51 | USHORT usRegAddress;
52 | USHORT usDiscreteCnt;
53 | UCHAR ucNBytes;
54 | UCHAR *pucFrameCur;
55 |
56 | eMBException eStatus = MB_EX_NONE;
57 | eMBErrorCode eRegStatus;
58 |
59 | if( *usLen == ( MB_PDU_FUNC_READ_SIZE + MB_PDU_SIZE_MIN ) )
60 | {
61 | usRegAddress = ( USHORT )( pucFrame[MB_PDU_FUNC_READ_ADDR_OFF] << 8 );
62 | usRegAddress |= ( USHORT )( pucFrame[MB_PDU_FUNC_READ_ADDR_OFF + 1] );
63 | usRegAddress++;
64 |
65 | usDiscreteCnt = ( USHORT )( pucFrame[MB_PDU_FUNC_READ_DISCCNT_OFF] << 8 );
66 | usDiscreteCnt |= ( USHORT )( pucFrame[MB_PDU_FUNC_READ_DISCCNT_OFF + 1] );
67 |
68 | /* Check if the number of registers to read is valid. If not
69 | * return Modbus illegal data value exception.
70 | */
71 | if( ( usDiscreteCnt >= 1 ) &&
72 | ( usDiscreteCnt < MB_PDU_FUNC_READ_DISCCNT_MAX ) )
73 | {
74 | /* Set the current PDU data pointer to the beginning. */
75 | pucFrameCur = &pucFrame[MB_PDU_FUNC_OFF];
76 | *usLen = MB_PDU_FUNC_OFF;
77 |
78 | /* First byte contains the function code. */
79 | *pucFrameCur++ = MB_FUNC_READ_DISCRETE_INPUTS;
80 | *usLen += 1;
81 |
82 | /* Test if the quantity of coils is a multiple of 8. If not last
83 | * byte is only partially field with unused coils set to zero. */
84 | if( ( usDiscreteCnt & 0x0007 ) != 0 )
85 | {
86 | ucNBytes = ( UCHAR ) ( usDiscreteCnt / 8 + 1 );
87 | }
88 | else
89 | {
90 | ucNBytes = ( UCHAR ) ( usDiscreteCnt / 8 );
91 | }
92 | *pucFrameCur++ = ucNBytes;
93 | *usLen += 1;
94 |
95 | eRegStatus =
96 | eMBRegDiscreteCB( pucFrameCur, usRegAddress, usDiscreteCnt );
97 |
98 | /* If an error occured convert it into a Modbus exception. */
99 | if( eRegStatus != MB_ENOERR )
100 | {
101 | eStatus = prveMBError2Exception( eRegStatus );
102 | }
103 | else
104 | {
105 | /* The response contains the function code, the starting address
106 | * and the quantity of registers. We reuse the old values in the
107 | * buffer because they are still valid. */
108 | *usLen += ucNBytes;;
109 | }
110 | }
111 | else
112 | {
113 | eStatus = MB_EX_ILLEGAL_DATA_VALUE;
114 | }
115 | }
116 | else
117 | {
118 | /* Can't be a valid read coil register request because the length
119 | * is incorrect. */
120 | eStatus = MB_EX_ILLEGAL_DATA_VALUE;
121 | }
122 | return eStatus;
123 | }
124 |
125 | #endif
126 |
--------------------------------------------------------------------------------
/MIddleware/FreeModbus/modbus/functions/mbfuncdisc_m.c:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
3 | * Copyright (C) 2013 Armink
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions
8 | * are met:
9 | * 1. Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | * 2. Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | * 3. The name of the author may not be used to endorse or promote products
15 | * derived from this software without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | *
28 | * File: $Id: mbfuncdisc_m.c,v 1.60 2013/10/15 8:48:20 Armink Add Master Functions Exp $
29 | */
30 |
31 |
32 |
33 | /* ----------------------- System includes ----------------------------------*/
34 | #include "stdlib.h"
35 | #include "string.h"
36 |
37 | /* ----------------------- Platform includes --------------------------------*/
38 | #include "port.h"
39 |
40 | /* ----------------------- Modbus includes ----------------------------------*/
41 | #include "mb.h"
42 | #include "mb_m.h"
43 | #include "mbframe.h"
44 | #include "mbproto.h"
45 | #include "mbconfig.h"
46 |
47 | /* ----------------------- Defines ------------------------------------------*/
48 | #define MB_PDU_REQ_READ_ADDR_OFF ( MB_PDU_DATA_OFF + 0 )
49 | #define MB_PDU_REQ_READ_DISCCNT_OFF ( MB_PDU_DATA_OFF + 2 )
50 | #define MB_PDU_REQ_READ_SIZE ( 4 )
51 | #define MB_PDU_FUNC_READ_DISCCNT_OFF ( MB_PDU_DATA_OFF + 0 )
52 | #define MB_PDU_FUNC_READ_VALUES_OFF ( MB_PDU_DATA_OFF + 1 )
53 | #define MB_PDU_FUNC_READ_SIZE_MIN ( 1 )
54 |
55 | /* ----------------------- Static functions ---------------------------------*/
56 | eMBException prveMBError2Exception( eMBErrorCode eErrorCode );
57 |
58 | /* ----------------------- Start implementation -----------------------------*/
59 | #if MB_MASTER_RTU_ENABLED > 0 || MB_MASTER_ASCII_ENABLED > 0
60 | #if MB_FUNC_READ_DISCRETE_INPUTS_ENABLED > 0
61 |
62 | /**
63 | * This function will request read discrete inputs.
64 | *
65 | * @param ucSndAddr salve address
66 | * @param usDiscreteAddr discrete start address
67 | * @param usNDiscreteIn discrete total number
68 | * @param lTimeOut timeout (-1 will waiting forever)
69 | *
70 | * @return error code
71 | */
72 | eMBMasterReqErrCode
73 | eMBMasterReqReadDiscreteInputs( UCHAR ucSndAddr, USHORT usDiscreteAddr, USHORT usNDiscreteIn, LONG lTimeOut )
74 | {
75 | UCHAR *ucMBFrame;
76 | eMBMasterReqErrCode eErrStatus = MB_MRE_NO_ERR;
77 |
78 | if ( ucSndAddr > MB_MASTER_TOTAL_SLAVE_NUM ) eErrStatus = MB_MRE_ILL_ARG;
79 | else if ( xMBMasterRunResTake( lTimeOut ) == FALSE ) eErrStatus = MB_MRE_MASTER_BUSY;
80 | else
81 | {
82 | vMBMasterGetPDUSndBuf(&ucMBFrame);
83 | vMBMasterSetDestAddress(ucSndAddr);
84 | ucMBFrame[MB_PDU_FUNC_OFF] = MB_FUNC_READ_DISCRETE_INPUTS;
85 | ucMBFrame[MB_PDU_REQ_READ_ADDR_OFF] = usDiscreteAddr >> 8;
86 | ucMBFrame[MB_PDU_REQ_READ_ADDR_OFF + 1] = usDiscreteAddr;
87 | ucMBFrame[MB_PDU_REQ_READ_DISCCNT_OFF ] = usNDiscreteIn >> 8;
88 | ucMBFrame[MB_PDU_REQ_READ_DISCCNT_OFF + 1] = usNDiscreteIn;
89 | vMBMasterSetPDUSndLength( MB_PDU_SIZE_MIN + MB_PDU_REQ_READ_SIZE );
90 | xMBMasterPortEventPost( EV_MASTER_FRAME_SENT );
91 | eErrStatus = eMBMasterWaitRequestFinish(lTimeOut);
92 | }
93 | return eErrStatus;
94 | }
95 |
96 | eMBException
97 | eMBMasterFuncReadDiscreteInputs( UCHAR * pucFrame, USHORT * usLen )
98 | {
99 | USHORT usRegAddress;
100 | USHORT usDiscreteCnt;
101 | UCHAR ucNBytes;
102 | UCHAR *ucMBFrame;
103 |
104 | eMBException eStatus = MB_EX_NONE;
105 | eMBErrorCode eRegStatus;
106 |
107 | /* If this request is broadcast, and it's read mode. This request don't need execute. */
108 | if ( xMBMasterRequestIsBroadcast() )
109 | {
110 | eStatus = MB_EX_NONE;
111 | }
112 | else if( *usLen >= MB_PDU_SIZE_MIN + MB_PDU_FUNC_READ_SIZE_MIN )
113 | {
114 | vMBMasterGetPDUSndBuf(&ucMBFrame);
115 | usRegAddress = ( USHORT )( ucMBFrame[MB_PDU_REQ_READ_ADDR_OFF] << 8 );
116 | usRegAddress |= ( USHORT )( ucMBFrame[MB_PDU_REQ_READ_ADDR_OFF + 1] );
117 | usRegAddress++;
118 |
119 | usDiscreteCnt = ( USHORT )( ucMBFrame[MB_PDU_REQ_READ_DISCCNT_OFF] << 8 );
120 | usDiscreteCnt |= ( USHORT )( ucMBFrame[MB_PDU_REQ_READ_DISCCNT_OFF + 1] );
121 |
122 | /* Test if the quantity of coils is a multiple of 8. If not last
123 | * byte is only partially field with unused coils set to zero. */
124 | if( ( usDiscreteCnt & 0x0007 ) != 0 )
125 | {
126 | ucNBytes = ( UCHAR )( usDiscreteCnt / 8 + 1 );
127 | }
128 | else
129 | {
130 | ucNBytes = ( UCHAR )( usDiscreteCnt / 8 );
131 | }
132 |
133 | /* Check if the number of registers to read is valid. If not
134 | * return Modbus illegal data value exception.
135 | */
136 | if ((usDiscreteCnt >= 1) && ucNBytes == pucFrame[MB_PDU_FUNC_READ_DISCCNT_OFF])
137 | {
138 | /* Make callback to fill the buffer. */
139 | eRegStatus = eMBMasterRegDiscreteCB( &pucFrame[MB_PDU_FUNC_READ_VALUES_OFF], usRegAddress, usDiscreteCnt );
140 |
141 | /* If an error occured convert it into a Modbus exception. */
142 | if( eRegStatus != MB_ENOERR )
143 | {
144 | eStatus = prveMBError2Exception( eRegStatus );
145 | }
146 | }
147 | else
148 | {
149 | eStatus = MB_EX_ILLEGAL_DATA_VALUE;
150 | }
151 | }
152 | else
153 | {
154 | /* Can't be a valid read coil register request because the length
155 | * is incorrect. */
156 | eStatus = MB_EX_ILLEGAL_DATA_VALUE;
157 | }
158 | return eStatus;
159 | }
160 |
161 | #endif
162 | #endif
163 |
--------------------------------------------------------------------------------
/MIddleware/FreeModbus/modbus/functions/mbfuncinput.c:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
3 | * Copyright (c) 2006 Christian Walter
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions
8 | * are met:
9 | * 1. Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | * 2. Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | * 3. The name of the author may not be used to endorse or promote products
15 | * derived from this software without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | *
28 | * File: $Id: mbfuncinput.c,v 1.10 2007/09/12 10:15:56 wolti Exp $
29 | */
30 |
31 | /* ----------------------- System includes ----------------------------------*/
32 | #include "stdlib.h"
33 | #include "string.h"
34 |
35 | /* ----------------------- Platform includes --------------------------------*/
36 | #include "port.h"
37 |
38 | /* ----------------------- Modbus includes ----------------------------------*/
39 | #include "mb.h"
40 | #include "mbframe.h"
41 | #include "mbproto.h"
42 | #include "mbconfig.h"
43 |
44 | /* ----------------------- Defines ------------------------------------------*/
45 | #define MB_PDU_FUNC_READ_ADDR_OFF ( MB_PDU_DATA_OFF )
46 | #define MB_PDU_FUNC_READ_REGCNT_OFF ( MB_PDU_DATA_OFF + 2 )
47 | #define MB_PDU_FUNC_READ_SIZE ( 4 )
48 | #define MB_PDU_FUNC_READ_REGCNT_MAX ( 0x007D )
49 |
50 | #define MB_PDU_FUNC_READ_RSP_BYTECNT_OFF ( MB_PDU_DATA_OFF )
51 |
52 | /* ----------------------- Static functions ---------------------------------*/
53 | eMBException prveMBError2Exception( eMBErrorCode eErrorCode );
54 |
55 | /* ----------------------- Start implementation -----------------------------*/
56 | #if MB_FUNC_READ_INPUT_ENABLED > 0
57 |
58 | eMBException
59 | eMBFuncReadInputRegister( UCHAR * pucFrame, USHORT * usLen )
60 | {
61 | USHORT usRegAddress;
62 | USHORT usRegCount;
63 | UCHAR *pucFrameCur;
64 |
65 | eMBException eStatus = MB_EX_NONE;
66 | eMBErrorCode eRegStatus;
67 |
68 | if( *usLen == ( MB_PDU_FUNC_READ_SIZE + MB_PDU_SIZE_MIN ) )
69 | {
70 | usRegAddress = ( USHORT )( pucFrame[MB_PDU_FUNC_READ_ADDR_OFF] << 8 );
71 | usRegAddress |= ( USHORT )( pucFrame[MB_PDU_FUNC_READ_ADDR_OFF + 1] );
72 | usRegAddress++;
73 |
74 | usRegCount = ( USHORT )( pucFrame[MB_PDU_FUNC_READ_REGCNT_OFF] << 8 );
75 | usRegCount |= ( USHORT )( pucFrame[MB_PDU_FUNC_READ_REGCNT_OFF + 1] );
76 |
77 | /* Check if the number of registers to read is valid. If not
78 | * return Modbus illegal data value exception.
79 | */
80 | if( ( usRegCount >= 1 )
81 | && ( usRegCount < MB_PDU_FUNC_READ_REGCNT_MAX ) )
82 | {
83 | /* Set the current PDU data pointer to the beginning. */
84 | pucFrameCur = &pucFrame[MB_PDU_FUNC_OFF];
85 | *usLen = MB_PDU_FUNC_OFF;
86 |
87 | /* First byte contains the function code. */
88 | *pucFrameCur++ = MB_FUNC_READ_INPUT_REGISTER;
89 | *usLen += 1;
90 |
91 | /* Second byte in the response contain the number of bytes. */
92 | *pucFrameCur++ = ( UCHAR )( usRegCount * 2 );
93 | *usLen += 1;
94 |
95 | eRegStatus =
96 | eMBRegInputCB( pucFrameCur, usRegAddress, usRegCount );
97 |
98 | /* If an error occured convert it into a Modbus exception. */
99 | if( eRegStatus != MB_ENOERR )
100 | {
101 | eStatus = prveMBError2Exception( eRegStatus );
102 | }
103 | else
104 | {
105 | *usLen += usRegCount * 2;
106 | }
107 | }
108 | else
109 | {
110 | eStatus = MB_EX_ILLEGAL_DATA_VALUE;
111 | }
112 | }
113 | else
114 | {
115 | /* Can't be a valid read input register request because the length
116 | * is incorrect. */
117 | eStatus = MB_EX_ILLEGAL_DATA_VALUE;
118 | }
119 | return eStatus;
120 | }
121 |
122 | #endif
123 |
--------------------------------------------------------------------------------
/MIddleware/FreeModbus/modbus/functions/mbfuncinput_m.c:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
3 | * Copyright (C) 2013 Armink
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions
8 | * are met:
9 | * 1. Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | * 2. Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | * 3. The name of the author may not be used to endorse or promote products
15 | * derived from this software without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | *
28 | * File: $Id: mbfuncinput_m.c,v 1.60 2013/10/12 14:23:40 Armink Add Master Functions Exp $
29 | */
30 |
31 | /* ----------------------- System includes ----------------------------------*/
32 | #include "stdlib.h"
33 | #include "string.h"
34 |
35 | /* ----------------------- Platform includes --------------------------------*/
36 | #include "port.h"
37 |
38 | /* ----------------------- Modbus includes ----------------------------------*/
39 | #include "mb.h"
40 | #include "mb_m.h"
41 | #include "mbframe.h"
42 | #include "mbproto.h"
43 | #include "mbconfig.h"
44 |
45 | /* ----------------------- Defines ------------------------------------------*/
46 | #define MB_PDU_REQ_READ_ADDR_OFF ( MB_PDU_DATA_OFF + 0 )
47 | #define MB_PDU_REQ_READ_REGCNT_OFF ( MB_PDU_DATA_OFF + 2 )
48 | #define MB_PDU_REQ_READ_SIZE ( 4 )
49 | #define MB_PDU_FUNC_READ_BYTECNT_OFF ( MB_PDU_DATA_OFF + 0 )
50 | #define MB_PDU_FUNC_READ_VALUES_OFF ( MB_PDU_DATA_OFF + 1 )
51 | #define MB_PDU_FUNC_READ_SIZE_MIN ( 1 )
52 |
53 | #define MB_PDU_FUNC_READ_RSP_BYTECNT_OFF ( MB_PDU_DATA_OFF )
54 |
55 | /* ----------------------- Static functions ---------------------------------*/
56 | eMBException prveMBError2Exception( eMBErrorCode eErrorCode );
57 |
58 | /* ----------------------- Start implementation -----------------------------*/
59 | #if MB_MASTER_RTU_ENABLED > 0 || MB_MASTER_ASCII_ENABLED > 0
60 | #if MB_FUNC_READ_INPUT_ENABLED > 0
61 |
62 | /**
63 | * This function will request read input register.
64 | *
65 | * @param ucSndAddr salve address
66 | * @param usRegAddr register start address
67 | * @param usNRegs register total number
68 | * @param lTimeOut timeout (-1 will waiting forever)
69 | *
70 | * @return error code
71 | */
72 | eMBMasterReqErrCode
73 | eMBMasterReqReadInputRegister( UCHAR ucSndAddr, USHORT usRegAddr, USHORT usNRegs, LONG lTimeOut )
74 | {
75 | UCHAR *ucMBFrame;
76 | eMBMasterReqErrCode eErrStatus = MB_MRE_NO_ERR;
77 |
78 | if ( ucSndAddr > MB_MASTER_TOTAL_SLAVE_NUM ) eErrStatus = MB_MRE_ILL_ARG;
79 | else if ( xMBMasterRunResTake( lTimeOut ) == FALSE ) eErrStatus = MB_MRE_MASTER_BUSY;
80 | else
81 | {
82 | vMBMasterGetPDUSndBuf(&ucMBFrame);
83 | vMBMasterSetDestAddress(ucSndAddr);
84 | ucMBFrame[MB_PDU_FUNC_OFF] = MB_FUNC_READ_INPUT_REGISTER;
85 | ucMBFrame[MB_PDU_REQ_READ_ADDR_OFF] = usRegAddr >> 8;
86 | ucMBFrame[MB_PDU_REQ_READ_ADDR_OFF + 1] = usRegAddr;
87 | ucMBFrame[MB_PDU_REQ_READ_REGCNT_OFF] = usNRegs >> 8;
88 | ucMBFrame[MB_PDU_REQ_READ_REGCNT_OFF + 1] = usNRegs;
89 | vMBMasterSetPDUSndLength( MB_PDU_SIZE_MIN + MB_PDU_REQ_READ_SIZE );
90 | xMBMasterPortEventPost( EV_MASTER_FRAME_SENT );
91 | eErrStatus = eMBMasterWaitRequestFinish(lTimeOut);
92 | }
93 | return eErrStatus;
94 | }
95 |
96 | eMBException
97 | eMBMasterFuncReadInputRegister( UCHAR * pucFrame, USHORT * usLen )
98 | {
99 | UCHAR *ucMBFrame;
100 | USHORT usRegAddress;
101 | USHORT usRegCount;
102 |
103 | eMBException eStatus = MB_EX_NONE;
104 | eMBErrorCode eRegStatus;
105 |
106 | /* If this request is broadcast, and it's read mode. This request don't need execute. */
107 | if ( xMBMasterRequestIsBroadcast() )
108 | {
109 | eStatus = MB_EX_NONE;
110 | }
111 | else if( *usLen >= MB_PDU_SIZE_MIN + MB_PDU_FUNC_READ_SIZE_MIN )
112 | {
113 | vMBMasterGetPDUSndBuf(&ucMBFrame);
114 | usRegAddress = ( USHORT )( ucMBFrame[MB_PDU_REQ_READ_ADDR_OFF] << 8 );
115 | usRegAddress |= ( USHORT )( ucMBFrame[MB_PDU_REQ_READ_ADDR_OFF + 1] );
116 | usRegAddress++;
117 |
118 | usRegCount = ( USHORT )( ucMBFrame[MB_PDU_REQ_READ_REGCNT_OFF] << 8 );
119 | usRegCount |= ( USHORT )( ucMBFrame[MB_PDU_REQ_READ_REGCNT_OFF + 1] );
120 |
121 | /* Check if the number of registers to read is valid. If not
122 | * return Modbus illegal data value exception.
123 | */
124 | if( ( usRegCount >= 1 ) && ( 2 * usRegCount == pucFrame[MB_PDU_FUNC_READ_BYTECNT_OFF] ) )
125 | {
126 | /* Make callback to fill the buffer. */
127 | eRegStatus = eMBMasterRegInputCB( &pucFrame[MB_PDU_FUNC_READ_VALUES_OFF], usRegAddress, usRegCount );
128 | /* If an error occured convert it into a Modbus exception. */
129 | if( eRegStatus != MB_ENOERR )
130 | {
131 | eStatus = prveMBError2Exception( eRegStatus );
132 | }
133 | }
134 | else
135 | {
136 | eStatus = MB_EX_ILLEGAL_DATA_VALUE;
137 | }
138 | }
139 | else
140 | {
141 | /* Can't be a valid request because the length is incorrect. */
142 | eStatus = MB_EX_ILLEGAL_DATA_VALUE;
143 | }
144 | return eStatus;
145 | }
146 |
147 | #endif
148 | #endif
149 |
--------------------------------------------------------------------------------
/MIddleware/FreeModbus/modbus/functions/mbfuncother.c:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
3 | * Copyright (c) 2006 Christian Walter
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions
8 | * are met:
9 | * 1. Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | * 2. Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | * 3. The name of the author may not be used to endorse or promote products
15 | * derived from this software without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | *
28 | * File: $Id: mbfuncother.c,v 1.8 2006/12/07 22:10:34 wolti Exp $
29 | */
30 |
31 | /* ----------------------- System includes ----------------------------------*/
32 | #include "stdlib.h"
33 | #include "string.h"
34 |
35 | /* ----------------------- Platform includes --------------------------------*/
36 | #include "port.h"
37 |
38 | /* ----------------------- Modbus includes ----------------------------------*/
39 | #include "mb.h"
40 | #include "mbframe.h"
41 | #include "mbproto.h"
42 | #include "mbconfig.h"
43 |
44 | #if MB_FUNC_OTHER_REP_SLAVEID_ENABLED > 0
45 |
46 | /* ----------------------- Static variables ---------------------------------*/
47 | static UCHAR ucMBSlaveID[MB_FUNC_OTHER_REP_SLAVEID_BUF];
48 | static USHORT usMBSlaveIDLen;
49 |
50 | /* ----------------------- Start implementation -----------------------------*/
51 |
52 | eMBErrorCode
53 | eMBSetSlaveID( UCHAR ucSlaveID, BOOL xIsRunning,
54 | UCHAR const *pucAdditional, USHORT usAdditionalLen )
55 | {
56 | eMBErrorCode eStatus = MB_ENOERR;
57 |
58 | /* the first byte and second byte in the buffer is reserved for
59 | * the parameter ucSlaveID and the running flag. The rest of
60 | * the buffer is available for additional data. */
61 | if( usAdditionalLen + 2 < MB_FUNC_OTHER_REP_SLAVEID_BUF )
62 | {
63 | usMBSlaveIDLen = 0;
64 | ucMBSlaveID[usMBSlaveIDLen++] = ucSlaveID;
65 | ucMBSlaveID[usMBSlaveIDLen++] = ( UCHAR )( xIsRunning ? 0xFF : 0x00 );
66 | if( usAdditionalLen > 0 )
67 | {
68 | memcpy( &ucMBSlaveID[usMBSlaveIDLen], pucAdditional,
69 | ( size_t )usAdditionalLen );
70 | usMBSlaveIDLen += usAdditionalLen;
71 | }
72 | }
73 | else
74 | {
75 | eStatus = MB_ENORES;
76 | }
77 | return eStatus;
78 | }
79 |
80 | eMBException
81 | eMBFuncReportSlaveID( UCHAR * pucFrame, USHORT * usLen )
82 | {
83 | memcpy( &pucFrame[MB_PDU_DATA_OFF], &ucMBSlaveID[0], ( size_t )usMBSlaveIDLen );
84 | *usLen = ( USHORT )( MB_PDU_DATA_OFF + usMBSlaveIDLen );
85 | return MB_EX_NONE;
86 | }
87 |
88 | #endif
89 |
--------------------------------------------------------------------------------
/MIddleware/FreeModbus/modbus/functions/mbutils.c:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
3 | * Copyright (c) 2006 Christian Walter
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions
8 | * are met:
9 | * 1. Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | * 2. Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | * 3. The name of the author may not be used to endorse or promote products
15 | * derived from this software without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | *
28 | * File: $Id: mbutils.c,v 1.6 2007/02/18 23:49:07 wolti Exp $
29 | */
30 |
31 | /* ----------------------- System includes ----------------------------------*/
32 | #include "stdlib.h"
33 | #include "string.h"
34 |
35 | /* ----------------------- Platform includes --------------------------------*/
36 | #include "port.h"
37 |
38 | /* ----------------------- Modbus includes ----------------------------------*/
39 | #include "mb.h"
40 | #include "mbproto.h"
41 |
42 | /* ----------------------- Defines ------------------------------------------*/
43 | #define BITS_UCHAR 8U
44 |
45 | /* ----------------------- Start implementation -----------------------------*/
46 | void
47 | xMBUtilSetBits( UCHAR * ucByteBuf, USHORT usBitOffset, UCHAR ucNBits,
48 | UCHAR ucValue )
49 | {
50 | USHORT usWordBuf;
51 | USHORT usMask;
52 | USHORT usByteOffset;
53 | USHORT usNPreBits;
54 | USHORT usValue = ucValue;
55 |
56 | assert_param( ucNBits <= 8 );
57 | assert_param( ( size_t )BITS_UCHAR == sizeof( UCHAR ) * 8 );
58 |
59 | /* Calculate byte offset for first byte containing the bit values starting
60 | * at usBitOffset. */
61 | usByteOffset = ( USHORT )( ( usBitOffset ) / BITS_UCHAR );
62 |
63 | /* How many bits precede our bits to set. */
64 | usNPreBits = ( USHORT )( usBitOffset - usByteOffset * BITS_UCHAR );
65 |
66 | /* Move bit field into position over bits to set */
67 | usValue <<= usNPreBits;
68 |
69 | /* Prepare a mask for setting the new bits. */
70 | usMask = ( USHORT )( ( 1 << ( USHORT ) ucNBits ) - 1 );
71 | usMask <<= usBitOffset - usByteOffset * BITS_UCHAR;
72 |
73 | /* copy bits into temporary storage. */
74 | usWordBuf = ucByteBuf[usByteOffset];
75 | usWordBuf |= ucByteBuf[usByteOffset + 1] << BITS_UCHAR;
76 |
77 | /* Zero out bit field bits and then or value bits into them. */
78 | usWordBuf = ( USHORT )( ( usWordBuf & ( ~usMask ) ) | usValue );
79 |
80 | /* move bits back into storage */
81 | ucByteBuf[usByteOffset] = ( UCHAR )( usWordBuf & 0xFF );
82 | ucByteBuf[usByteOffset + 1] = ( UCHAR )( usWordBuf >> BITS_UCHAR );
83 | }
84 |
85 | UCHAR
86 | xMBUtilGetBits( UCHAR * ucByteBuf, USHORT usBitOffset, UCHAR ucNBits )
87 | {
88 | USHORT usWordBuf;
89 | USHORT usMask;
90 | USHORT usByteOffset;
91 | USHORT usNPreBits;
92 |
93 | /* Calculate byte offset for first byte containing the bit values starting
94 | * at usBitOffset. */
95 | usByteOffset = ( USHORT )( ( usBitOffset ) / BITS_UCHAR );
96 |
97 | /* How many bits precede our bits to set. */
98 | usNPreBits = ( USHORT )( usBitOffset - usByteOffset * BITS_UCHAR );
99 |
100 | /* Prepare a mask for setting the new bits. */
101 | usMask = ( USHORT )( ( 1 << ( USHORT ) ucNBits ) - 1 );
102 |
103 | /* copy bits into temporary storage. */
104 | usWordBuf = ucByteBuf[usByteOffset];
105 | usWordBuf |= ucByteBuf[usByteOffset + 1] << BITS_UCHAR;
106 |
107 | /* throw away unneeded bits. */
108 | usWordBuf >>= usNPreBits;
109 |
110 | /* mask away bits above the requested bitfield. */
111 | usWordBuf &= usMask;
112 |
113 | return ( UCHAR ) usWordBuf;
114 | }
115 |
116 | eMBException
117 | prveMBError2Exception( eMBErrorCode eErrorCode )
118 | {
119 | eMBException eStatus;
120 |
121 | switch ( eErrorCode )
122 | {
123 | case MB_ENOERR:
124 | eStatus = MB_EX_NONE;
125 | break;
126 |
127 | case MB_ENOREG:
128 | eStatus = MB_EX_ILLEGAL_DATA_ADDRESS;
129 | break;
130 |
131 | case MB_ETIMEDOUT:
132 | eStatus = MB_EX_SLAVE_BUSY;
133 | break;
134 |
135 | default:
136 | eStatus = MB_EX_SLAVE_DEVICE_FAILURE;
137 | break;
138 | }
139 |
140 | return eStatus;
141 | }
142 |
--------------------------------------------------------------------------------
/MIddleware/FreeModbus/modbus/include/mb_m.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whyengineer/FreeModbus_Slave-Master-NOOS-STM32/fbbf7e462afed18c981176fa4e050e2a42ff6a24/MIddleware/FreeModbus/modbus/include/mb_m.h
--------------------------------------------------------------------------------
/MIddleware/FreeModbus/modbus/include/mbconfig.h:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
3 | * Copyright (c) 2006 Christian Walter
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions
8 | * are met:
9 | * 1. Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | * 2. Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | * 3. The name of the author may not be used to endorse or promote products
15 | * derived from this software without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | *
28 | * File: $Id: mbconfig.h,v 1.14 2006/12/07 22:10:34 wolti Exp $
29 | * $Id: mbconfig.h,v 1.60 2013/08/13 21:19:55 Armink Add Master Functions $
30 | */
31 |
32 | #ifndef _MB_CONFIG_H
33 | #define _MB_CONFIG_H
34 |
35 | #ifdef __cplusplus
36 | PR_BEGIN_EXTERN_C
37 | #endif
38 | /* ----------------------- Defines ------------------------------------------*/
39 | /*! \defgroup modbus_cfg Modbus Configuration
40 | *
41 | * Most modules in the protocol stack are completly optional and can be
42 | * excluded. This is specially important if target resources are very small
43 | * and program memory space should be saved.
44 | *
45 | * All of these settings are available in the file mbconfig.h
46 | */
47 | /*! \addtogroup modbus_cfg
48 | * @{
49 | */
50 | /*! \brief If Modbus Master ASCII support is enabled. */
51 | #define MB_MASTER_ASCII_ENABLED ( 0 )
52 | /*! \brief If Modbus Master RTU support is enabled. */
53 | #define MB_MASTER_RTU_ENABLED ( 1 )
54 | /*! \brief If Modbus Master TCP support is enabled. */
55 | #define MB_MASTER_TCP_ENABLED ( 0 )
56 | /*! \brief If Modbus Slave ASCII support is enabled. */
57 | #define MB_SLAVE_ASCII_ENABLED ( 0 )
58 | /*! \brief If Modbus Slave RTU support is enabled. */
59 | #define MB_SLAVE_RTU_ENABLED ( 0 )
60 | /*! \brief If Modbus Slave TCP support is enabled. */
61 | #define MB_SLAVE_TCP_ENABLED ( 0 )
62 | /*! \brief The character timeout value for Modbus ASCII.
63 | *
64 | * The character timeout value is not fixed for Modbus ASCII and is therefore
65 | * a configuration option. It should be set to the maximum expected delay
66 | * time of the network.
67 | */
68 | #define MB_ASCII_TIMEOUT_SEC ( 1 )
69 | /*! \brief Maximum number of Modbus functions codes the protocol stack
70 | * should support.
71 | *
72 | * The maximum number of supported Modbus functions must be greater than
73 | * the sum of all enabled functions in this file and custom function
74 | * handlers. If set to small adding more functions will fail.
75 | */
76 | #define MB_FUNC_HANDLERS_MAX ( 16 )
77 | /*! \brief Number of bytes which should be allocated for the Report Slave ID
78 | * command.
79 | *
80 | * This number limits the maximum size of the additional segment in the
81 | * report slave id function. See eMBSetSlaveID( ) for more information on
82 | * how to set this value. It is only used if MB_FUNC_OTHER_REP_SLAVEID_ENABLED
83 | * is set to 1
.
84 | */
85 | #define MB_FUNC_OTHER_REP_SLAVEID_BUF ( 32 )
86 | /*! \brief If the Report Slave ID function should be enabled. */
87 | #define MB_FUNC_OTHER_REP_SLAVEID_ENABLED ( 1 )
88 | /*! \brief If the Read Input Registers function should be enabled. */
89 | #define MB_FUNC_READ_INPUT_ENABLED ( 1 )
90 | /*! \brief If the Read Holding Registers function should be enabled. */
91 | #define MB_FUNC_READ_HOLDING_ENABLED ( 1 )
92 | /*! \brief If the Write Single Register function should be enabled. */
93 | #define MB_FUNC_WRITE_HOLDING_ENABLED ( 1 )
94 | /*! \brief If the Write Multiple registers function should be enabled. */
95 | #define MB_FUNC_WRITE_MULTIPLE_HOLDING_ENABLED ( 1 )
96 | /*! \brief If the Read Coils function should be enabled. */
97 | #define MB_FUNC_READ_COILS_ENABLED ( 1 )
98 | /*! \brief If the Write Coils function should be enabled. */
99 | #define MB_FUNC_WRITE_COIL_ENABLED ( 1 )
100 | /*! \brief If the Write Multiple Coils function should be enabled. */
101 | #define MB_FUNC_WRITE_MULTIPLE_COILS_ENABLED ( 1 )
102 | /*! \brief If the Read Discrete Inputs function should be enabled. */
103 | #define MB_FUNC_READ_DISCRETE_INPUTS_ENABLED ( 1 )
104 | /*! \brief If the Read/Write Multiple Registers function should be enabled. */
105 | #define MB_FUNC_READWRITE_HOLDING_ENABLED ( 1 )
106 | /*! @} */
107 | #ifdef __cplusplus
108 | PR_END_EXTERN_C
109 | #endif
110 |
111 | #if MB_MASTER_RTU_ENABLED > 0 || MB_MASTER_ASCII_ENABLED > 0
112 | /*! \brief If master send a broadcast frame,the master will wait time of convert to delay,
113 | * then master can send other frame */
114 | #define MB_MASTER_DELAY_MS_CONVERT (200 )
115 | /*! \brief If master send a frame which is not broadcast,the master will wait sometime for slave.
116 | * And if slave is not respond in this time,the master will process this timeout error.
117 | * Then master can send other frame */
118 | #define MB_MASTER_TIMEOUT_MS_RESPOND (100 )
119 | /*! \brief The total slaves in Modbus Master system. Default 16.
120 | * \note : The slave ID must be continuous from 1.*/
121 | #define MB_MASTER_TOTAL_SLAVE_NUM ( 16 )
122 | #endif
123 |
124 | #endif
125 |
--------------------------------------------------------------------------------
/MIddleware/FreeModbus/modbus/include/mbframe.h:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
3 | * Copyright (c) 2006 Christian Walter
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions
8 | * are met:
9 | * 1. Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | * 2. Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | * 3. The name of the author may not be used to endorse or promote products
15 | * derived from this software without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | *
28 | * File: $Id: mbframe.h,v 1.9 2006/12/07 22:10:34 wolti Exp $
29 | */
30 |
31 | #ifndef _MB_FRAME_H
32 | #define _MB_FRAME_H
33 |
34 | #ifdef __cplusplus
35 | PR_BEGIN_EXTERN_C
36 | #endif
37 |
38 | /*!
39 | * Constants which defines the format of a modbus frame. The example is
40 | * shown for a Modbus RTU/ASCII frame. Note that the Modbus PDU is not
41 | * dependent on the underlying transport.
42 | *
43 | *
44 | * <------------------------ MODBUS SERIAL LINE PDU (1) ------------------->
45 | * <----------- MODBUS PDU (1') ---------------->
46 | * +-----------+---------------+----------------------------+-------------+
47 | * | Address | Function Code | Data | CRC/LRC |
48 | * +-----------+---------------+----------------------------+-------------+
49 | * | | | |
50 | * (2) (3/2') (3') (4)
51 | *
52 | * (1) ... MB_SER_PDU_SIZE_MAX = 256
53 | * (2) ... MB_SER_PDU_ADDR_OFF = 0
54 | * (3) ... MB_SER_PDU_PDU_OFF = 1
55 | * (4) ... MB_SER_PDU_SIZE_CRC = 2
56 | *
57 | * (1') ... MB_PDU_SIZE_MAX = 253
58 | * (2') ... MB_PDU_FUNC_OFF = 0
59 | * (3') ... MB_PDU_DATA_OFF = 1
60 | *
61 | */
62 |
63 | /* ----------------------- Defines ------------------------------------------*/
64 | #define MB_PDU_SIZE_MAX 253 /*!< Maximum size of a PDU. */
65 | #define MB_PDU_SIZE_MIN 1 /*!< Function Code */
66 | #define MB_PDU_FUNC_OFF 0 /*!< Offset of function code in PDU. */
67 | #define MB_PDU_DATA_OFF 1 /*!< Offset for response data in PDU. */
68 |
69 | /* ----------------------- Prototypes 0-------------------------------------*/
70 | typedef void ( *pvMBFrameStart ) ( void );
71 |
72 | typedef void ( *pvMBFrameStop ) ( void );
73 |
74 | typedef eMBErrorCode( *peMBFrameReceive ) ( UCHAR * pucRcvAddress,
75 | UCHAR ** pucFrame,
76 | USHORT * pusLength );
77 |
78 | typedef eMBErrorCode( *peMBFrameSend ) ( UCHAR slaveAddress,
79 | const UCHAR * pucFrame,
80 | USHORT usLength );
81 |
82 | typedef void( *pvMBFrameClose ) ( void );
83 |
84 | #ifdef __cplusplus
85 | PR_END_EXTERN_C
86 | #endif
87 | #endif
88 |
--------------------------------------------------------------------------------
/MIddleware/FreeModbus/modbus/include/mbfunc.h:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
3 | * Copyright (c) 2006 Christian Walter
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions
8 | * are met:
9 | * 1. Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | * 2. Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | * 3. The name of the author may not be used to endorse or promote products
15 | * derived from this software without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | *
28 | * File: $Id: mbfunc.h,v 1.12 2006/12/07 22:10:34 wolti Exp $
29 | */
30 |
31 | #ifndef _MB_FUNC_H
32 | #define _MB_FUNC_H
33 |
34 | #ifdef __cplusplus
35 | PR_BEGIN_EXTERN_C
36 | #endif
37 | #if MB_FUNC_OTHER_REP_SLAVEID_BUF > 0
38 | eMBException eMBFuncReportSlaveID( UCHAR * pucFrame, USHORT * usLen );
39 | #endif
40 |
41 | #if MB_FUNC_READ_INPUT_ENABLED > 0
42 | eMBException eMBFuncReadInputRegister( UCHAR * pucFrame, USHORT * usLen );
43 | #endif
44 |
45 | #if MB_FUNC_READ_HOLDING_ENABLED > 0
46 | eMBException eMBFuncReadHoldingRegister( UCHAR * pucFrame, USHORT * usLen );
47 | #endif
48 |
49 | #if MB_FUNC_WRITE_HOLDING_ENABLED > 0
50 | eMBException eMBFuncWriteHoldingRegister( UCHAR * pucFrame, USHORT * usLen );
51 | #endif
52 |
53 | #if MB_FUNC_WRITE_MULTIPLE_HOLDING_ENABLED > 0
54 | eMBException eMBFuncWriteMultipleHoldingRegister( UCHAR * pucFrame, USHORT * usLen );
55 | #endif
56 |
57 | #if MB_FUNC_READ_COILS_ENABLED > 0
58 | eMBException eMBFuncReadCoils( UCHAR * pucFrame, USHORT * usLen );
59 | #endif
60 |
61 | #if MB_FUNC_WRITE_COIL_ENABLED > 0
62 | eMBException eMBFuncWriteCoil( UCHAR * pucFrame, USHORT * usLen );
63 | #endif
64 |
65 | #if MB_FUNC_WRITE_MULTIPLE_COILS_ENABLED > 0
66 | eMBException eMBFuncWriteMultipleCoils( UCHAR * pucFrame, USHORT * usLen );
67 | #endif
68 |
69 | #if MB_FUNC_READ_DISCRETE_INPUTS_ENABLED > 0
70 | eMBException eMBFuncReadDiscreteInputs( UCHAR * pucFrame, USHORT * usLen );
71 | #endif
72 |
73 | #if MB_FUNC_READWRITE_HOLDING_ENABLED > 0
74 | eMBException eMBFuncReadWriteMultipleHoldingRegister( UCHAR * pucFrame, USHORT * usLen );
75 | #endif
76 |
77 | #ifdef __cplusplus
78 | PR_END_EXTERN_C
79 | #endif
80 | #endif
81 |
--------------------------------------------------------------------------------
/MIddleware/FreeModbus/modbus/include/mbport.h:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
3 | * Copyright (c) 2006 Christian Walter
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions
8 | * are met:
9 | * 1. Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | * 2. Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | * 3. The name of the author may not be used to endorse or promote products
15 | * derived from this software without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | *
28 | * File: $Id: mbport.h,v 1.17 2006/12/07 22:10:34 wolti Exp $
29 | * mbport.h,v 1.60 2013/08/17 11:42:56 Armink Add Master Functions $
30 | */
31 |
32 | #ifndef _MB_PORT_H
33 | #define _MB_PORT_H
34 |
35 | #ifdef __cplusplus
36 | PR_BEGIN_EXTERN_C
37 | #endif
38 |
39 | #include "port.h"
40 | /* ----------------------- Defines ------------------------------------------*/
41 |
42 | /* ----------------------- Type definitions ---------------------------------*/
43 |
44 | typedef enum
45 | {
46 | EV_READY = 1<<0, /*!< Startup finished. */
47 | EV_FRAME_RECEIVED = 1<<1, /*!< Frame received. */
48 | EV_EXECUTE = 1<<2, /*!< Execute function. */
49 | EV_FRAME_SENT = 1<<3 /*!< Frame sent. */
50 | } eMBEventType;
51 |
52 | typedef enum
53 | {
54 | EV_MASTER_READY = 1<<0, /*!< Startup finished. */
55 | EV_MASTER_FRAME_RECEIVED = 1<<1, /*!< Frame received. */
56 | EV_MASTER_EXECUTE = 1<<2, /*!< Execute function. */
57 | EV_MASTER_FRAME_SENT = 1<<3, /*!< Frame sent. */
58 | EV_MASTER_ERROR_PROCESS = 1<<4, /*!< Frame error process. */
59 | EV_MASTER_PROCESS_SUCESS = 1<<5, /*!< Request process success. */
60 | EV_MASTER_ERROR_RESPOND_TIMEOUT = 1<<6, /*!< Request respond timeout. */
61 | EV_MASTER_ERROR_RECEIVE_DATA = 1<<7, /*!< Request receive data error. */
62 | EV_MASTER_ERROR_EXECUTE_FUNCTION = 1<<8, /*!< Request execute function error. */
63 | } eMBMasterEventType;
64 |
65 | typedef enum
66 | {
67 | EV_ERROR_RESPOND_TIMEOUT, /*!< Slave respond timeout. */
68 | EV_ERROR_RECEIVE_DATA, /*!< Receive frame data erroe. */
69 | EV_ERROR_EXECUTE_FUNCTION, /*!< Execute function error. */
70 | } eMBMasterErrorEventType;
71 |
72 | /*! \ingroup modbus
73 | * \brief Parity used for characters in serial mode.
74 | *
75 | * The parity which should be applied to the characters sent over the serial
76 | * link. Please note that this values are actually passed to the porting
77 | * layer and therefore not all parity modes might be available.
78 | */
79 | typedef enum
80 | {
81 | MB_PAR_NONE, /*!< No parity. */
82 | MB_PAR_ODD, /*!< Odd parity. */
83 | MB_PAR_EVEN /*!< Even parity. */
84 | } eMBParity;
85 |
86 | /* ----------------------- Supporting functions -----------------------------*/
87 | BOOL xMBPortEventInit( void );
88 |
89 | BOOL xMBPortEventPost( eMBEventType eEvent );
90 |
91 | BOOL xMBPortEventGet( /*@out@ */ eMBEventType * eEvent );
92 |
93 | BOOL xMBMasterPortEventInit( void );
94 |
95 | BOOL xMBMasterPortEventPost( eMBMasterEventType eEvent );
96 |
97 | BOOL xMBMasterPortEventGet( /*@out@ */ eMBMasterEventType * eEvent );
98 |
99 | void vMBMasterOsResInit( void );
100 |
101 | BOOL xMBMasterRunResTake( int32_t time );
102 |
103 | void vMBMasterRunResRelease( void );
104 |
105 | /* ----------------------- Serial port functions ----------------------------*/
106 |
107 | BOOL xMBPortSerialInit( UCHAR ucPort, ULONG ulBaudRate,
108 | UCHAR ucDataBits, eMBParity eParity );
109 |
110 | void vMBPortClose( void );
111 |
112 | void xMBPortSerialClose( void );
113 |
114 | void vMBPortSerialEnable( BOOL xRxEnable, BOOL xTxEnable );
115 |
116 | INLINE BOOL xMBPortSerialGetByte( CHAR * pucByte );
117 |
118 | INLINE BOOL xMBPortSerialPutByte( CHAR ucByte );
119 |
120 | BOOL xMBMasterPortSerialInit( UCHAR ucPort, ULONG ulBaudRate,
121 | UCHAR ucDataBits, eMBParity eParity );
122 |
123 | void vMBMasterPortClose( void );
124 |
125 | void xMBMasterPortSerialClose( void );
126 |
127 | void vMBMasterPortSerialEnable( BOOL xRxEnable, BOOL xTxEnable );
128 |
129 | INLINE BOOL xMBMasterPortSerialGetByte( CHAR * pucByte );
130 |
131 | INLINE BOOL xMBMasterPortSerialPutByte( CHAR ucByte );
132 |
133 | /* ----------------------- Timers functions ---------------------------------*/
134 | BOOL xMBPortTimersInit( USHORT usTimeOut50us );
135 |
136 | void xMBPortTimersClose( void );
137 |
138 | INLINE void vMBPortTimersEnable( void );
139 |
140 | INLINE void vMBPortTimersDisable( void );
141 |
142 | BOOL xMBMasterPortTimersInit( USHORT usTimeOut50us );
143 |
144 | void xMBMasterPortTimersClose( void );
145 |
146 | INLINE void vMBMasterPortTimersT35Enable( void );
147 |
148 | INLINE void vMBMasterPortTimersConvertDelayEnable( void );
149 |
150 | INLINE void vMBMasterPortTimersRespondTimeoutEnable( void );
151 |
152 | INLINE void vMBMasterPortTimersDisable( void );
153 |
154 | /* ----------------- Callback for the master error process ------------------*/
155 | void vMBMasterErrorCBRespondTimeout( UCHAR ucDestAddress, const UCHAR* pucPDUData,
156 | USHORT ucPDULength );
157 |
158 | void vMBMasterErrorCBReceiveData( UCHAR ucDestAddress, const UCHAR* pucPDUData,
159 | USHORT ucPDULength );
160 |
161 | void vMBMasterErrorCBExecuteFunction( UCHAR ucDestAddress, const UCHAR* pucPDUData,
162 | USHORT ucPDULength );
163 |
164 | void vMBMasterCBRequestScuuess( void );
165 |
166 | /* ----------------------- Callback for the protocol stack ------------------*/
167 |
168 | /*!
169 | * \brief Callback function for the porting layer when a new byte is
170 | * available.
171 | *
172 | * Depending upon the mode this callback function is used by the RTU or
173 | * ASCII transmission layers. In any case a call to xMBPortSerialGetByte()
174 | * must immediately return a new character.
175 | *
176 | * \return TRUE
if a event was posted to the queue because
177 | * a new byte was received. The port implementation should wake up the
178 | * tasks which are currently blocked on the eventqueue.
179 | */
180 | extern BOOL( *pxMBFrameCBByteReceived ) ( void );
181 |
182 | extern BOOL( *pxMBFrameCBTransmitterEmpty ) ( void );
183 |
184 | extern BOOL( *pxMBPortCBTimerExpired ) ( void );
185 |
186 | extern BOOL( *pxMBMasterFrameCBByteReceived ) ( void );
187 |
188 | extern BOOL( *pxMBMasterFrameCBTransmitterEmpty ) ( void );
189 |
190 | extern BOOL( *pxMBMasterPortCBTimerExpired ) ( void );
191 |
192 | /* ----------------------- TCP port functions -------------------------------*/
193 | BOOL xMBTCPPortInit( USHORT usTCPPort );
194 |
195 | void vMBTCPPortClose( void );
196 |
197 | void vMBTCPPortDisable( void );
198 |
199 | BOOL xMBTCPPortGetRequest( UCHAR **ppucMBTCPFrame, USHORT * usTCPLength );
200 |
201 | BOOL xMBTCPPortSendResponse( const UCHAR *pucMBTCPFrame, USHORT usTCPLength );
202 |
203 | #ifdef __cplusplus
204 | PR_END_EXTERN_C
205 | #endif
206 | #endif
207 |
--------------------------------------------------------------------------------
/MIddleware/FreeModbus/modbus/include/mbproto.h:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
3 | * Copyright (c) 2006 Christian Walter
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions
8 | * are met:
9 | * 1. Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | * 2. Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | * 3. The name of the author may not be used to endorse or promote products
15 | * derived from this software without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | *
28 | * File: $Id: mbproto.h,v 1.14 2006/12/07 22:10:34 wolti Exp $
29 | */
30 |
31 | #ifndef _MB_PROTO_H
32 | #define _MB_PROTO_H
33 |
34 | #ifdef __cplusplus
35 | PR_BEGIN_EXTERN_C
36 | #endif
37 | /* ----------------------- Defines ------------------------------------------*/
38 | #define MB_ADDRESS_BROADCAST ( 0 ) /*! Modbus broadcast address. */
39 | #define MB_ADDRESS_MIN ( 1 ) /*! Smallest possible slave address. */
40 | #define MB_ADDRESS_MAX ( 247 ) /*! Biggest possible slave address. */
41 | #define MB_FUNC_NONE ( 0 )
42 | #define MB_FUNC_READ_COILS ( 1 )
43 | #define MB_FUNC_READ_DISCRETE_INPUTS ( 2 )
44 | #define MB_FUNC_WRITE_SINGLE_COIL ( 5 )
45 | #define MB_FUNC_WRITE_MULTIPLE_COILS ( 15 )
46 | #define MB_FUNC_READ_HOLDING_REGISTER ( 3 )
47 | #define MB_FUNC_READ_INPUT_REGISTER ( 4 )
48 | #define MB_FUNC_WRITE_REGISTER ( 6 )
49 | #define MB_FUNC_WRITE_MULTIPLE_REGISTERS ( 16 )
50 | #define MB_FUNC_READWRITE_MULTIPLE_REGISTERS ( 23 )
51 | #define MB_FUNC_DIAG_READ_EXCEPTION ( 7 )
52 | #define MB_FUNC_DIAG_DIAGNOSTIC ( 8 )
53 | #define MB_FUNC_DIAG_GET_COM_EVENT_CNT ( 11 )
54 | #define MB_FUNC_DIAG_GET_COM_EVENT_LOG ( 12 )
55 | #define MB_FUNC_OTHER_REPORT_SLAVEID ( 17 )
56 | #define MB_FUNC_ERROR ( 128 )
57 | /* ----------------------- Type definitions ---------------------------------*/
58 | typedef enum
59 | {
60 | MB_EX_NONE = 0x00,
61 | MB_EX_ILLEGAL_FUNCTION = 0x01,
62 | MB_EX_ILLEGAL_DATA_ADDRESS = 0x02,
63 | MB_EX_ILLEGAL_DATA_VALUE = 0x03,
64 | MB_EX_SLAVE_DEVICE_FAILURE = 0x04,
65 | MB_EX_ACKNOWLEDGE = 0x05,
66 | MB_EX_SLAVE_BUSY = 0x06,
67 | MB_EX_MEMORY_PARITY_ERROR = 0x08,
68 | MB_EX_GATEWAY_PATH_FAILED = 0x0A,
69 | MB_EX_GATEWAY_TGT_FAILED = 0x0B
70 | } eMBException;
71 |
72 | typedef eMBException( *pxMBFunctionHandler ) ( UCHAR * pucFrame, USHORT * pusLength );
73 |
74 | typedef struct
75 | {
76 | UCHAR ucFunctionCode;
77 | pxMBFunctionHandler pxHandler;
78 | } xMBFunctionHandler;
79 |
80 | #ifdef __cplusplus
81 | PR_END_EXTERN_C
82 | #endif
83 | #endif
84 |
--------------------------------------------------------------------------------
/MIddleware/FreeModbus/modbus/include/mbutils.h:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
3 | * Copyright (c) 2006 Christian Walter
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions
8 | * are met:
9 | * 1. Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | * 2. Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | * 3. The name of the author may not be used to endorse or promote products
15 | * derived from this software without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | *
28 | * File: $Id: mbutils.h,v 1.5 2006/12/07 22:10:34 wolti Exp $
29 | */
30 |
31 | #ifndef _MB_UTILS_H
32 | #define _MB_UTILS_H
33 |
34 | #ifdef __cplusplus
35 | PR_BEGIN_EXTERN_C
36 | #endif
37 | /*! \defgroup modbus_utils Utilities
38 | *
39 | * This module contains some utility functions which can be used by
40 | * the application. It includes some special functions for working with
41 | * bitfields backed by a character array buffer.
42 | *
43 | */
44 | /*! \addtogroup modbus_utils
45 | * @{
46 | */
47 | /*! \brief Function to set bits in a byte buffer.
48 | *
49 | * This function allows the efficient use of an array to implement bitfields.
50 | * The array used for storing the bits must always be a multiple of two
51 | * bytes. Up to eight bits can be set or cleared in one operation.
52 | *
53 | * \param ucByteBuf A buffer where the bit values are stored. Must be a
54 | * multiple of 2 bytes. No length checking is performed and if
55 | * usBitOffset / 8 is greater than the size of the buffer memory contents
56 | * is overwritten.
57 | * \param usBitOffset The starting address of the bits to set. The first
58 | * bit has the offset 0.
59 | * \param ucNBits Number of bits to modify. The value must always be smaller
60 | * than 8.
61 | * \param ucValues Thew new values for the bits. The value for the first bit
62 | * starting at usBitOffset
is the LSB of the value
63 | * ucValues
64 | *
65 | * \code
66 | * ucBits[2] = {0, 0};
67 | *
68 | * // Set bit 4 to 1 (read: set 1 bit starting at bit offset 4 to value 1)
69 | * xMBUtilSetBits( ucBits, 4, 1, 1 );
70 | *
71 | * // Set bit 7 to 1 and bit 8 to 0.
72 | * xMBUtilSetBits( ucBits, 7, 2, 0x01 );
73 | *
74 | * // Set bits 8 - 11 to 0x05 and bits 12 - 15 to 0x0A;
75 | * xMBUtilSetBits( ucBits, 8, 8, 0x5A);
76 | * \endcode
77 | */
78 | void xMBUtilSetBits( UCHAR * ucByteBuf, USHORT usBitOffset,
79 | UCHAR ucNBits, UCHAR ucValues );
80 |
81 | /*! \brief Function to read bits in a byte buffer.
82 | *
83 | * This function is used to extract up bit values from an array. Up to eight
84 | * bit values can be extracted in one step.
85 | *
86 | * \param ucByteBuf A buffer where the bit values are stored.
87 | * \param usBitOffset The starting address of the bits to set. The first
88 | * bit has the offset 0.
89 | * \param ucNBits Number of bits to modify. The value must always be smaller
90 | * than 8.
91 | *
92 | * \code
93 | * UCHAR ucBits[2] = {0, 0};
94 | * UCHAR ucResult;
95 | *
96 | * // Extract the bits 3 - 10.
97 | * ucResult = xMBUtilGetBits( ucBits, 3, 8 );
98 | * \endcode
99 | */
100 | UCHAR xMBUtilGetBits( UCHAR * ucByteBuf, USHORT usBitOffset,
101 | UCHAR ucNBits );
102 |
103 | /*! @} */
104 |
105 | #ifdef __cplusplus
106 | PR_END_EXTERN_C
107 | #endif
108 | #endif
109 |
--------------------------------------------------------------------------------
/MIddleware/FreeModbus/modbus/rtu/mbcrc.c:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
3 | * Copyright (c) 2006 Christian Walter
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions
8 | * are met:
9 | * 1. Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | * 2. Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | * 3. The name of the author may not be used to endorse or promote products
15 | * derived from this software without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | *
28 | * File: $Id: mbcrc.c,v 1.7 2007/02/18 23:50:27 wolti Exp $
29 | */
30 |
31 | /* ----------------------- Platform includes --------------------------------*/
32 | #include "port.h"
33 |
34 | static const UCHAR aucCRCHi[] = {
35 | 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
36 | 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
37 | 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
38 | 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
39 | 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
40 | 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
41 | 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
42 | 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
43 | 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
44 | 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
45 | 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
46 | 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
47 | 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
48 | 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
49 | 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
50 | 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
51 | 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
52 | 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
53 | 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
54 | 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
55 | 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
56 | 0x00, 0xC1, 0x81, 0x40
57 | };
58 |
59 | static const UCHAR aucCRCLo[] = {
60 | 0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06, 0x07, 0xC7,
61 | 0x05, 0xC5, 0xC4, 0x04, 0xCC, 0x0C, 0x0D, 0xCD, 0x0F, 0xCF, 0xCE, 0x0E,
62 | 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09, 0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9,
63 | 0x1B, 0xDB, 0xDA, 0x1A, 0x1E, 0xDE, 0xDF, 0x1F, 0xDD, 0x1D, 0x1C, 0xDC,
64 | 0x14, 0xD4, 0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, 0x12, 0x13, 0xD3,
65 | 0x11, 0xD1, 0xD0, 0x10, 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3, 0xF2, 0x32,
66 | 0x36, 0xF6, 0xF7, 0x37, 0xF5, 0x35, 0x34, 0xF4, 0x3C, 0xFC, 0xFD, 0x3D,
67 | 0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A, 0x3B, 0xFB, 0x39, 0xF9, 0xF8, 0x38,
68 | 0x28, 0xE8, 0xE9, 0x29, 0xEB, 0x2B, 0x2A, 0xEA, 0xEE, 0x2E, 0x2F, 0xEF,
69 | 0x2D, 0xED, 0xEC, 0x2C, 0xE4, 0x24, 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26,
70 | 0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0, 0xA0, 0x60, 0x61, 0xA1,
71 | 0x63, 0xA3, 0xA2, 0x62, 0x66, 0xA6, 0xA7, 0x67, 0xA5, 0x65, 0x64, 0xA4,
72 | 0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F, 0x6E, 0xAE, 0xAA, 0x6A, 0x6B, 0xAB,
73 | 0x69, 0xA9, 0xA8, 0x68, 0x78, 0xB8, 0xB9, 0x79, 0xBB, 0x7B, 0x7A, 0xBA,
74 | 0xBE, 0x7E, 0x7F, 0xBF, 0x7D, 0xBD, 0xBC, 0x7C, 0xB4, 0x74, 0x75, 0xB5,
75 | 0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71, 0x70, 0xB0,
76 | 0x50, 0x90, 0x91, 0x51, 0x93, 0x53, 0x52, 0x92, 0x96, 0x56, 0x57, 0x97,
77 | 0x55, 0x95, 0x94, 0x54, 0x9C, 0x5C, 0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E,
78 | 0x5A, 0x9A, 0x9B, 0x5B, 0x99, 0x59, 0x58, 0x98, 0x88, 0x48, 0x49, 0x89,
79 | 0x4B, 0x8B, 0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C,
80 | 0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42, 0x43, 0x83,
81 | 0x41, 0x81, 0x80, 0x40
82 | };
83 |
84 | USHORT
85 | usMBCRC16( UCHAR * pucFrame, USHORT usLen )
86 | {
87 | UCHAR ucCRCHi = 0xFF;
88 | UCHAR ucCRCLo = 0xFF;
89 | int iIndex;
90 |
91 | while( usLen-- )
92 | {
93 | iIndex = ucCRCLo ^ *( pucFrame++ );
94 | ucCRCLo = ( UCHAR )( ucCRCHi ^ aucCRCHi[iIndex] );
95 | ucCRCHi = aucCRCLo[iIndex];
96 | }
97 | return ( USHORT )( ucCRCHi << 8 | ucCRCLo );
98 | }
99 |
--------------------------------------------------------------------------------
/MIddleware/FreeModbus/modbus/rtu/mbcrc.h:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
3 | * Copyright (c) 2006 Christian Walter
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions
8 | * are met:
9 | * 1. Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | * 2. Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | * 3. The name of the author may not be used to endorse or promote products
15 | * derived from this software without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | *
28 | * File: $Id: mbcrc.h,v 1.5 2006/12/07 22:10:34 wolti Exp $
29 | */
30 |
31 | #ifndef _MB_CRC_H
32 | #define _MB_CRC_H
33 |
34 | USHORT usMBCRC16( UCHAR * pucFrame, USHORT usLen );
35 |
36 | #endif
37 |
--------------------------------------------------------------------------------
/MIddleware/FreeModbus/modbus/rtu/mbrtu.h:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
3 | * Copyright (c) 2006 Christian Walter
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions
8 | * are met:
9 | * 1. Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | * 2. Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | * 3. The name of the author may not be used to endorse or promote products
15 | * derived from this software without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | *
28 | * File: $Id: mbrtu.h,v 1.9 2006/12/07 22:10:34 wolti Exp $
29 | * File: $Id: mbrtu.h,v 1.60 2013/08/17 13:11:42 Armink Add Master Functions $
30 | */
31 | #include "mbconfig.h"
32 |
33 | #ifndef _MB_RTU_H
34 | #define _MB_RTU_H
35 |
36 | #ifdef __cplusplus
37 | PR_BEGIN_EXTERN_C
38 | #endif
39 | eMBErrorCode eMBRTUInit( UCHAR slaveAddress, UCHAR ucPort, ULONG ulBaudRate,
40 | eMBParity eParity );
41 | void eMBRTUStart( void );
42 | void eMBRTUStop( void );
43 | eMBErrorCode eMBRTUReceive( UCHAR * pucRcvAddress, UCHAR ** pucFrame, USHORT * pusLength );
44 | eMBErrorCode eMBRTUSend( UCHAR slaveAddress, const UCHAR * pucFrame, USHORT usLength );
45 | BOOL xMBRTUReceiveFSM( void );
46 | BOOL xMBRTUTransmitFSM( void );
47 | BOOL xMBRTUTimerT15Expired( void );
48 | BOOL xMBRTUTimerT35Expired( void );
49 |
50 | #if MB_MASTER_RTU_ENABLED > 0
51 | eMBErrorCode eMBMasterRTUInit( UCHAR ucPort, ULONG ulBaudRate,eMBParity eParity );
52 | void eMBMasterRTUStart( void );
53 | void eMBMasterRTUStop( void );
54 | eMBErrorCode eMBMasterRTUReceive( UCHAR * pucRcvAddress, UCHAR ** pucFrame, USHORT * pusLength );
55 | eMBErrorCode eMBMasterRTUSend( UCHAR slaveAddress, const UCHAR * pucFrame, USHORT usLength );
56 | BOOL xMBMasterRTUReceiveFSM( void );
57 | BOOL xMBMasterRTUTransmitFSM( void );
58 | BOOL xMBMasterRTUTimerExpired( void );
59 | #endif
60 |
61 | #ifdef __cplusplus
62 | PR_END_EXTERN_C
63 | #endif
64 | #endif
65 |
--------------------------------------------------------------------------------
/MIddleware/FreeModbus/modbus/tcp/mbtcp.c:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
3 | * Copyright (c) 2006 Christian Walter
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions
8 | * are met:
9 | * 1. Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | * 2. Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | * 3. The name of the author may not be used to endorse or promote products
15 | * derived from this software without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | *
28 | * File: $Id: mbtcp.c,v 1.3 2006/12/07 22:10:34 wolti Exp $
29 | */
30 |
31 | /* ----------------------- System includes ----------------------------------*/
32 | #include "stdlib.h"
33 | #include "string.h"
34 |
35 | /* ----------------------- Platform includes --------------------------------*/
36 | #include "port.h"
37 |
38 | /* ----------------------- Modbus includes ----------------------------------*/
39 | #include "mb.h"
40 | #include "mbconfig.h"
41 | #include "mbtcp.h"
42 | #include "mbframe.h"
43 | #include "mbport.h"
44 |
45 | #if MB_SLAVE_TCP_ENABLED > 0
46 |
47 | /* ----------------------- Defines ------------------------------------------*/
48 |
49 | /* ----------------------- MBAP Header --------------------------------------*/
50 | /*
51 | *
52 | * <------------------------ MODBUS TCP/IP ADU(1) ------------------------->
53 | * <----------- MODBUS PDU (1') ---------------->
54 | * +-----------+---------------+------------------------------------------+
55 | * | TID | PID | Length | UID |Code | Data |
56 | * +-----------+---------------+------------------------------------------+
57 | * | | | | |
58 | * (2) (3) (4) (5) (6)
59 | *
60 | * (2) ... MB_TCP_TID = 0 (Transaction Identifier - 2 Byte)
61 | * (3) ... MB_TCP_PID = 2 (Protocol Identifier - 2 Byte)
62 | * (4) ... MB_TCP_LEN = 4 (Number of bytes - 2 Byte)
63 | * (5) ... MB_TCP_UID = 6 (Unit Identifier - 1 Byte)
64 | * (6) ... MB_TCP_FUNC = 7 (Modbus Function Code)
65 | *
66 | * (1) ... Modbus TCP/IP Application Data Unit
67 | * (1') ... Modbus Protocol Data Unit
68 | */
69 |
70 | #define MB_TCP_TID 0
71 | #define MB_TCP_PID 2
72 | #define MB_TCP_LEN 4
73 | #define MB_TCP_UID 6
74 | #define MB_TCP_FUNC 7
75 |
76 | #define MB_TCP_PROTOCOL_ID 0 /* 0 = Modbus Protocol */
77 |
78 |
79 | /* ----------------------- Start implementation -----------------------------*/
80 | eMBErrorCode
81 | eMBTCPDoInit( USHORT ucTCPPort )
82 | {
83 | eMBErrorCode eStatus = MB_ENOERR;
84 |
85 | if( xMBTCPPortInit( ucTCPPort ) == FALSE )
86 | {
87 | eStatus = MB_EPORTERR;
88 | }
89 | return eStatus;
90 | }
91 |
92 | void
93 | eMBTCPStart( void )
94 | {
95 | }
96 |
97 | void
98 | eMBTCPStop( void )
99 | {
100 | /* Make sure that no more clients are connected. */
101 | vMBTCPPortDisable( );
102 | }
103 |
104 | eMBErrorCode
105 | eMBTCPReceive( UCHAR * pucRcvAddress, UCHAR ** ppucFrame, USHORT * pusLength )
106 | {
107 | eMBErrorCode eStatus = MB_EIO;
108 | UCHAR *pucMBTCPFrame;
109 | USHORT usLength;
110 | USHORT usPID;
111 |
112 | if( xMBTCPPortGetRequest( &pucMBTCPFrame, &usLength ) != FALSE )
113 | {
114 | usPID = pucMBTCPFrame[MB_TCP_PID] << 8U;
115 | usPID |= pucMBTCPFrame[MB_TCP_PID + 1];
116 |
117 | if( usPID == MB_TCP_PROTOCOL_ID )
118 | {
119 | *ppucFrame = &pucMBTCPFrame[MB_TCP_FUNC];
120 | *pusLength = usLength - MB_TCP_FUNC;
121 | eStatus = MB_ENOERR;
122 |
123 | /* Modbus TCP does not use any addresses. Fake the source address such
124 | * that the processing part deals with this frame.
125 | */
126 | *pucRcvAddress = MB_TCP_PSEUDO_ADDRESS;
127 | }
128 | }
129 | else
130 | {
131 | eStatus = MB_EIO;
132 | }
133 | return eStatus;
134 | }
135 |
136 | eMBErrorCode
137 | eMBTCPSend( UCHAR _unused, const UCHAR * pucFrame, USHORT usLength )
138 | {
139 | eMBErrorCode eStatus = MB_ENOERR;
140 | UCHAR *pucMBTCPFrame = ( UCHAR * ) pucFrame - MB_TCP_FUNC;
141 | USHORT usTCPLength = usLength + MB_TCP_FUNC;
142 |
143 | /* The MBAP header is already initialized because the caller calls this
144 | * function with the buffer returned by the previous call. Therefore we
145 | * only have to update the length in the header. Note that the length
146 | * header includes the size of the Modbus PDU and the UID Byte. Therefore
147 | * the length is usLength plus one.
148 | */
149 | pucMBTCPFrame[MB_TCP_LEN] = ( usLength + 1 ) >> 8U;
150 | pucMBTCPFrame[MB_TCP_LEN + 1] = ( usLength + 1 ) & 0xFF;
151 | if( xMBTCPPortSendResponse( pucMBTCPFrame, usTCPLength ) == FALSE )
152 | {
153 | eStatus = MB_EIO;
154 | }
155 | return eStatus;
156 | }
157 |
158 | #endif
159 |
--------------------------------------------------------------------------------
/MIddleware/FreeModbus/modbus/tcp/mbtcp.h:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
3 | * Copyright (c) 2006 Christian Walter
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions
8 | * are met:
9 | * 1. Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | * 2. Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | * 3. The name of the author may not be used to endorse or promote products
15 | * derived from this software without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | *
28 | * File: $Id: mbtcp.h,v 1.2 2006/12/07 22:10:34 wolti Exp $
29 | */
30 |
31 | #ifndef _MB_TCP_H
32 | #define _MB_TCP_H
33 |
34 | #ifdef __cplusplus
35 | PR_BEGIN_EXTERN_C
36 | #endif
37 |
38 | /* ----------------------- Defines ------------------------------------------*/
39 | #define MB_TCP_PSEUDO_ADDRESS 255
40 |
41 | /* ----------------------- Function prototypes ------------------------------*/
42 | eMBErrorCode eMBTCPDoInit( USHORT ucTCPPort );
43 | void eMBTCPStart( void );
44 | void eMBTCPStop( void );
45 | eMBErrorCode eMBTCPReceive( UCHAR * pucRcvAddress, UCHAR ** pucFrame,
46 | USHORT * pusLength );
47 | eMBErrorCode eMBTCPSend( UCHAR _unused, const UCHAR * pucFrame,
48 | USHORT usLength );
49 |
50 | #ifdef __cplusplus
51 | PR_END_EXTERN_C
52 | #endif
53 | #endif
54 |
--------------------------------------------------------------------------------
/MIddleware/FreeModbus/port/no_os/port.c:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeModbus Libary: RT-Thread Port
3 | * Copyright (C) 2013 Armink
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | *
19 | * File: $Id: port.c,v 1.60 2015/02/01 9:18:05 Armink $
20 | */
21 |
22 | /* ----------------------- System includes --------------------------------*/
23 |
24 | /* ----------------------- Modbus includes ----------------------------------*/
25 | #include "port.h"
26 | /* ----------------------- Variables ----------------------------------------*/
27 | /* ----------------------- Start implementation -----------------------------*/
28 | void EnterCriticalSection(void)
29 | {
30 | __disable_irq();
31 | }
32 |
33 | void ExitCriticalSection(void)
34 | {
35 | __enable_irq();
36 | }
37 |
38 |
--------------------------------------------------------------------------------
/MIddleware/FreeModbus/port/no_os/portevent.c:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeModbus Libary: BARE Port
3 | * Copyright (C) 2006 Christian Walter
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | *
19 | * File: $Id: portevent.c,v 1.1 2006/08/22 21:35:13 wolti Exp $
20 | */
21 |
22 | /* ----------------------- Modbus includes ----------------------------------*/
23 | #include "mb.h"
24 | #include "mbport.h"
25 |
26 | /* ----------------------- Variables ----------------------------------------*/
27 | static eMBEventType eQueuedEvent;
28 | static BOOL xEventInQueue;
29 |
30 | /* ----------------------- Start implementation -----------------------------*/
31 | BOOL
32 | xMBPortEventInit( void )
33 | {
34 | xEventInQueue = FALSE;
35 | return TRUE;
36 | }
37 |
38 | BOOL
39 | xMBPortEventPost( eMBEventType eEvent )
40 | {
41 | xEventInQueue = TRUE;
42 | eQueuedEvent = eEvent;
43 | return TRUE;
44 | }
45 |
46 | BOOL
47 | xMBPortEventGet( eMBEventType * eEvent )
48 | {
49 | BOOL xEventHappened = FALSE;
50 |
51 | if( xEventInQueue )
52 | {
53 | *eEvent = eQueuedEvent;
54 | xEventInQueue = FALSE;
55 | xEventHappened = TRUE;
56 | }
57 | return xEventHappened;
58 | }
59 |
--------------------------------------------------------------------------------
/MIddleware/FreeModbus/port/no_os/portserial.c:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeModbus Libary: BARE Port
3 | * Copyright (C) 2006 Christian Walter
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | *
19 | * File: $Id: portserial.c,v 1.1 2006/08/22 21:35:13 wolti Exp $
20 | */
21 |
22 | #include "port.h"
23 |
24 | /* ----------------------- Modbus includes ----------------------------------*/
25 | #include "mb.h"
26 | #include "mbport.h"
27 | #include "usart.h"
28 | #include "bsp.h"
29 |
30 | /* ----------------------- static functions ---------------------------------*/
31 | //static void prvvUARTTxReadyISR( void );
32 | //static void prvvUARTRxISR( void );
33 |
34 | /* ----------------------- Start implementation -----------------------------*/
35 | void
36 | vMBPortSerialEnable( BOOL xRxEnable, BOOL xTxEnable )
37 | {
38 | /* If xRXEnable enable serial receive interrupts. If xTxENable enable
39 | * transmitter empty interrupts.
40 | */
41 | if (xRxEnable) {
42 | HAL_GPIO_WritePin(M485_EN_PORT, M485_EN_PIN, GPIO_PIN_RESET);
43 | __HAL_UART_ENABLE_IT(&huart1, UART_IT_RXNE);
44 | } else {
45 | __HAL_UART_DISABLE_IT(&huart1, UART_IT_RXNE);
46 | }
47 |
48 | if (xTxEnable) {
49 | HAL_GPIO_WritePin(M485_EN_PORT, M485_EN_PIN, GPIO_PIN_SET);
50 | __HAL_UART_ENABLE_IT(&huart1, UART_IT_TXE);
51 | } else {
52 | __HAL_UART_DISABLE_IT(&huart1, UART_IT_TXE);
53 | }
54 |
55 | }
56 |
57 | BOOL
58 | xMBPortSerialInit( UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits, eMBParity eParity )
59 | {
60 |
61 | return TRUE;
62 | }
63 |
64 | BOOL
65 | xMBPortSerialPutByte( CHAR ucByte )
66 | {
67 | /* Put a byte in the UARTs transmit buffer. This function is called
68 | * by the protocol stack if pxMBFrameCBTransmitterEmpty( ) has been
69 | * called. */
70 | return (HAL_OK == HAL_UART_Transmit(&huart1, (uint8_t*)&ucByte, 1, 10));
71 | }
72 |
73 | BOOL
74 | xMBPortSerialGetByte( CHAR * pucByte )
75 | {
76 | /* Return the byte in the UARTs receive buffer. This function is called
77 | * by the protocol stack after pxMBFrameCBByteReceived( ) has been called.
78 | */
79 | *pucByte = (uint8_t)(huart1.Instance->DR & (uint8_t)0x00FF);
80 | return TRUE;
81 | }
82 |
83 | /* Create an interrupt handler for the transmit buffer empty interrupt
84 | * (or an equivalent) for your target processor. This function should then
85 | * call pxMBFrameCBTransmitterEmpty( ) which tells the protocol stack that
86 | * a new character can be sent. The protocol stack will then call
87 | * xMBPortSerialPutByte( ) to send the character.
88 | */
89 |
90 | /*
91 | *move to irq_callback.c
92 | static void prvvUARTTxReadyISR( void )
93 | {
94 | pxMBFrameCBTransmitterEmpty( );
95 | }
96 | */
97 |
98 | /* Create an interrupt handler for the receive interrupt for your target
99 | * processor. This function should then call pxMBFrameCBByteReceived( ). The
100 | * protocol stack will then call xMBPortSerialGetByte( ) to retrieve the
101 | * character.
102 | */
103 | /*
104 | static void prvvUARTRxISR( void )
105 | {
106 | pxMBFrameCBByteReceived( );
107 | }
108 | */
109 |
--------------------------------------------------------------------------------
/MIddleware/FreeModbus/port/no_os/portserial_m.c:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeModbus Libary: RT-Thread Port
3 | * Copyright (C) 2013 Armink
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | *
19 | * File: $Id: portserial_m.c,v 1.60 2013/08/13 15:07:05 Armink add Master Functions $
20 | */
21 |
22 | #include "port.h"
23 |
24 | /* ----------------------- Modbus includes ----------------------------------*/
25 | #include "mb.h"
26 | #include "mbport.h"
27 | #include "usart.h"
28 | #include "bsp.h"
29 |
30 | #if MB_MASTER_RTU_ENABLED > 0 || MB_MASTER_ASCII_ENABLED > 0
31 | /* ----------------------- Static variables ---------------------------------*/
32 |
33 | /* ----------------------- Defines ------------------------------------------*/
34 | /* serial transmit event */
35 | #define EVENT_SERIAL_TRANS_START (1<<0)
36 |
37 | /* ----------------------- static functions ---------------------------------*/
38 |
39 | /* ----------------------- Start implementation -----------------------------*/
40 | BOOL xMBMasterPortSerialInit(UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits,
41 | eMBParity eParity)
42 | {
43 | return TRUE;
44 | }
45 |
46 | void vMBMasterPortSerialEnable(BOOL xRxEnable, BOOL xTxEnable)
47 | {
48 | if (xRxEnable) {
49 | HAL_GPIO_WritePin(M485_EN_PORT, M485_EN_PIN, GPIO_PIN_RESET);
50 | __HAL_UART_ENABLE_IT(&huart1, UART_IT_RXNE);
51 | } else{
52 | __HAL_UART_DISABLE_IT(&huart1, UART_IT_RXNE);
53 | }
54 |
55 | if (xTxEnable) {
56 | HAL_GPIO_WritePin(M485_EN_PORT, M485_EN_PIN, GPIO_PIN_SET);
57 | __HAL_UART_ENABLE_IT(&huart1, UART_IT_TXE);
58 | } else{
59 | __HAL_UART_DISABLE_IT(&huart1, UART_IT_TXE);
60 | }
61 | }
62 |
63 | void vMBMasterPortClose(void)
64 | {
65 |
66 | }
67 |
68 | BOOL xMBMasterPortSerialPutByte(CHAR ucByte)
69 | {
70 |
71 | return (HAL_OK == HAL_UART_Transmit(&huart1, (uint8_t*)&ucByte, 1, 10));
72 | }
73 |
74 | BOOL xMBMasterPortSerialGetByte(CHAR * pucByte)
75 | {
76 |
77 | *pucByte = (uint8_t)(huart1.Instance->DR & (uint8_t)0x00FF);
78 | return TRUE;
79 | }
80 |
81 |
82 |
83 | #endif
84 |
--------------------------------------------------------------------------------
/MIddleware/FreeModbus/port/no_os/porttimer.c:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeModbus Libary: BARE Port
3 | * Copyright (C) 2006 Christian Walter
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | *
19 | * File: $Id: porttimer.c,v 1.1 2006/08/22 21:35:13 wolti Exp $
20 | */
21 |
22 | /* ----------------------- Platform includes --------------------------------*/
23 | #include "port.h"
24 |
25 | /* ----------------------- Modbus includes ----------------------------------*/
26 | #include "mb.h"
27 | #include "mbport.h"
28 | #include "tim.h"
29 | /* ----------------------- static functions ---------------------------------*/
30 | //static void prvvTIMERExpiredISR( void );
31 |
32 | /* ----------------------- Start implementation -----------------------------*/
33 | BOOL
34 | xMBPortTimersInit( USHORT usTim1Timerout50us )
35 | {
36 | htim3.Instance = TIM3;
37 | htim3.Init.Prescaler = (uint16_t)(SystemCoreClock/20000)-1;
38 | htim3.Init.Period = usTim1Timerout50us;
39 | htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
40 | htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
41 | if (HAL_TIM_Base_Init(&htim3) != HAL_OK)
42 | {
43 | _Error_Handler(__FILE__, __LINE__);
44 | }
45 | return TRUE;
46 | }
47 |
48 |
49 | inline void
50 | vMBPortTimersEnable( )
51 | {
52 | /* Enable the timer with the timeout passed to xMBPortTimersInit( ) */
53 | htim3.Instance->CNT=0;
54 | __HAL_TIM_CLEAR_IT(&htim3, TIM_IT_UPDATE);
55 | HAL_TIM_Base_Start_IT(&htim3);
56 |
57 | }
58 |
59 | inline void
60 | vMBPortTimersDisable( )
61 | {
62 | /* Disable any pending timers. */
63 | HAL_TIM_Base_Stop_IT(&htim3);
64 | }
65 |
66 | /* Create an ISR which is called whenever the timer has expired. This function
67 | * must then call pxMBPortCBTimerExpired( ) to notify the protocol stack that
68 | * the timer has expired.
69 | */
70 | /*
71 | * call in irq_callbacj.c
72 | static void prvvTIMERExpiredISR( void )
73 | {
74 | ( void )pxMBPortCBTimerExpired( );
75 |
76 | }
77 | */
78 |
79 |
--------------------------------------------------------------------------------
/MIddleware/FreeModbus/port/no_os/porttimer_m.c:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeModbus Libary: RT-Thread Port
3 | * Copyright (C) 2013 Armink
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | *
19 | * File: $Id: porttimer_m.c,v 1.60 2013/08/13 15:07:05 Armink add Master Functions$
20 | */
21 |
22 | /* ----------------------- Platform includes --------------------------------*/
23 | #include "port.h"
24 |
25 | /* ----------------------- Modbus includes ----------------------------------*/
26 | #include "mb.h"
27 | #include "mb_m.h"
28 | #include "mbport.h"
29 | #include "tim.h"
30 |
31 | #if MB_MASTER_RTU_ENABLED > 0 || MB_MASTER_ASCII_ENABLED > 0
32 | /* ----------------------- Variables ----------------------------------------*/
33 |
34 |
35 | /* ----------------------- static functions ---------------------------------*/
36 |
37 | /* ----------------------- Start implementation -----------------------------*/
38 | BOOL xMBMasterPortTimersInit(USHORT usTimeOut50us)
39 | {
40 | htim3.Instance = TIM3;
41 | htim3.Init.Prescaler = (uint16_t)(SystemCoreClock/20000)-1;
42 | htim3.Init.Period = usTimeOut50us;
43 | htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
44 | htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
45 | if (HAL_TIM_Base_Init(&htim3) != HAL_OK)
46 | {
47 | _Error_Handler(__FILE__, __LINE__);
48 | }
49 | return TRUE;
50 | }
51 |
52 | void vMBMasterPortTimersT35Enable()
53 | {
54 | /* Set current timer mode, don't change it.*/
55 | vMBMasterSetCurTimerMode(MB_TMODE_T35);
56 | htim3.Instance->CNT=0;
57 | __HAL_TIM_CLEAR_IT(&htim3, TIM_IT_UPDATE);
58 | HAL_TIM_Base_Start_IT(&htim3);
59 | }
60 |
61 | void vMBMasterPortTimersConvertDelayEnable()
62 | {
63 | //rt_tick_t timer_tick = MB_MASTER_DELAY_MS_CONVERT * RT_TICK_PER_SECOND / 1000;
64 | htim3.Instance = TIM3;
65 | htim3.Init.Prescaler = (uint16_t)(SystemCoreClock/1000)-1;
66 | htim3.Init.Period = MB_MASTER_DELAY_MS_CONVERT;
67 | htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
68 | htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
69 | if (HAL_TIM_Base_Init(&htim3) != HAL_OK)
70 | {
71 | _Error_Handler(__FILE__, __LINE__);
72 | }
73 | /* Set current timer mode, don't change it.*/
74 | vMBMasterSetCurTimerMode(MB_TMODE_CONVERT_DELAY);
75 | htim3.Instance->CNT=0;
76 | __HAL_TIM_CLEAR_IT(&htim3, TIM_IT_UPDATE);
77 | HAL_TIM_Base_Start_IT(&htim3);
78 | }
79 |
80 | void vMBMasterPortTimersRespondTimeoutEnable()
81 | {
82 | //rt_tick_t timer_tick = MB_MASTER_TIMEOUT_MS_RESPOND * RT_TICK_PER_SECOND / 1000;
83 | htim3.Instance = TIM3;
84 | htim3.Init.Prescaler = (uint16_t)(SystemCoreClock/1000)-1;
85 | htim3.Init.Period = MB_MASTER_TIMEOUT_MS_RESPOND;
86 | htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
87 | htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
88 | if (HAL_TIM_Base_Init(&htim3) != HAL_OK)
89 | {
90 | _Error_Handler(__FILE__, __LINE__);
91 | }
92 | /* Set current timer mode, don't change it.*/
93 |
94 | vMBMasterSetCurTimerMode(MB_TMODE_RESPOND_TIMEOUT);
95 | htim3.Instance->CNT=0;
96 | __HAL_TIM_CLEAR_IT(&htim3, TIM_IT_UPDATE);
97 | HAL_TIM_Base_Start_IT(&htim3);
98 | }
99 |
100 | void vMBMasterPortTimersDisable()
101 | {
102 | HAL_TIM_Base_Stop_IT(&htim3);
103 | }
104 |
105 |
106 | #endif
107 |
--------------------------------------------------------------------------------
/MIddleware/FreeModbus/port/port.h:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeModbus Libary: BARE Port
3 | * Copyright (C) 2013 Armink
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | *
19 | * File: $Id: port.h ,v 1.60 2013/08/13 15:07:05 Armink add Master Functions $
20 | */
21 |
22 | #ifndef _PORT_H
23 | #define _PORT_H
24 |
25 | #include "stm32f1xx_hal.h"
26 | #include "mbconfig.h"
27 |
28 | #include
29 | #include
30 |
31 | #define INLINE
32 | #define PR_BEGIN_EXTERN_C extern "C" {
33 | #define PR_END_EXTERN_C }
34 |
35 | #define ENTER_CRITICAL_SECTION() EnterCriticalSection()
36 | #define EXIT_CRITICAL_SECTION() ExitCriticalSection()
37 |
38 | typedef uint8_t BOOL;
39 |
40 | typedef unsigned char UCHAR;
41 | typedef char CHAR;
42 |
43 | typedef uint16_t USHORT;
44 | typedef int16_t SHORT;
45 |
46 | typedef uint32_t ULONG;
47 | typedef int32_t LONG;
48 |
49 | #ifndef TRUE
50 | #define TRUE 1
51 | #endif
52 |
53 | #ifndef FALSE
54 | #define FALSE 0
55 | #endif
56 |
57 | void EnterCriticalSection(void);
58 | void ExitCriticalSection(void);
59 |
60 | #endif
61 |
--------------------------------------------------------------------------------
/MIddleware/FreeModbus/port/rtt/port.c:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeModbus Libary: RT-Thread Port
3 | * Copyright (C) 2013 Armink
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | *
19 | * File: $Id: port.c,v 1.60 2015/02/01 9:18:05 Armink $
20 | */
21 |
22 | /* ----------------------- System includes --------------------------------*/
23 |
24 | /* ----------------------- Modbus includes ----------------------------------*/
25 | #include "port.h"
26 | /* ----------------------- Variables ----------------------------------------*/
27 | static rt_base_t level;
28 | /* ----------------------- Start implementation -----------------------------*/
29 | void EnterCriticalSection(void)
30 | {
31 | level = rt_hw_interrupt_disable();
32 | }
33 |
34 | void ExitCriticalSection(void)
35 | {
36 | rt_hw_interrupt_enable(level);
37 | }
38 |
39 |
--------------------------------------------------------------------------------
/MIddleware/FreeModbus/port/rtt/portevent.c:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeModbus Libary: RT-Thread Port
3 | * Copyright (C) 2013 Armink
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | *
19 | * File: $Id: portevent.c,v 1.60 2013/08/13 15:07:05 Armink $
20 | */
21 |
22 | /* ----------------------- Modbus includes ----------------------------------*/
23 | #include "mb.h"
24 | #include "mbport.h"
25 |
26 | /* ----------------------- Variables ----------------------------------------*/
27 | static struct rt_event xSlaveOsEvent;
28 | /* ----------------------- Start implementation -----------------------------*/
29 | BOOL
30 | xMBPortEventInit( void )
31 | {
32 | rt_event_init(&xSlaveOsEvent,"slave event",RT_IPC_FLAG_PRIO);
33 | return TRUE;
34 | }
35 |
36 | BOOL
37 | xMBPortEventPost( eMBEventType eEvent )
38 | {
39 | rt_event_send(&xSlaveOsEvent, eEvent);
40 | return TRUE;
41 | }
42 |
43 | BOOL
44 | xMBPortEventGet( eMBEventType * eEvent )
45 | {
46 | rt_uint32_t recvedEvent;
47 | /* waiting forever OS event */
48 | rt_event_recv(&xSlaveOsEvent,
49 | EV_READY | EV_FRAME_RECEIVED | EV_EXECUTE | EV_FRAME_SENT,
50 | RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER,
51 | &recvedEvent);
52 | switch (recvedEvent)
53 | {
54 | case EV_READY:
55 | *eEvent = EV_READY;
56 | break;
57 | case EV_FRAME_RECEIVED:
58 | *eEvent = EV_FRAME_RECEIVED;
59 | break;
60 | case EV_EXECUTE:
61 | *eEvent = EV_EXECUTE;
62 | break;
63 | case EV_FRAME_SENT:
64 | *eEvent = EV_FRAME_SENT;
65 | break;
66 | }
67 | return TRUE;
68 | }
69 |
--------------------------------------------------------------------------------
/MIddleware/FreeModbus/port/rtt/portevent_m.c:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeModbus Libary: RT-Thread Port
3 | * Copyright (C) 2013 Armink
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | *
19 | * File: $Id: portevent_m.c v 1.60 2013/08/13 15:07:05 Armink add Master Functions$
20 | */
21 |
22 | /* ----------------------- Modbus includes ----------------------------------*/
23 | #include "mb.h"
24 | #include "mb_m.h"
25 | #include "mbport.h"
26 | #include "port.h"
27 |
28 | #if MB_MASTER_RTU_ENABLED > 0 || MB_MASTER_ASCII_ENABLED > 0
29 | /* ----------------------- Defines ------------------------------------------*/
30 | /* ----------------------- Variables ----------------------------------------*/
31 | static struct rt_semaphore xMasterRunRes;
32 | static struct rt_event xMasterOsEvent;
33 | /* ----------------------- Start implementation -----------------------------*/
34 | BOOL
35 | xMBMasterPortEventInit( void )
36 | {
37 | rt_event_init(&xMasterOsEvent,"master event",RT_IPC_FLAG_PRIO);
38 | return TRUE;
39 | }
40 |
41 | BOOL
42 | xMBMasterPortEventPost( eMBMasterEventType eEvent )
43 | {
44 | rt_event_send(&xMasterOsEvent, eEvent);
45 | return TRUE;
46 | }
47 |
48 | BOOL
49 | xMBMasterPortEventGet( eMBMasterEventType * eEvent )
50 | {
51 | rt_uint32_t recvedEvent;
52 | /* waiting forever OS event */
53 | rt_event_recv(&xMasterOsEvent,
54 | EV_MASTER_READY | EV_MASTER_FRAME_RECEIVED | EV_MASTER_EXECUTE |
55 | EV_MASTER_FRAME_SENT | EV_MASTER_ERROR_PROCESS,
56 | RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER,
57 | &recvedEvent);
58 | /* the enum type couldn't convert to int type */
59 | switch (recvedEvent)
60 | {
61 | case EV_MASTER_READY:
62 | *eEvent = EV_MASTER_READY;
63 | break;
64 | case EV_MASTER_FRAME_RECEIVED:
65 | *eEvent = EV_MASTER_FRAME_RECEIVED;
66 | break;
67 | case EV_MASTER_EXECUTE:
68 | *eEvent = EV_MASTER_EXECUTE;
69 | break;
70 | case EV_MASTER_FRAME_SENT:
71 | *eEvent = EV_MASTER_FRAME_SENT;
72 | break;
73 | case EV_MASTER_ERROR_PROCESS:
74 | *eEvent = EV_MASTER_ERROR_PROCESS;
75 | break;
76 | }
77 | return TRUE;
78 | }
79 | /**
80 | * This function is initialize the OS resource for modbus master.
81 | * Note:The resource is define by OS.If you not use OS this function can be empty.
82 | *
83 | */
84 | void vMBMasterOsResInit( void )
85 | {
86 | rt_sem_init(&xMasterRunRes, "master res", 0x01 , RT_IPC_FLAG_PRIO);
87 | }
88 |
89 | /**
90 | * This function is take Mobus Master running resource.
91 | * Note:The resource is define by Operating System.If you not use OS this function can be just return TRUE.
92 | *
93 | * @param lTimeOut the waiting time.
94 | *
95 | * @return resource taked result
96 | */
97 | BOOL xMBMasterRunResTake( LONG lTimeOut )
98 | {
99 | /*If waiting time is -1 .It will wait forever */
100 | return rt_sem_take(&xMasterRunRes, lTimeOut) ? FALSE : TRUE ;
101 | }
102 |
103 | /**
104 | * This function is release Mobus Master running resource.
105 | * Note:The resource is define by Operating System.If you not use OS this function can be empty.
106 | *
107 | */
108 | void vMBMasterRunResRelease( void )
109 | {
110 | /* release resource */
111 | rt_sem_release(&xMasterRunRes);
112 | }
113 |
114 | /**
115 | * This is modbus master respond timeout error process callback function.
116 | * @note There functions will block modbus master poll while execute OS waiting.
117 | * So,for real-time of system.Do not execute too much waiting process.
118 | *
119 | * @param ucDestAddress destination salve address
120 | * @param pucPDUData PDU buffer data
121 | * @param ucPDULength PDU buffer length
122 | *
123 | */
124 | void vMBMasterErrorCBRespondTimeout(UCHAR ucDestAddress, const UCHAR* pucPDUData,
125 | USHORT ucPDULength) {
126 | /**
127 | * @note This code is use OS's event mechanism for modbus master protocol stack.
128 | * If you don't use OS, you can change it.
129 | */
130 | rt_event_send(&xMasterOsEvent, EV_MASTER_ERROR_RESPOND_TIMEOUT);
131 |
132 | /* You can add your code under here. */
133 |
134 | }
135 |
136 | /**
137 | * This is modbus master receive data error process callback function.
138 | * @note There functions will block modbus master poll while execute OS waiting.
139 | * So,for real-time of system.Do not execute too much waiting process.
140 | *
141 | * @param ucDestAddress destination salve address
142 | * @param pucPDUData PDU buffer data
143 | * @param ucPDULength PDU buffer length
144 | *
145 | */
146 | void vMBMasterErrorCBReceiveData(UCHAR ucDestAddress, const UCHAR* pucPDUData,
147 | USHORT ucPDULength) {
148 | /**
149 | * @note This code is use OS's event mechanism for modbus master protocol stack.
150 | * If you don't use OS, you can change it.
151 | */
152 | rt_event_send(&xMasterOsEvent, EV_MASTER_ERROR_RECEIVE_DATA);
153 |
154 | /* You can add your code under here. */
155 |
156 | }
157 |
158 | /**
159 | * This is modbus master execute function error process callback function.
160 | * @note There functions will block modbus master poll while execute OS waiting.
161 | * So,for real-time of system.Do not execute too much waiting process.
162 | *
163 | * @param ucDestAddress destination salve address
164 | * @param pucPDUData PDU buffer data
165 | * @param ucPDULength PDU buffer length
166 | *
167 | */
168 | void vMBMasterErrorCBExecuteFunction(UCHAR ucDestAddress, const UCHAR* pucPDUData,
169 | USHORT ucPDULength) {
170 | /**
171 | * @note This code is use OS's event mechanism for modbus master protocol stack.
172 | * If you don't use OS, you can change it.
173 | */
174 | rt_event_send(&xMasterOsEvent, EV_MASTER_ERROR_EXECUTE_FUNCTION);
175 |
176 | /* You can add your code under here. */
177 |
178 | }
179 |
180 | /**
181 | * This is modbus master request process success callback function.
182 | * @note There functions will block modbus master poll while execute OS waiting.
183 | * So,for real-time of system.Do not execute too much waiting process.
184 | *
185 | */
186 | void vMBMasterCBRequestScuuess( void ) {
187 | /**
188 | * @note This code is use OS's event mechanism for modbus master protocol stack.
189 | * If you don't use OS, you can change it.
190 | */
191 | rt_event_send(&xMasterOsEvent, EV_MASTER_PROCESS_SUCESS);
192 |
193 | /* You can add your code under here. */
194 |
195 | }
196 |
197 | /**
198 | * This function is wait for modbus master request finish and return result.
199 | * Waiting result include request process success, request respond timeout,
200 | * receive data error and execute function error.You can use the above callback function.
201 | * @note If you are use OS, you can use OS's event mechanism. Otherwise you have to run
202 | * much user custom delay for waiting.
203 | *
204 | * @return request error code
205 | */
206 | eMBMasterReqErrCode eMBMasterWaitRequestFinish( void ) {
207 | eMBMasterReqErrCode eErrStatus = MB_MRE_NO_ERR;
208 | rt_uint32_t recvedEvent;
209 | /* waiting for OS event */
210 | rt_event_recv(&xMasterOsEvent,
211 | EV_MASTER_PROCESS_SUCESS | EV_MASTER_ERROR_RESPOND_TIMEOUT
212 | | EV_MASTER_ERROR_RECEIVE_DATA
213 | | EV_MASTER_ERROR_EXECUTE_FUNCTION,
214 | RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER,
215 | &recvedEvent);
216 | switch (recvedEvent)
217 | {
218 | case EV_MASTER_PROCESS_SUCESS:
219 | break;
220 | case EV_MASTER_ERROR_RESPOND_TIMEOUT:
221 | {
222 | eErrStatus = MB_MRE_TIMEDOUT;
223 | break;
224 | }
225 | case EV_MASTER_ERROR_RECEIVE_DATA:
226 | {
227 | eErrStatus = MB_MRE_REV_DATA;
228 | break;
229 | }
230 | case EV_MASTER_ERROR_EXECUTE_FUNCTION:
231 | {
232 | eErrStatus = MB_MRE_EXE_FUN;
233 | break;
234 | }
235 | }
236 | return eErrStatus;
237 | }
238 |
239 | #endif
240 |
--------------------------------------------------------------------------------
/MIddleware/FreeModbus/port/rtt/portserial.c:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeModbus Libary: RT-Thread Port
3 | * Copyright (C) 2013 Armink
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | *
19 | * File: $Id: portserial.c,v 1.60 2013/08/13 15:07:05 Armink $
20 | */
21 |
22 | #include "port.h"
23 |
24 | /* ----------------------- Modbus includes ----------------------------------*/
25 | #include "mb.h"
26 | #include "mbport.h"
27 | #include "rtdevice.h"
28 | #include "bsp.h"
29 |
30 | /* ----------------------- Static variables ---------------------------------*/
31 | ALIGN(RT_ALIGN_SIZE)
32 | /* software simulation serial transmit IRQ handler thread stack */
33 | static rt_uint8_t serial_soft_trans_irq_stack[512];
34 | /* software simulation serial transmit IRQ handler thread */
35 | static struct rt_thread thread_serial_soft_trans_irq;
36 | /* serial event */
37 | static struct rt_event event_serial;
38 | /* modbus slave serial device */
39 | static rt_serial_t *serial;
40 |
41 | /* ----------------------- Defines ------------------------------------------*/
42 | /* serial transmit event */
43 | #define EVENT_SERIAL_TRANS_START (1<<0)
44 |
45 | /* ----------------------- static functions ---------------------------------*/
46 | static void prvvUARTTxReadyISR(void);
47 | static void prvvUARTRxISR(void);
48 | static rt_err_t serial_rx_ind(rt_device_t dev, rt_size_t size);
49 | static void serial_soft_trans_irq(void* parameter);
50 |
51 | /* ----------------------- Start implementation -----------------------------*/
52 | BOOL xMBPortSerialInit(UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits,
53 | eMBParity eParity)
54 | {
55 | /**
56 | * set 485 mode receive and transmit control IO
57 | * @note MODBUS_SLAVE_RT_CONTROL_PIN_INDEX need be defined by user
58 | */
59 | rt_pin_mode(MODBUS_SLAVE_RT_CONTROL_PIN_INDEX, PIN_MODE_OUTPUT);
60 |
61 | /* set serial name */
62 | if (ucPORT == 1) {
63 | #if defined(RT_USING_UART1) || defined(RT_USING_REMAP_UART1)
64 | extern struct rt_serial_device serial1;
65 | serial = &serial1;
66 | #endif
67 | } else if (ucPORT == 2) {
68 | #if defined(RT_USING_UART2)
69 | extern struct rt_serial_device serial2;
70 | serial = &serial2;
71 | #endif
72 | } else if (ucPORT == 3) {
73 | #if defined(RT_USING_UART3)
74 | extern struct rt_serial_device serial3;
75 | serial = &serial3;
76 | #endif
77 | }
78 | /* set serial configure parameter */
79 | serial->config.baud_rate = ulBaudRate;
80 | serial->config.stop_bits = STOP_BITS_1;
81 | switch(eParity){
82 | case MB_PAR_NONE: {
83 | serial->config.data_bits = DATA_BITS_8;
84 | serial->config.parity = PARITY_NONE;
85 | break;
86 | }
87 | case MB_PAR_ODD: {
88 | serial->config.data_bits = DATA_BITS_9;
89 | serial->config.parity = PARITY_ODD;
90 | break;
91 | }
92 | case MB_PAR_EVEN: {
93 | serial->config.data_bits = DATA_BITS_9;
94 | serial->config.parity = PARITY_EVEN;
95 | break;
96 | }
97 | }
98 | /* set serial configure */
99 | serial->ops->configure(serial, &(serial->config));
100 |
101 | /* open serial device */
102 | if (!serial->parent.open(&serial->parent,
103 | RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX )) {
104 | serial->parent.rx_indicate = serial_rx_ind;
105 | } else {
106 | return FALSE;
107 | }
108 |
109 | /* software initialize */
110 | rt_event_init(&event_serial, "slave event", RT_IPC_FLAG_PRIO);
111 | rt_thread_init(&thread_serial_soft_trans_irq,
112 | "slave trans",
113 | serial_soft_trans_irq,
114 | RT_NULL,
115 | serial_soft_trans_irq_stack,
116 | sizeof(serial_soft_trans_irq_stack),
117 | 10, 5);
118 | rt_thread_startup(&thread_serial_soft_trans_irq);
119 |
120 | return TRUE;
121 | }
122 |
123 | void vMBPortSerialEnable(BOOL xRxEnable, BOOL xTxEnable)
124 | {
125 | rt_uint32_t recved_event;
126 | if (xRxEnable)
127 | {
128 | /* enable RX interrupt */
129 | serial->ops->control(serial, RT_DEVICE_CTRL_SET_INT, (void *)RT_DEVICE_FLAG_INT_RX);
130 | /* switch 485 to receive mode */
131 | rt_pin_write(MODBUS_SLAVE_RT_CONTROL_PIN_INDEX, PIN_LOW);
132 | }
133 | else
134 | {
135 | /* switch 485 to transmit mode */
136 | rt_pin_write(MODBUS_SLAVE_RT_CONTROL_PIN_INDEX, PIN_HIGH);
137 | /* disable RX interrupt */
138 | serial->ops->control(serial, RT_DEVICE_CTRL_CLR_INT, (void *)RT_DEVICE_FLAG_INT_RX);
139 | }
140 | if (xTxEnable)
141 | {
142 | /* start serial transmit */
143 | rt_event_send(&event_serial, EVENT_SERIAL_TRANS_START);
144 | }
145 | else
146 | {
147 | /* stop serial transmit */
148 | rt_event_recv(&event_serial, EVENT_SERIAL_TRANS_START,
149 | RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, 0,
150 | &recved_event);
151 | }
152 | }
153 |
154 | void vMBPortClose(void)
155 | {
156 | serial->parent.close(&(serial->parent));
157 | }
158 |
159 | BOOL xMBPortSerialPutByte(CHAR ucByte)
160 | {
161 | serial->parent.write(&(serial->parent), 0, &ucByte, 1);
162 | return TRUE;
163 | }
164 |
165 | BOOL xMBPortSerialGetByte(CHAR * pucByte)
166 | {
167 | serial->parent.read(&(serial->parent), 0, pucByte, 1);
168 | return TRUE;
169 | }
170 |
171 | /*
172 | * Create an interrupt handler for the transmit buffer empty interrupt
173 | * (or an equivalent) for your target processor. This function should then
174 | * call pxMBFrameCBTransmitterEmpty( ) which tells the protocol stack that
175 | * a new character can be sent. The protocol stack will then call
176 | * xMBPortSerialPutByte( ) to send the character.
177 | */
178 | void prvvUARTTxReadyISR(void)
179 | {
180 | pxMBFrameCBTransmitterEmpty();
181 | }
182 |
183 | /*
184 | * Create an interrupt handler for the receive interrupt for your target
185 | * processor. This function should then call pxMBFrameCBByteReceived( ). The
186 | * protocol stack will then call xMBPortSerialGetByte( ) to retrieve the
187 | * character.
188 | */
189 | void prvvUARTRxISR(void)
190 | {
191 | pxMBFrameCBByteReceived();
192 | }
193 |
194 | /**
195 | * Software simulation serial transmit IRQ handler.
196 | *
197 | * @param parameter parameter
198 | */
199 | static void serial_soft_trans_irq(void* parameter) {
200 | rt_uint32_t recved_event;
201 | while (1)
202 | {
203 | /* waiting for serial transmit start */
204 | rt_event_recv(&event_serial, EVENT_SERIAL_TRANS_START, RT_EVENT_FLAG_OR,
205 | RT_WAITING_FOREVER, &recved_event);
206 | /* execute modbus callback */
207 | prvvUARTTxReadyISR();
208 | }
209 | }
210 |
211 | /**
212 | * This function is serial receive callback function
213 | *
214 | * @param dev the device of serial
215 | * @param size the data size that receive
216 | *
217 | * @return return RT_EOK
218 | */
219 | static rt_err_t serial_rx_ind(rt_device_t dev, rt_size_t size) {
220 | prvvUARTRxISR();
221 | return RT_EOK;
222 | }
223 |
--------------------------------------------------------------------------------
/MIddleware/FreeModbus/port/rtt/portserial_m.c:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeModbus Libary: RT-Thread Port
3 | * Copyright (C) 2013 Armink
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | *
19 | * File: $Id: portserial_m.c,v 1.60 2013/08/13 15:07:05 Armink add Master Functions $
20 | */
21 |
22 | #include "port.h"
23 |
24 | /* ----------------------- Modbus includes ----------------------------------*/
25 | #include "mb.h"
26 | #include "mbport.h"
27 | #include "rtdevice.h"
28 | #include "bsp.h"
29 |
30 | #if MB_MASTER_RTU_ENABLED > 0 || MB_MASTER_ASCII_ENABLED > 0
31 | /* ----------------------- Static variables ---------------------------------*/
32 | ALIGN(RT_ALIGN_SIZE)
33 | /* software simulation serial transmit IRQ handler thread stack */
34 | static rt_uint8_t serial_soft_trans_irq_stack[512];
35 | /* software simulation serial transmit IRQ handler thread */
36 | static struct rt_thread thread_serial_soft_trans_irq;
37 | /* serial event */
38 | static struct rt_event event_serial;
39 | /* modbus master serial device */
40 | static rt_serial_t *serial;
41 |
42 | /* ----------------------- Defines ------------------------------------------*/
43 | /* serial transmit event */
44 | #define EVENT_SERIAL_TRANS_START (1<<0)
45 |
46 | /* ----------------------- static functions ---------------------------------*/
47 | static void prvvUARTTxReadyISR(void);
48 | static void prvvUARTRxISR(void);
49 | static rt_err_t serial_rx_ind(rt_device_t dev, rt_size_t size);
50 | static void serial_soft_trans_irq(void* parameter);
51 |
52 | /* ----------------------- Start implementation -----------------------------*/
53 | BOOL xMBMasterPortSerialInit(UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits,
54 | eMBParity eParity)
55 | {
56 | /**
57 | * set 485 mode receive and transmit control IO
58 | * @note MODBUS_MASTER_RT_CONTROL_PIN_INDEX need be defined by user
59 | */
60 | rt_pin_mode(MODBUS_MASTER_RT_CONTROL_PIN_INDEX, PIN_MODE_OUTPUT);
61 |
62 | /* set serial name */
63 | if (ucPORT == 1) {
64 | #if defined(RT_USING_UART1) || defined(RT_USING_REMAP_UART1)
65 | extern struct rt_serial_device serial1;
66 | serial = &serial1;
67 | #endif
68 | } else if (ucPORT == 2) {
69 | #if defined(RT_USING_UART2)
70 | extern struct rt_serial_device serial2;
71 | serial = &serial2;
72 | #endif
73 | } else if (ucPORT == 3) {
74 | #if defined(RT_USING_UART3)
75 | extern struct rt_serial_device serial3;
76 | serial = &serial3;
77 | #endif
78 | }
79 | /* set serial configure parameter */
80 | serial->config.baud_rate = ulBaudRate;
81 | serial->config.stop_bits = STOP_BITS_1;
82 | switch(eParity){
83 | case MB_PAR_NONE: {
84 | serial->config.data_bits = DATA_BITS_8;
85 | serial->config.parity = PARITY_NONE;
86 | break;
87 | }
88 | case MB_PAR_ODD: {
89 | serial->config.data_bits = DATA_BITS_9;
90 | serial->config.parity = PARITY_ODD;
91 | break;
92 | }
93 | case MB_PAR_EVEN: {
94 | serial->config.data_bits = DATA_BITS_9;
95 | serial->config.parity = PARITY_EVEN;
96 | break;
97 | }
98 | }
99 | /* set serial configure */
100 | serial->ops->configure(serial, &(serial->config));
101 |
102 | /* open serial device */
103 | if (!serial->parent.open(&serial->parent,
104 | RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX )) {
105 | serial->parent.rx_indicate = serial_rx_ind;
106 | } else {
107 | return FALSE;
108 | }
109 |
110 | /* software initialize */
111 | rt_event_init(&event_serial, "master event", RT_IPC_FLAG_PRIO);
112 | rt_thread_init(&thread_serial_soft_trans_irq,
113 | "master trans",
114 | serial_soft_trans_irq,
115 | RT_NULL,
116 | serial_soft_trans_irq_stack,
117 | sizeof(serial_soft_trans_irq_stack),
118 | 10, 5);
119 | rt_thread_startup(&thread_serial_soft_trans_irq);
120 |
121 | return TRUE;
122 | }
123 |
124 | void vMBMasterPortSerialEnable(BOOL xRxEnable, BOOL xTxEnable)
125 | {
126 | rt_uint32_t recved_event;
127 | if (xRxEnable)
128 | {
129 | /* enable RX interrupt */
130 | serial->ops->control(serial, RT_DEVICE_CTRL_SET_INT, (void *)RT_DEVICE_FLAG_INT_RX);
131 | /* switch 485 to receive mode */
132 | rt_pin_write(MODBUS_MASTER_RT_CONTROL_PIN_INDEX, PIN_LOW);
133 | }
134 | else
135 | {
136 | /* switch 485 to transmit mode */
137 | rt_pin_write(MODBUS_MASTER_RT_CONTROL_PIN_INDEX, PIN_HIGH);
138 | /* disable RX interrupt */
139 | serial->ops->control(serial, RT_DEVICE_CTRL_CLR_INT, (void *)RT_DEVICE_FLAG_INT_RX);
140 | }
141 | if (xTxEnable)
142 | {
143 | /* start serial transmit */
144 | rt_event_send(&event_serial, EVENT_SERIAL_TRANS_START);
145 | }
146 | else
147 | {
148 | /* stop serial transmit */
149 | rt_event_recv(&event_serial, EVENT_SERIAL_TRANS_START,
150 | RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, 0,
151 | &recved_event);
152 | }
153 | }
154 |
155 | void vMBMasterPortClose(void)
156 | {
157 | serial->parent.close(&(serial->parent));
158 | }
159 |
160 | BOOL xMBMasterPortSerialPutByte(CHAR ucByte)
161 | {
162 | serial->parent.write(&(serial->parent), 0, &ucByte, 1);
163 | return TRUE;
164 | }
165 |
166 | BOOL xMBMasterPortSerialGetByte(CHAR * pucByte)
167 | {
168 | serial->parent.read(&(serial->parent), 0, pucByte, 1);
169 | return TRUE;
170 | }
171 |
172 | /*
173 | * Create an interrupt handler for the transmit buffer empty interrupt
174 | * (or an equivalent) for your target processor. This function should then
175 | * call pxMBFrameCBTransmitterEmpty( ) which tells the protocol stack that
176 | * a new character can be sent. The protocol stack will then call
177 | * xMBPortSerialPutByte( ) to send the character.
178 | */
179 | void prvvUARTTxReadyISR(void)
180 | {
181 | pxMBMasterFrameCBTransmitterEmpty();
182 | }
183 |
184 | /*
185 | * Create an interrupt handler for the receive interrupt for your target
186 | * processor. This function should then call pxMBFrameCBByteReceived( ). The
187 | * protocol stack will then call xMBPortSerialGetByte( ) to retrieve the
188 | * character.
189 | */
190 | void prvvUARTRxISR(void)
191 | {
192 | pxMBMasterFrameCBByteReceived();
193 | }
194 |
195 | /**
196 | * Software simulation serial transmit IRQ handler.
197 | *
198 | * @param parameter parameter
199 | */
200 | static void serial_soft_trans_irq(void* parameter) {
201 | rt_uint32_t recved_event;
202 | while (1)
203 | {
204 | /* waiting for serial transmit start */
205 | rt_event_recv(&event_serial, EVENT_SERIAL_TRANS_START, RT_EVENT_FLAG_OR,
206 | RT_WAITING_FOREVER, &recved_event);
207 | /* execute modbus callback */
208 | prvvUARTTxReadyISR();
209 | }
210 | }
211 |
212 | /**
213 | * This function is serial receive callback function
214 | *
215 | * @param dev the device of serial
216 | * @param size the data size that receive
217 | *
218 | * @return return RT_EOK
219 | */
220 | static rt_err_t serial_rx_ind(rt_device_t dev, rt_size_t size) {
221 | prvvUARTRxISR();
222 | return RT_EOK;
223 | }
224 |
225 | #endif
226 |
--------------------------------------------------------------------------------
/MIddleware/FreeModbus/port/rtt/porttimer.c:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeModbus Libary: RT-Thread Port
3 | * Copyright (C) 2013 Armink
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | *
19 | * File: $Id: porttimer.c,v 1.60 2013/08/13 15:07:05 Armink $
20 | */
21 |
22 | /* ----------------------- Platform includes --------------------------------*/
23 | #include "port.h"
24 |
25 | /* ----------------------- Modbus includes ----------------------------------*/
26 | #include "mb.h"
27 | #include "mbport.h"
28 |
29 | /* ----------------------- static functions ---------------------------------*/
30 | static struct rt_timer timer;
31 | static void prvvTIMERExpiredISR(void);
32 | static void timer_timeout_ind(void* parameter);
33 |
34 | /* ----------------------- Start implementation -----------------------------*/
35 | BOOL xMBPortTimersInit(USHORT usTim1Timerout50us)
36 | {
37 | rt_timer_init(&timer, "slave timer",
38 | timer_timeout_ind, /* bind timeout callback function */
39 | RT_NULL,
40 | (50 * usTim1Timerout50us) / (1000 * 1000 / RT_TICK_PER_SECOND) + 1,
41 | RT_TIMER_FLAG_ONE_SHOT); /* one shot */
42 | return TRUE;
43 | }
44 |
45 | void vMBPortTimersEnable()
46 | {
47 | rt_timer_start(&timer);
48 | }
49 |
50 | void vMBPortTimersDisable()
51 | {
52 | rt_timer_stop(&timer);
53 | }
54 |
55 | void prvvTIMERExpiredISR(void)
56 | {
57 | (void) pxMBPortCBTimerExpired();
58 | }
59 |
60 | static void timer_timeout_ind(void* parameter)
61 | {
62 | prvvTIMERExpiredISR();
63 | }
64 |
--------------------------------------------------------------------------------
/MIddleware/FreeModbus/port/rtt/porttimer_m.c:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeModbus Libary: RT-Thread Port
3 | * Copyright (C) 2013 Armink
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | *
19 | * File: $Id: porttimer_m.c,v 1.60 2013/08/13 15:07:05 Armink add Master Functions$
20 | */
21 |
22 | /* ----------------------- Platform includes --------------------------------*/
23 | #include "port.h"
24 |
25 | /* ----------------------- Modbus includes ----------------------------------*/
26 | #include "mb.h"
27 | #include "mb_m.h"
28 | #include "mbport.h"
29 |
30 | #if MB_MASTER_RTU_ENABLED > 0 || MB_MASTER_ASCII_ENABLED > 0
31 | /* ----------------------- Variables ----------------------------------------*/
32 | static USHORT usT35TimeOut50us;
33 | static struct rt_timer timer;
34 | static void prvvTIMERExpiredISR(void);
35 | static void timer_timeout_ind(void* parameter);
36 |
37 | /* ----------------------- static functions ---------------------------------*/
38 | static void prvvTIMERExpiredISR(void);
39 |
40 | /* ----------------------- Start implementation -----------------------------*/
41 | BOOL xMBMasterPortTimersInit(USHORT usTimeOut50us)
42 | {
43 | /* backup T35 ticks */
44 | usT35TimeOut50us = usTimeOut50us;
45 |
46 | rt_timer_init(&timer, "master timer",
47 | timer_timeout_ind, /* bind timeout callback function */
48 | RT_NULL,
49 | (50 * usT35TimeOut50us) / (1000 * 1000 / RT_TICK_PER_SECOND) + 1,
50 | RT_TIMER_FLAG_ONE_SHOT); /* one shot */
51 |
52 | return TRUE;
53 | }
54 |
55 | void vMBMasterPortTimersT35Enable()
56 | {
57 | rt_tick_t timer_tick = (50 * usT35TimeOut50us)
58 | / (1000 * 1000 / RT_TICK_PER_SECOND);
59 |
60 | /* Set current timer mode, don't change it.*/
61 | vMBMasterSetCurTimerMode(MB_TMODE_T35);
62 |
63 | rt_timer_control(&timer, RT_TIMER_CTRL_SET_TIME, &timer_tick);
64 |
65 | rt_timer_start(&timer);
66 | }
67 |
68 | void vMBMasterPortTimersConvertDelayEnable()
69 | {
70 | rt_tick_t timer_tick = MB_MASTER_DELAY_MS_CONVERT * RT_TICK_PER_SECOND / 1000;
71 |
72 | /* Set current timer mode, don't change it.*/
73 | vMBMasterSetCurTimerMode(MB_TMODE_CONVERT_DELAY);
74 |
75 | rt_timer_control(&timer, RT_TIMER_CTRL_SET_TIME, &timer_tick);
76 |
77 | rt_timer_start(&timer);
78 | }
79 |
80 | void vMBMasterPortTimersRespondTimeoutEnable()
81 | {
82 | rt_tick_t timer_tick = MB_MASTER_TIMEOUT_MS_RESPOND * RT_TICK_PER_SECOND / 1000;
83 |
84 | /* Set current timer mode, don't change it.*/
85 | vMBMasterSetCurTimerMode(MB_TMODE_RESPOND_TIMEOUT);
86 |
87 | rt_timer_control(&timer, RT_TIMER_CTRL_SET_TIME, &timer_tick);
88 |
89 | rt_timer_start(&timer);
90 | }
91 |
92 | void vMBMasterPortTimersDisable()
93 | {
94 | rt_timer_stop(&timer);
95 | }
96 |
97 | void prvvTIMERExpiredISR(void)
98 | {
99 | (void) pxMBMasterPortCBTimerExpired();
100 | }
101 |
102 | static void timer_timeout_ind(void* parameter)
103 | {
104 | prvvTIMERExpiredISR();
105 | }
106 |
107 | #endif
108 |
--------------------------------------------------------------------------------
/MIddleware/FreeModbus/port/user_mb_app.h:
--------------------------------------------------------------------------------
1 | #ifndef USER_APP
2 | #define USER_APP
3 | /* ----------------------- Modbus includes ----------------------------------*/
4 | #include "mb.h"
5 | #include "mb_m.h"
6 | #include "mbconfig.h"
7 | #include "mbframe.h"
8 | #include "mbutils.h"
9 |
10 | /* -----------------------Slave Defines -------------------------------------*/
11 | #define S_DISCRETE_INPUT_START 0
12 | #define S_DISCRETE_INPUT_NDISCRETES 16
13 | #define S_COIL_START 0
14 | #define S_COIL_NCOILS 64
15 | #define S_REG_INPUT_START 0
16 | #define S_REG_INPUT_NREGS 100
17 | #define S_REG_HOLDING_START 0
18 | #define S_REG_HOLDING_NREGS 100
19 | /* salve mode: holding register's all address */
20 | #define S_HD_RESERVE 0
21 | #define S_HD_CPU_USAGE_MAJOR 1
22 | #define S_HD_CPU_USAGE_MINOR 2
23 | /* salve mode: input register's all address */
24 | #define S_IN_RESERVE 0
25 | /* salve mode: coil's all address */
26 | #define S_CO_RESERVE 0
27 | /* salve mode: discrete's all address */
28 | #define S_DI_RESERVE 0
29 |
30 | /* -----------------------Master Defines -------------------------------------*/
31 | #define M_DISCRETE_INPUT_START 0
32 | #define M_DISCRETE_INPUT_NDISCRETES 16
33 | #define M_COIL_START 0
34 | #define M_COIL_NCOILS 64
35 | #define M_REG_INPUT_START 0
36 | #define M_REG_INPUT_NREGS 100
37 | #define M_REG_HOLDING_START 0
38 | #define M_REG_HOLDING_NREGS 100
39 | /* master mode: holding register's all address */
40 | #define M_HD_RESERVE 0
41 | /* master mode: input register's all address */
42 | #define M_IN_RESERVE 0
43 | /* master mode: coil's all address */
44 | #define M_CO_RESERVE 0
45 | /* master mode: discrete's all address */
46 | #define M_DI_RESERVE 0
47 |
48 |
49 |
50 | extern USHORT usSRegHoldBuf[];
51 | #endif
52 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # FreeModbus_Slave-Master-NOOS-STM32
2 | freemodbus stm32 hal master slave noos
3 | # Fork from
4 | https://github.com/armink/FreeModbus_Slave-Master-RTT-STM32
5 |
6 | becaule no os,only use poll and block to realize a simple event engine.
7 | # RS485
8 | * uart(pa9,pa10)
9 | * max485 tx/rx control pin (pa8)
10 | # Build
11 | * the project based of stm32f103c8,use the stm32cubemx to build the project
12 | * the project use IAR,you can use other IDE or makefile to build the project,just config the stm32cubemx
13 |
14 | # Stm32cubemx
15 | download link:http://www.st.com/zh/development-tools/stm32cubemx.html
16 | the *.ico file is stm32cubemx config file.
17 |
--------------------------------------------------------------------------------
/Src/gpio.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * File Name : gpio.c
4 | * Description : This file provides code for the configuration
5 | * of all used GPIO pins.
6 | ******************************************************************************
7 | ** This notice applies to any and all portions of this file
8 | * that are not between comment pairs USER CODE BEGIN and
9 | * USER CODE END. Other portions of this file, whether
10 | * inserted by the user or by software development tools
11 | * are owned by their respective copyright owners.
12 | *
13 | * COPYRIGHT(c) 2018 STMicroelectronics
14 | *
15 | * Redistribution and use in source and binary forms, with or without modification,
16 | * are permitted provided that the following conditions are met:
17 | * 1. Redistributions of source code must retain the above copyright notice,
18 | * this list of conditions and the following disclaimer.
19 | * 2. Redistributions in binary form must reproduce the above copyright notice,
20 | * this list of conditions and the following disclaimer in the documentation
21 | * and/or other materials provided with the distribution.
22 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
23 | * may be used to endorse or promote products derived from this software
24 | * without specific prior written permission.
25 | *
26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
34 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | ******************************************************************************
38 | */
39 |
40 | /* Includes ------------------------------------------------------------------*/
41 | #include "gpio.h"
42 | /* USER CODE BEGIN 0 */
43 |
44 | /* USER CODE END 0 */
45 |
46 | /*----------------------------------------------------------------------------*/
47 | /* Configure GPIO */
48 | /*----------------------------------------------------------------------------*/
49 | /* USER CODE BEGIN 1 */
50 |
51 | /* USER CODE END 1 */
52 |
53 | /** Configure pins as
54 | * Analog
55 | * Input
56 | * Output
57 | * EVENT_OUT
58 | * EXTI
59 | */
60 | void MX_GPIO_Init(void)
61 | {
62 |
63 | GPIO_InitTypeDef GPIO_InitStruct;
64 |
65 | /* GPIO Ports Clock Enable */
66 | __HAL_RCC_GPIOA_CLK_ENABLE();
67 | __HAL_RCC_GPIOB_CLK_ENABLE();
68 |
69 | /*Configure GPIO pin Output Level */
70 | HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8|GPIO_PIN_15, GPIO_PIN_RESET);
71 |
72 | /*Configure GPIO pin Output Level */
73 | HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3|GPIO_PIN_4, GPIO_PIN_RESET);
74 |
75 | /*Configure GPIO pins : PA8 PA15 */
76 | GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_15;
77 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
78 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
79 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
80 |
81 | /*Configure GPIO pins : PB3 PB4 */
82 | GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_4;
83 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
84 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
85 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
86 |
87 | }
88 |
89 | /* USER CODE BEGIN 2 */
90 |
91 | /* USER CODE END 2 */
92 |
93 | /**
94 | * @}
95 | */
96 |
97 | /**
98 | * @}
99 | */
100 |
101 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
102 |
--------------------------------------------------------------------------------
/Src/main.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file : main.c
4 | * @brief : Main program body
5 | ******************************************************************************
6 | ** This notice applies to any and all portions of this file
7 | * that are not between comment pairs USER CODE BEGIN and
8 | * USER CODE END. Other portions of this file, whether
9 | * inserted by the user or by software development tools
10 | * are owned by their respective copyright owners.
11 | *
12 | * COPYRIGHT(c) 2018 STMicroelectronics
13 | *
14 | * Redistribution and use in source and binary forms, with or without modification,
15 | * are permitted provided that the following conditions are met:
16 | * 1. Redistributions of source code must retain the above copyright notice,
17 | * this list of conditions and the following disclaimer.
18 | * 2. Redistributions in binary form must reproduce the above copyright notice,
19 | * this list of conditions and the following disclaimer in the documentation
20 | * and/or other materials provided with the distribution.
21 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
22 | * may be used to endorse or promote products derived from this software
23 | * without specific prior written permission.
24 | *
25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 | *
36 | ******************************************************************************
37 | */
38 | /* Includes ------------------------------------------------------------------*/
39 | #include "main.h"
40 | #include "stm32f1xx_hal.h"
41 | #include "tim.h"
42 | #include "usart.h"
43 | #include "gpio.h"
44 |
45 | /* USER CODE BEGIN Includes */
46 | #include "bsp.h"
47 | #include "mb_m.h"
48 | #include "user_mb_app.h"
49 | /* USER CODE END Includes */
50 |
51 | /* Private variables ---------------------------------------------------------*/
52 |
53 | /* USER CODE BEGIN PV */
54 | /* Private variables ---------------------------------------------------------*/
55 |
56 | /* USER CODE END PV */
57 |
58 | /* Private function prototypes -----------------------------------------------*/
59 | void SystemClock_Config(void);
60 |
61 | /* USER CODE BEGIN PFP */
62 | /* Private function prototypes -----------------------------------------------*/
63 |
64 | /* USER CODE END PFP */
65 |
66 | /* USER CODE BEGIN 0 */
67 | __IO eMBMasterReqErrCode err;
68 | /* USER CODE END 0 */
69 |
70 | /**
71 | * @brief The application entry point.
72 | *
73 | * @retval None
74 | */
75 | int main(void)
76 | {
77 | /* USER CODE BEGIN 1 */
78 |
79 | /* USER CODE END 1 */
80 |
81 | /* MCU Configuration----------------------------------------------------------*/
82 |
83 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
84 | HAL_Init();
85 |
86 | /* USER CODE BEGIN Init */
87 |
88 | /* USER CODE END Init */
89 |
90 | /* Configure the system clock */
91 | SystemClock_Config();
92 |
93 | /* USER CODE BEGIN SysInit */
94 |
95 | /* USER CODE END SysInit */
96 |
97 | /* Initialize all configured peripherals */
98 | MX_GPIO_Init();
99 | MX_USART1_UART_Init();
100 | MX_TIM3_Init();
101 | /* USER CODE BEGIN 2 */
102 | bsp_init();
103 | eMBMasterInit(MB_RTU,0,115200,MB_PAR_NONE);
104 | eMBMasterEnable();
105 | err=eMBMasterReqReadInputRegister(0x01,0x0000,2,200);
106 | err=eMBMasterReqReadHoldingRegister(0x01,0x0000,4,200);
107 | err=eMBMasterReqReadDiscreteInputs(0x01,0x0000,16,200);
108 | err=eMBMasterReqReadCoils(0x01,0x0000,16,200);
109 | /* USER CODE END 2 */
110 |
111 | /* Infinite loop */
112 | /* USER CODE BEGIN WHILE */
113 | while (1)
114 | {
115 |
116 | /* USER CODE END WHILE */
117 |
118 | /* USER CODE BEGIN 3 */
119 | HAL_GPIO_TogglePin(LED_R_PORT,LED_R_PIN);
120 | HAL_Delay(1000);
121 | }
122 | /* USER CODE END 3 */
123 |
124 | }
125 |
126 | /**
127 | * @brief System Clock Configuration
128 | * @retval None
129 | */
130 | void SystemClock_Config(void)
131 | {
132 |
133 | RCC_OscInitTypeDef RCC_OscInitStruct;
134 | RCC_ClkInitTypeDef RCC_ClkInitStruct;
135 |
136 | /**Initializes the CPU, AHB and APB busses clocks
137 | */
138 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
139 | RCC_OscInitStruct.HSIState = RCC_HSI_ON;
140 | RCC_OscInitStruct.HSICalibrationValue = 16;
141 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
142 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2;
143 | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16;
144 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
145 | {
146 | _Error_Handler(__FILE__, __LINE__);
147 | }
148 |
149 | /**Initializes the CPU, AHB and APB busses clocks
150 | */
151 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
152 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
153 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
154 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
155 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
156 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
157 |
158 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
159 | {
160 | _Error_Handler(__FILE__, __LINE__);
161 | }
162 |
163 | /**Configure the Systick interrupt time
164 | */
165 | HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
166 |
167 | /**Configure the Systick
168 | */
169 | HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
170 |
171 | /* SysTick_IRQn interrupt configuration */
172 | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
173 | }
174 |
175 | /* USER CODE BEGIN 4 */
176 |
177 | /* USER CODE END 4 */
178 |
179 | /**
180 | * @brief This function is executed in case of error occurrence.
181 | * @param file: The file name as string.
182 | * @param line: The line in file as a number.
183 | * @retval None
184 | */
185 | void _Error_Handler(char *file, int line)
186 | {
187 | /* USER CODE BEGIN Error_Handler_Debug */
188 | /* User can add his own implementation to report the HAL error return state */
189 | while(1)
190 | {
191 | }
192 | /* USER CODE END Error_Handler_Debug */
193 | }
194 |
195 | #ifdef USE_FULL_ASSERT
196 | /**
197 | * @brief Reports the name of the source file and the source line number
198 | * where the assert_param error has occurred.
199 | * @param file: pointer to the source file name
200 | * @param line: assert_param error line source number
201 | * @retval None
202 | */
203 | void assert_failed(uint8_t* file, uint32_t line)
204 | {
205 | /* USER CODE BEGIN 6 */
206 | /* User can add his own implementation to report the file name and line number,
207 | tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
208 | /* USER CODE END 6 */
209 | }
210 | #endif /* USE_FULL_ASSERT */
211 |
212 | /**
213 | * @}
214 | */
215 |
216 | /**
217 | * @}
218 | */
219 |
220 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
221 |
--------------------------------------------------------------------------------
/Src/stm32f1xx_hal_msp.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * File Name : stm32f1xx_hal_msp.c
4 | * Description : This file provides code for the MSP Initialization
5 | * and de-Initialization codes.
6 | ******************************************************************************
7 | ** This notice applies to any and all portions of this file
8 | * that are not between comment pairs USER CODE BEGIN and
9 | * USER CODE END. Other portions of this file, whether
10 | * inserted by the user or by software development tools
11 | * are owned by their respective copyright owners.
12 | *
13 | * COPYRIGHT(c) 2018 STMicroelectronics
14 | *
15 | * Redistribution and use in source and binary forms, with or without modification,
16 | * are permitted provided that the following conditions are met:
17 | * 1. Redistributions of source code must retain the above copyright notice,
18 | * this list of conditions and the following disclaimer.
19 | * 2. Redistributions in binary form must reproduce the above copyright notice,
20 | * this list of conditions and the following disclaimer in the documentation
21 | * and/or other materials provided with the distribution.
22 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
23 | * may be used to endorse or promote products derived from this software
24 | * without specific prior written permission.
25 | *
26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
34 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | ******************************************************************************
38 | */
39 | /* Includes ------------------------------------------------------------------*/
40 | #include "stm32f1xx_hal.h"
41 |
42 | extern void _Error_Handler(char *, int);
43 | /* USER CODE BEGIN 0 */
44 |
45 | /* USER CODE END 0 */
46 | /**
47 | * Initializes the Global MSP.
48 | */
49 | void HAL_MspInit(void)
50 | {
51 | /* USER CODE BEGIN MspInit 0 */
52 |
53 | /* USER CODE END MspInit 0 */
54 |
55 | __HAL_RCC_AFIO_CLK_ENABLE();
56 |
57 | HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
58 |
59 | /* System interrupt init*/
60 | /* MemoryManagement_IRQn interrupt configuration */
61 | HAL_NVIC_SetPriority(MemoryManagement_IRQn, 0, 0);
62 | /* BusFault_IRQn interrupt configuration */
63 | HAL_NVIC_SetPriority(BusFault_IRQn, 0, 0);
64 | /* UsageFault_IRQn interrupt configuration */
65 | HAL_NVIC_SetPriority(UsageFault_IRQn, 0, 0);
66 | /* SVCall_IRQn interrupt configuration */
67 | HAL_NVIC_SetPriority(SVCall_IRQn, 0, 0);
68 | /* DebugMonitor_IRQn interrupt configuration */
69 | HAL_NVIC_SetPriority(DebugMonitor_IRQn, 0, 0);
70 | /* PendSV_IRQn interrupt configuration */
71 | HAL_NVIC_SetPriority(PendSV_IRQn, 0, 0);
72 | /* SysTick_IRQn interrupt configuration */
73 | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
74 |
75 | /**NOJTAG: JTAG-DP Disabled and SW-DP Enabled
76 | */
77 | __HAL_AFIO_REMAP_SWJ_NOJTAG();
78 |
79 | /* USER CODE BEGIN MspInit 1 */
80 |
81 | /* USER CODE END MspInit 1 */
82 | }
83 |
84 | /* USER CODE BEGIN 1 */
85 |
86 | /* USER CODE END 1 */
87 |
88 | /**
89 | * @}
90 | */
91 |
92 | /**
93 | * @}
94 | */
95 |
96 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
97 |
--------------------------------------------------------------------------------
/Src/stm32f1xx_it.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f1xx_it.c
4 | * @brief Interrupt Service Routines.
5 | ******************************************************************************
6 | *
7 | * COPYRIGHT(c) 2018 STMicroelectronics
8 | *
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | * 1. Redistributions of source code must retain the above copyright notice,
12 | * this list of conditions and the following disclaimer.
13 | * 2. Redistributions in binary form must reproduce the above copyright notice,
14 | * this list of conditions and the following disclaimer in the documentation
15 | * and/or other materials provided with the distribution.
16 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
17 | * may be used to endorse or promote products derived from this software
18 | * without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 | *
31 | ******************************************************************************
32 | */
33 | /* Includes ------------------------------------------------------------------*/
34 | #include "stm32f1xx_hal.h"
35 | #include "stm32f1xx.h"
36 | #include "stm32f1xx_it.h"
37 |
38 | /* USER CODE BEGIN 0 */
39 | #include "mb.h"
40 | #include "mbport.h"
41 | /* USER CODE END 0 */
42 |
43 | /* External variables --------------------------------------------------------*/
44 | extern TIM_HandleTypeDef htim3;
45 | extern UART_HandleTypeDef huart1;
46 |
47 | /******************************************************************************/
48 | /* Cortex-M3 Processor Interruption and Exception Handlers */
49 | /******************************************************************************/
50 |
51 | /**
52 | * @brief This function handles Non maskable interrupt.
53 | */
54 | void NMI_Handler(void)
55 | {
56 | /* USER CODE BEGIN NonMaskableInt_IRQn 0 */
57 |
58 | /* USER CODE END NonMaskableInt_IRQn 0 */
59 | /* USER CODE BEGIN NonMaskableInt_IRQn 1 */
60 |
61 | /* USER CODE END NonMaskableInt_IRQn 1 */
62 | }
63 |
64 | /**
65 | * @brief This function handles Hard fault interrupt.
66 | */
67 | void HardFault_Handler(void)
68 | {
69 | /* USER CODE BEGIN HardFault_IRQn 0 */
70 |
71 | /* USER CODE END HardFault_IRQn 0 */
72 | while (1)
73 | {
74 | /* USER CODE BEGIN W1_HardFault_IRQn 0 */
75 | /* USER CODE END W1_HardFault_IRQn 0 */
76 | }
77 | /* USER CODE BEGIN HardFault_IRQn 1 */
78 |
79 | /* USER CODE END HardFault_IRQn 1 */
80 | }
81 |
82 | /**
83 | * @brief This function handles Memory management fault.
84 | */
85 | void MemManage_Handler(void)
86 | {
87 | /* USER CODE BEGIN MemoryManagement_IRQn 0 */
88 |
89 | /* USER CODE END MemoryManagement_IRQn 0 */
90 | while (1)
91 | {
92 | /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */
93 | /* USER CODE END W1_MemoryManagement_IRQn 0 */
94 | }
95 | /* USER CODE BEGIN MemoryManagement_IRQn 1 */
96 |
97 | /* USER CODE END MemoryManagement_IRQn 1 */
98 | }
99 |
100 | /**
101 | * @brief This function handles Prefetch fault, memory access fault.
102 | */
103 | void BusFault_Handler(void)
104 | {
105 | /* USER CODE BEGIN BusFault_IRQn 0 */
106 |
107 | /* USER CODE END BusFault_IRQn 0 */
108 | while (1)
109 | {
110 | /* USER CODE BEGIN W1_BusFault_IRQn 0 */
111 | /* USER CODE END W1_BusFault_IRQn 0 */
112 | }
113 | /* USER CODE BEGIN BusFault_IRQn 1 */
114 |
115 | /* USER CODE END BusFault_IRQn 1 */
116 | }
117 |
118 | /**
119 | * @brief This function handles Undefined instruction or illegal state.
120 | */
121 | void UsageFault_Handler(void)
122 | {
123 | /* USER CODE BEGIN UsageFault_IRQn 0 */
124 |
125 | /* USER CODE END UsageFault_IRQn 0 */
126 | while (1)
127 | {
128 | /* USER CODE BEGIN W1_UsageFault_IRQn 0 */
129 | /* USER CODE END W1_UsageFault_IRQn 0 */
130 | }
131 | /* USER CODE BEGIN UsageFault_IRQn 1 */
132 |
133 | /* USER CODE END UsageFault_IRQn 1 */
134 | }
135 |
136 | /**
137 | * @brief This function handles System service call via SWI instruction.
138 | */
139 | void SVC_Handler(void)
140 | {
141 | /* USER CODE BEGIN SVCall_IRQn 0 */
142 |
143 | /* USER CODE END SVCall_IRQn 0 */
144 | /* USER CODE BEGIN SVCall_IRQn 1 */
145 |
146 | /* USER CODE END SVCall_IRQn 1 */
147 | }
148 |
149 | /**
150 | * @brief This function handles Debug monitor.
151 | */
152 | void DebugMon_Handler(void)
153 | {
154 | /* USER CODE BEGIN DebugMonitor_IRQn 0 */
155 |
156 | /* USER CODE END DebugMonitor_IRQn 0 */
157 | /* USER CODE BEGIN DebugMonitor_IRQn 1 */
158 |
159 | /* USER CODE END DebugMonitor_IRQn 1 */
160 | }
161 |
162 | /**
163 | * @brief This function handles Pendable request for system service.
164 | */
165 | void PendSV_Handler(void)
166 | {
167 | /* USER CODE BEGIN PendSV_IRQn 0 */
168 |
169 | /* USER CODE END PendSV_IRQn 0 */
170 | /* USER CODE BEGIN PendSV_IRQn 1 */
171 |
172 | /* USER CODE END PendSV_IRQn 1 */
173 | }
174 |
175 | /**
176 | * @brief This function handles System tick timer.
177 | */
178 | void SysTick_Handler(void)
179 | {
180 | /* USER CODE BEGIN SysTick_IRQn 0 */
181 |
182 | /* USER CODE END SysTick_IRQn 0 */
183 | HAL_IncTick();
184 | HAL_SYSTICK_IRQHandler();
185 | /* USER CODE BEGIN SysTick_IRQn 1 */
186 |
187 | /* USER CODE END SysTick_IRQn 1 */
188 | }
189 |
190 | /******************************************************************************/
191 | /* STM32F1xx Peripheral Interrupt Handlers */
192 | /* Add here the Interrupt Handlers for the used peripherals. */
193 | /* For the available peripheral interrupt handler names, */
194 | /* please refer to the startup file (startup_stm32f1xx.s). */
195 | /******************************************************************************/
196 |
197 | /**
198 | * @brief This function handles TIM3 global interrupt.
199 | */
200 | void TIM3_IRQHandler(void)
201 | {
202 | /* USER CODE BEGIN TIM3_IRQn 0 */
203 |
204 | /* USER CODE END TIM3_IRQn 0 */
205 | HAL_TIM_IRQHandler(&htim3);
206 | /* USER CODE BEGIN TIM3_IRQn 1 */
207 |
208 | /* USER CODE END TIM3_IRQn 1 */
209 | }
210 |
211 | /**
212 | * @brief This function handles USART1 global interrupt.
213 | */
214 | void USART1_IRQHandler(void)
215 | {
216 | /* USER CODE BEGIN USART1_IRQn 0 */
217 | uint32_t tmp_flag = __HAL_UART_GET_FLAG(&huart1, UART_FLAG_RXNE);
218 | uint32_t tmp_it_source = __HAL_UART_GET_IT_SOURCE(&huart1, UART_IT_RXNE);
219 |
220 | if((tmp_flag != RESET) && (tmp_it_source != RESET)) {
221 | #if MB_MASTER_RTU_ENABLED > 0 || MB_MASTER_ASCII_ENABLED > 0
222 | pxMBMasterFrameCBByteReceived();
223 | #endif
224 |
225 | #if MB_SLAVE_RTU_ENABLED>0 || MB_SLAVE_ASCII_ENABLED>0
226 | pxMBFrameCBByteReceived();
227 | #endif
228 | __HAL_UART_CLEAR_PEFLAG(&huart1);
229 | return;
230 | }
231 |
232 | if((__HAL_UART_GET_FLAG(&huart1, UART_FLAG_TXE) != RESET) &&(__HAL_UART_GET_IT_SOURCE(&huart1, UART_IT_TXE) != RESET)) {
233 | #if MB_MASTER_RTU_ENABLED > 0 || MB_MASTER_ASCII_ENABLED > 0
234 | pxMBMasterFrameCBTransmitterEmpty();
235 | #endif
236 | #if MB_SLAVE_RTU_ENABLED>0 || MB_SLAVE_ASCII_ENABLED>0
237 | pxMBFrameCBTransmitterEmpty();
238 | #endif
239 | return ;
240 | }
241 |
242 | /* USER CODE END USART1_IRQn 0 */
243 | HAL_UART_IRQHandler(&huart1);
244 | /* USER CODE BEGIN USART1_IRQn 1 */
245 |
246 | /* USER CODE END USART1_IRQn 1 */
247 | }
248 |
249 | /* USER CODE BEGIN 1 */
250 |
251 | /* USER CODE END 1 */
252 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
253 |
--------------------------------------------------------------------------------
/Src/tim.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * File Name : TIM.c
4 | * Description : This file provides code for the configuration
5 | * of the TIM instances.
6 | ******************************************************************************
7 | ** This notice applies to any and all portions of this file
8 | * that are not between comment pairs USER CODE BEGIN and
9 | * USER CODE END. Other portions of this file, whether
10 | * inserted by the user or by software development tools
11 | * are owned by their respective copyright owners.
12 | *
13 | * COPYRIGHT(c) 2018 STMicroelectronics
14 | *
15 | * Redistribution and use in source and binary forms, with or without modification,
16 | * are permitted provided that the following conditions are met:
17 | * 1. Redistributions of source code must retain the above copyright notice,
18 | * this list of conditions and the following disclaimer.
19 | * 2. Redistributions in binary form must reproduce the above copyright notice,
20 | * this list of conditions and the following disclaimer in the documentation
21 | * and/or other materials provided with the distribution.
22 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
23 | * may be used to endorse or promote products derived from this software
24 | * without specific prior written permission.
25 | *
26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
34 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | ******************************************************************************
38 | */
39 |
40 | /* Includes ------------------------------------------------------------------*/
41 | #include "tim.h"
42 |
43 | /* USER CODE BEGIN 0 */
44 |
45 | /* USER CODE END 0 */
46 |
47 | TIM_HandleTypeDef htim3;
48 |
49 | /* TIM3 init function */
50 | void MX_TIM3_Init(void)
51 | {
52 | TIM_ClockConfigTypeDef sClockSourceConfig;
53 | TIM_MasterConfigTypeDef sMasterConfig;
54 |
55 | htim3.Instance = TIM3;
56 | htim3.Init.Prescaler = 0;
57 | htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
58 | htim3.Init.Period = 0;
59 | htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
60 | htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
61 | if (HAL_TIM_Base_Init(&htim3) != HAL_OK)
62 | {
63 | _Error_Handler(__FILE__, __LINE__);
64 | }
65 |
66 | sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
67 | if (HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig) != HAL_OK)
68 | {
69 | _Error_Handler(__FILE__, __LINE__);
70 | }
71 |
72 | sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
73 | sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
74 | if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK)
75 | {
76 | _Error_Handler(__FILE__, __LINE__);
77 | }
78 |
79 | }
80 |
81 | void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)
82 | {
83 |
84 | if(tim_baseHandle->Instance==TIM3)
85 | {
86 | /* USER CODE BEGIN TIM3_MspInit 0 */
87 |
88 | /* USER CODE END TIM3_MspInit 0 */
89 | /* TIM3 clock enable */
90 | __HAL_RCC_TIM3_CLK_ENABLE();
91 |
92 | /* TIM3 interrupt Init */
93 | HAL_NVIC_SetPriority(TIM3_IRQn, 0, 0);
94 | HAL_NVIC_EnableIRQ(TIM3_IRQn);
95 | /* USER CODE BEGIN TIM3_MspInit 1 */
96 |
97 | /* USER CODE END TIM3_MspInit 1 */
98 | }
99 | }
100 |
101 | void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle)
102 | {
103 |
104 | if(tim_baseHandle->Instance==TIM3)
105 | {
106 | /* USER CODE BEGIN TIM3_MspDeInit 0 */
107 |
108 | /* USER CODE END TIM3_MspDeInit 0 */
109 | /* Peripheral clock disable */
110 | __HAL_RCC_TIM3_CLK_DISABLE();
111 |
112 | /* TIM3 interrupt Deinit */
113 | HAL_NVIC_DisableIRQ(TIM3_IRQn);
114 | /* USER CODE BEGIN TIM3_MspDeInit 1 */
115 |
116 | /* USER CODE END TIM3_MspDeInit 1 */
117 | }
118 | }
119 |
120 | /* USER CODE BEGIN 1 */
121 |
122 | /* USER CODE END 1 */
123 |
124 | /**
125 | * @}
126 | */
127 |
128 | /**
129 | * @}
130 | */
131 |
132 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
133 |
--------------------------------------------------------------------------------
/Src/usart.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * File Name : USART.c
4 | * Description : This file provides code for the configuration
5 | * of the USART instances.
6 | ******************************************************************************
7 | ** This notice applies to any and all portions of this file
8 | * that are not between comment pairs USER CODE BEGIN and
9 | * USER CODE END. Other portions of this file, whether
10 | * inserted by the user or by software development tools
11 | * are owned by their respective copyright owners.
12 | *
13 | * COPYRIGHT(c) 2018 STMicroelectronics
14 | *
15 | * Redistribution and use in source and binary forms, with or without modification,
16 | * are permitted provided that the following conditions are met:
17 | * 1. Redistributions of source code must retain the above copyright notice,
18 | * this list of conditions and the following disclaimer.
19 | * 2. Redistributions in binary form must reproduce the above copyright notice,
20 | * this list of conditions and the following disclaimer in the documentation
21 | * and/or other materials provided with the distribution.
22 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
23 | * may be used to endorse or promote products derived from this software
24 | * without specific prior written permission.
25 | *
26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
34 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | ******************************************************************************
38 | */
39 |
40 | /* Includes ------------------------------------------------------------------*/
41 | #include "usart.h"
42 |
43 | #include "gpio.h"
44 |
45 | /* USER CODE BEGIN 0 */
46 |
47 | /* USER CODE END 0 */
48 |
49 | UART_HandleTypeDef huart1;
50 |
51 | /* USART1 init function */
52 |
53 | void MX_USART1_UART_Init(void)
54 | {
55 |
56 | huart1.Instance = USART1;
57 | huart1.Init.BaudRate = 115200;
58 | huart1.Init.WordLength = UART_WORDLENGTH_8B;
59 | huart1.Init.StopBits = UART_STOPBITS_1;
60 | huart1.Init.Parity = UART_PARITY_NONE;
61 | huart1.Init.Mode = UART_MODE_TX_RX;
62 | huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
63 | huart1.Init.OverSampling = UART_OVERSAMPLING_16;
64 | if (HAL_UART_Init(&huart1) != HAL_OK)
65 | {
66 | _Error_Handler(__FILE__, __LINE__);
67 | }
68 |
69 | }
70 |
71 | void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
72 | {
73 |
74 | GPIO_InitTypeDef GPIO_InitStruct;
75 | if(uartHandle->Instance==USART1)
76 | {
77 | /* USER CODE BEGIN USART1_MspInit 0 */
78 |
79 | /* USER CODE END USART1_MspInit 0 */
80 | /* USART1 clock enable */
81 | __HAL_RCC_USART1_CLK_ENABLE();
82 |
83 | /**USART1 GPIO Configuration
84 | PA9 ------> USART1_TX
85 | PA10 ------> USART1_RX
86 | */
87 | GPIO_InitStruct.Pin = GPIO_PIN_9;
88 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
89 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
90 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
91 |
92 | GPIO_InitStruct.Pin = GPIO_PIN_10;
93 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
94 | GPIO_InitStruct.Pull = GPIO_NOPULL;
95 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
96 |
97 | /* USART1 interrupt Init */
98 | HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
99 | HAL_NVIC_EnableIRQ(USART1_IRQn);
100 | /* USER CODE BEGIN USART1_MspInit 1 */
101 |
102 | /* USER CODE END USART1_MspInit 1 */
103 | }
104 | }
105 |
106 | void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
107 | {
108 |
109 | if(uartHandle->Instance==USART1)
110 | {
111 | /* USER CODE BEGIN USART1_MspDeInit 0 */
112 |
113 | /* USER CODE END USART1_MspDeInit 0 */
114 | /* Peripheral clock disable */
115 | __HAL_RCC_USART1_CLK_DISABLE();
116 |
117 | /**USART1 GPIO Configuration
118 | PA9 ------> USART1_TX
119 | PA10 ------> USART1_RX
120 | */
121 | HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10);
122 |
123 | /* USART1 interrupt Deinit */
124 | HAL_NVIC_DisableIRQ(USART1_IRQn);
125 | /* USER CODE BEGIN USART1_MspDeInit 1 */
126 |
127 | /* USER CODE END USART1_MspDeInit 1 */
128 | }
129 | }
130 |
131 | /* USER CODE BEGIN 1 */
132 |
133 | /* USER CODE END 1 */
134 |
135 | /**
136 | * @}
137 | */
138 |
139 | /**
140 | * @}
141 | */
142 |
143 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
144 |
--------------------------------------------------------------------------------
/freemodbus_master.ioc:
--------------------------------------------------------------------------------
1 | #MicroXplorer Configuration settings - do not modify
2 | File.Version=6
3 | KeepUserPlacement=false
4 | Mcu.Family=STM32F1
5 | Mcu.IP0=NVIC
6 | Mcu.IP1=RCC
7 | Mcu.IP2=SYS
8 | Mcu.IP3=TIM3
9 | Mcu.IP4=USART1
10 | Mcu.IPNb=5
11 | Mcu.Name=STM32F103C(8-B)Tx
12 | Mcu.Package=LQFP48
13 | Mcu.Pin0=PA8
14 | Mcu.Pin1=PA9
15 | Mcu.Pin2=PA10
16 | Mcu.Pin3=PA13
17 | Mcu.Pin4=PA14
18 | Mcu.Pin5=PA15
19 | Mcu.Pin6=PB3
20 | Mcu.Pin7=PB4
21 | Mcu.Pin8=VP_SYS_VS_Systick
22 | Mcu.Pin9=VP_TIM3_VS_ClockSourceINT
23 | Mcu.PinsNb=10
24 | Mcu.ThirdPartyNb=0
25 | Mcu.UserConstants=
26 | Mcu.UserName=STM32F103C8Tx
27 | MxCube.Version=4.24.0
28 | MxDb.Version=DB.4.0.240
29 | NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false
30 | NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false
31 | NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false
32 | NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false
33 | NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false
34 | NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false
35 | NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4
36 | NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false
37 | NVIC.SysTick_IRQn=true\:0\:0\:false\:false\:true\:false
38 | NVIC.TIM3_IRQn=true\:0\:0\:false\:false\:true\:true
39 | NVIC.USART1_IRQn=true\:0\:0\:false\:false\:true\:true
40 | NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false
41 | PA10.Mode=Asynchronous
42 | PA10.Signal=USART1_RX
43 | PA13.Mode=Serial_Wire
44 | PA13.Signal=SYS_JTMS-SWDIO
45 | PA14.Mode=Serial_Wire
46 | PA14.Signal=SYS_JTCK-SWCLK
47 | PA15.GPIOParameters=GPIO_Speed
48 | PA15.GPIO_Speed=GPIO_SPEED_FREQ_HIGH
49 | PA15.Locked=true
50 | PA15.Signal=GPIO_Output
51 | PA8.GPIOParameters=GPIO_Speed
52 | PA8.GPIO_Speed=GPIO_SPEED_FREQ_HIGH
53 | PA8.Locked=true
54 | PA8.Signal=GPIO_Output
55 | PA9.Mode=Asynchronous
56 | PA9.Signal=USART1_TX
57 | PB3.GPIOParameters=GPIO_Speed
58 | PB3.GPIO_Speed=GPIO_SPEED_FREQ_HIGH
59 | PB3.Locked=true
60 | PB3.Signal=GPIO_Output
61 | PB4.GPIOParameters=GPIO_Speed
62 | PB4.GPIO_Speed=GPIO_SPEED_FREQ_HIGH
63 | PB4.Locked=true
64 | PB4.Signal=GPIO_Output
65 | PCC.Checker=false
66 | PCC.Line=STM32F103
67 | PCC.MCU=STM32F103C(8-B)Tx
68 | PCC.PartNumber=STM32F103C8Tx
69 | PCC.Seq0=0
70 | PCC.Series=STM32F1
71 | PCC.Temperature=25
72 | PCC.Vdd=3.3
73 | PinOutPanel.RotationAngle=0
74 | ProjectManager.AskForMigrate=true
75 | ProjectManager.BackupPrevious=false
76 | ProjectManager.CompilerOptimize=2
77 | ProjectManager.ComputerToolchain=false
78 | ProjectManager.CoupleFile=true
79 | ProjectManager.CustomerFirmwarePackage=C\:/Users/Administrator/STM32Cube/Repository/STM32Cube_FW_F1_V1.6.0
80 | ProjectManager.DefaultFWLocation=true
81 | ProjectManager.DeletePrevious=true
82 | ProjectManager.DeviceId=STM32F103C8Tx
83 | ProjectManager.FirmwarePackage=STM32Cube FW_F1 V1.6.0
84 | ProjectManager.FreePins=false
85 | ProjectManager.HalAssertFull=false
86 | ProjectManager.HeapSize=0x200
87 | ProjectManager.KeepUserCode=true
88 | ProjectManager.LastFirmware=true
89 | ProjectManager.LibraryCopy=0
90 | ProjectManager.PreviousToolchain=
91 | ProjectManager.ProjectBuild=false
92 | ProjectManager.ProjectFileName=freemodbus_master.ioc
93 | ProjectManager.ProjectName=freemodbus_master
94 | ProjectManager.StackSize=0x400
95 | ProjectManager.TargetToolchain=EWARM
96 | ProjectManager.ToolChainLocation=
97 | ProjectManager.UnderRoot=false
98 | ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-true,3-MX_USART1_UART_Init-USART1-false-HAL-true,4-MX_TIM3_Init-TIM3-false-HAL-true
99 | RCC.ADCFreqValue=32000000
100 | RCC.AHBFreq_Value=64000000
101 | RCC.APB1CLKDivider=RCC_HCLK_DIV2
102 | RCC.APB1Freq_Value=32000000
103 | RCC.APB1TimFreq_Value=64000000
104 | RCC.APB2Freq_Value=64000000
105 | RCC.APB2TimFreq_Value=64000000
106 | RCC.FCLKCortexFreq_Value=64000000
107 | RCC.FamilyName=M
108 | RCC.HCLKFreq_Value=64000000
109 | RCC.IPParameters=ADCFreqValue,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,MCOFreq_Value,PLLCLKFreq_Value,PLLMCOFreq_Value,PLLMUL,SYSCLKFreq_VALUE,SYSCLKSource,TimSysFreq_Value,USBFreq_Value
110 | RCC.MCOFreq_Value=64000000
111 | RCC.PLLCLKFreq_Value=64000000
112 | RCC.PLLMCOFreq_Value=32000000
113 | RCC.PLLMUL=RCC_PLL_MUL16
114 | RCC.SYSCLKFreq_VALUE=64000000
115 | RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK
116 | RCC.TimSysFreq_Value=64000000
117 | RCC.USBFreq_Value=64000000
118 | USART1.IPParameters=VirtualMode
119 | USART1.VirtualMode=VM_ASYNC
120 | VP_SYS_VS_Systick.Mode=SysTick
121 | VP_SYS_VS_Systick.Signal=SYS_VS_Systick
122 | VP_TIM3_VS_ClockSourceINT.Mode=Internal
123 | VP_TIM3_VS_ClockSourceINT.Signal=TIM3_VS_ClockSourceINT
124 | board=freemodbus_master
125 |
--------------------------------------------------------------------------------