Cleaned up compile on Win32 for MS/TP datalink. Still not reliable yet.

This commit is contained in:
skarg
2011-07-26 22:11:20 +00:00
parent 813f3f0f1b
commit ef80e662b3
4 changed files with 49 additions and 66 deletions
+6 -38
View File
@@ -22,6 +22,7 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
@@ -39,6 +40,7 @@
#include "npdu.h"
#include "bits.h"
#include "ringbuf.h"
#include "timer.h"
#define WIN32_LEAN_AND_MEAN
#define STRICT 1
@@ -70,33 +72,16 @@ static uint16_t Treply_timeout = 260;
static uint8_t Tusage_timeout = 50;
/* Timer that indicates line silence - and functions */
static uint16_t SilenceTime;
#define INCREMENT_AND_LIMIT_UINT16(x) {if (x < 0xFFFF) x++;}
static uint16_t Timer_Silence(
static uint32_t Timer_Silence(
void)
{
return SilenceTime;
return timer_milliseconds(TIMER_SILENCE);
}
static void Timer_Silence_Reset(
void)
{
SilenceTime = 0;
}
static void dlmstp_millisecond_timer(
void)
{
INCREMENT_AND_LIMIT_UINT16(SilenceTime);
}
static void dlmstp_reinit(
void)
{
/*RS485_Reinit(); */
dlmstp_set_mac_address(DEFAULT_MAC_ADDRESS);
dlmstp_set_max_info_frames(DEFAULT_MAX_INFO_FRAMES);
dlmstp_set_max_master(DEFAULT_MAX_MASTER);
timer_reset(TIMER_SILENCE);
}
void dlmstp_cleanup(
@@ -230,18 +215,6 @@ static void dlmstp_master_fsm_task(
}
}
static void dlmstp_millisecond_task(
void *pArg)
{
(void) pArg;
(void) SetThreadPriority(GetCurrentThread(),
THREAD_PRIORITY_TIME_CRITICAL);
for (;;) {
dlmstp_millisecond_timer();
Sleep(1);
}
}
void dlmstp_fill_bacnet_address(
BACNET_ADDRESS * src,
uint8_t mstp_address)
@@ -622,7 +595,7 @@ bool dlmstp_init(
exit(1);
}
/* initialize hardware */
/* initialize hardware */
timer_init();
if (ifname) {
RS485_Set_Interface(ifname);
#if PRINT_ENABLED
@@ -672,11 +645,6 @@ bool dlmstp_init(
fprintf(stderr, "MS/TP Max_Info_Frames: %u\n",
(unsigned) MSTP_Port.Nmax_info_frames);
#endif
/* start the threads */
hThread = _beginthread(dlmstp_millisecond_task, 4096, &arg_value);
if (hThread == 0) {
fprintf(stderr, "Failed to start timer task\n");
}
hThread = _beginthread(dlmstp_receive_fsm_task, 4096, &arg_value);
if (hThread == 0) {
fprintf(stderr, "Failed to start recive FSM task\n");
+31 -19
View File
@@ -33,12 +33,12 @@
-------------------------------------------
####COPYRIGHTEND####*/
/* The module handles sending data out the RS-485 port */
/* and handles receiving data from the RS-485 port. */
/* Customize this file for your specific hardware */
/** @file win32/rs485.c Provides Windows-specific functions for RS-485 */
/* Suggested USB to RS485 devices:
B&B Electronics USOPTL4
SerialGear USB-COMi-SI-M
USB-RS485-WE-1800-BT
*/
#include <stddef.h>
@@ -54,6 +54,7 @@
#define STRICT 1
#include <windows.h>
#include "rs485.h"
#include "fifo.h"
/* details from Serial Communications in Win32 at MSDN */
@@ -83,6 +84,11 @@ static DWORD RS485_DTRControl = DTR_CONTROL_DISABLE;
RTS_CONTROL_ENABLE, RTS_CONTROL_DISABLE,
RTS_CONTROL_HANDSHAKE, RTS_CONTROL_TOGGLE */
static DWORD RS485_RTSControl = RTS_CONTROL_DISABLE;
/* Ring buffer for incoming bytes, in order to speed up the receiving. */
static FIFO_BUFFER Rx_FIFO;
/* buffer size needs to be a power of 2 */
static uint8_t Rx_Buffer[1 << 12];
/****************************************************************************
* DESCRIPTION: Change the characters in a string to uppercase
@@ -99,8 +105,6 @@ static void strupper(
}
}
#pragma
/****************************************************************************
* DESCRIPTION: Initializes the RS485 hardware and variables, and starts in
* receive mode.
@@ -211,6 +215,26 @@ static void RS485_Configure_Status(
}
}
/****************************************************************************
* DESCRIPTION: Cleans up any handles that were created at startup.
* RETURN: none
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
static void RS485_Cleanup(
void)
{
if (!EscapeCommFunction(RS485_Handle, CLRDTR)) {
RS485_Print_Error();
}
if (!SetCommTimeouts(RS485_Handle, &RS485_Timeouts)) {
RS485_Print_Error();
}
CloseHandle(RS485_Handle);
}
/****************************************************************************
* DESCRIPTION: Initializes the RS485 hardware and variables, and starts in
* receive mode.
@@ -236,23 +260,11 @@ void RS485_Initialize(
}
RS485_Configure_Status();
atexit(RS485_Cleanup);
return;
}
void RS485_Cleanup(
void)
{
if (!EscapeCommFunction(RS485_Handle, CLRDTR)) {
RS485_Print_Error();
}
if (!SetCommTimeouts(RS485_Handle, &RS485_Timeouts)) {
RS485_Print_Error();
}
CloseHandle(RS485_Handle);
}
/****************************************************************************
* DESCRIPTION: Returns the baud rate that we are currently running at
* RETURN: none