auto-sync

This commit is contained in:
rusEfi 2016-05-30 19:02:00 -04:00
parent 7aa85b11a5
commit 433c667ee8
11 changed files with 1171 additions and 11 deletions

View File

@ -0,0 +1,128 @@
/*
ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* @file console.c
* @brief Simulator console driver code.
* @{
*/
#include <stdio.h>
#include "ch.h"
#include "hal.h"
#include "console.h"
/*===========================================================================*/
/* Driver exported variables. */
/*===========================================================================*/
/**
* @brief Console driver 1.
*/
BaseChannel CD1;
/*===========================================================================*/
/* Driver local variables. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver local functions. */
/*===========================================================================*/
static size_t write(void *ip, const uint8_t *bp, size_t n) {
size_t ret;
(void)ip;
ret = fwrite(bp, 1, n, stdout);
fflush(stdout);
return ret;
}
static size_t read(void *ip, uint8_t *bp, size_t n) {
(void)ip;
return fread(bp, 1, n, stdin);
}
static msg_t put(void *ip, uint8_t b) {
(void)ip;
fputc(b, stdout);
fflush(stdout);
return RDY_OK;
}
static msg_t get(void *ip) {
(void)ip;
return fgetc(stdin);
}
static msg_t putt(void *ip, uint8_t b, systime_t timeout) {
(void)ip;
(void)timeout;
fputc(b, stdout);
fflush(stdout);
return RDY_OK;
}
static msg_t gett(void *ip, systime_t timeout) {
(void)ip;
(void)timeout;
return fgetc(stdin);
}
static size_t writet(void *ip, const uint8_t *bp, size_t n, systime_t timeout) {
size_t ret;
(void)ip;
(void)timeout;
ret = fwrite(bp, 1, n, stdout);
fflush(stdout);
return ret;
}
static size_t readt(void *ip, uint8_t *bp, size_t n, systime_t timeout) {
(void)ip;
(void)timeout;
return fread(bp, 1, n, stdin);
}
static const struct BaseChannelVMT vmt = {
write, read, put, get,
putt, gett, writet, readt
};
/*===========================================================================*/
/* Driver interrupt handlers. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver exported functions. */
/*===========================================================================*/
void conInit(void) {
CD1.vmt = &vmt;
}
/** @} */

View File

@ -0,0 +1,62 @@
/*
ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* @file console.h
* @brief Simulator console driver header.
* @{
*/
#ifndef _CONSOLE_H_
#define _CONSOLE_H_
/*===========================================================================*/
/* Driver constants. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver pre-compile time settings. */
/*===========================================================================*/
/*===========================================================================*/
/* Derived constants and error checks. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver data structures and types. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver macros. */
/*===========================================================================*/
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
extern BaseChannel CD1;
#ifdef __cplusplus
extern "C" {
#endif
void conInit(void);
#ifdef __cplusplus
}
#endif
#endif /* _CONSOLE_H_ */
/** @} */

View File

@ -0,0 +1,104 @@
/*
ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* @file Posix/hal_lld.c
* @brief Posix HAL subsystem low level driver code.
*
* @addtogroup POSIX_HAL
* @{
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include "ch.h"
#include "hal.h"
/*===========================================================================*/
/* Driver exported variables. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver local variables and types. */
/*===========================================================================*/
static struct timeval nextcnt;
static struct timeval tick = {0, 1000000 / CH_FREQUENCY};
/*===========================================================================*/
/* Driver local functions. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver interrupt handlers. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver exported functions. */
/*===========================================================================*/
/**
* @brief Low level HAL driver initialization.
*/
void hal_lld_init(void) {
#if defined(__APPLE__)
puts("ChibiOS/RT simulator (OS X)\n");
#else
puts("ChibiOS/RT simulator (Linux)\n");
#endif
gettimeofday(&nextcnt, NULL);
timeradd(&nextcnt, &tick, &nextcnt);
}
/**
* @brief Interrupt simulation.
*/
void ChkIntSources(void) {
struct timeval tv;
#if HAL_USE_SERIAL
if (sd_lld_interrupt_pending()) {
dbg_check_lock();
if (chSchIsPreemptionRequired())
chSchDoReschedule();
dbg_check_unlock();
return;
}
#endif
gettimeofday(&tv, NULL);
if (timercmp(&tv, &nextcnt, >=)) {
timeradd(&nextcnt, &tick, &nextcnt);
CH_IRQ_PROLOGUE();
chSysLockFromIsr();
chSysTimerHandlerI();
chSysUnlockFromIsr();
CH_IRQ_EPILOGUE();
dbg_check_lock();
if (chSchIsPreemptionRequired())
chSchDoReschedule();
dbg_check_unlock();
}
}
/** @} */

View File

@ -0,0 +1,80 @@
/*
ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* @file Posix/hal_lld.h
* @brief Posix simulator HAL subsystem low level driver header.
*
* @addtogroup POSIX_HAL
* @{
*/
#ifndef _HAL_LLD_H_
#define _HAL_LLD_H_
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
/*===========================================================================*/
/* Driver constants. */
/*===========================================================================*/
/**
* @brief Defines the support for realtime counters in the HAL.
*/
#define HAL_IMPLEMENTS_COUNTERS FALSE
/**
* @brief Platform name.
*/
#define PLATFORM_NAME "Linux"
#define SOCKET int
#define INVALID_SOCKET -1
/*===========================================================================*/
/* Driver pre-compile time settings. */
/*===========================================================================*/
/*===========================================================================*/
/* Derived constants and error checks. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver data structures and types. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver macros. */
/*===========================================================================*/
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
#ifdef __cplusplus
extern "C" {
#endif
void hal_lld_init(void);
void ChkIntSources(void);
#ifdef __cplusplus
}
#endif
#endif /* _HAL_LLD_H_ */
/** @} */

View File

@ -0,0 +1,95 @@
/*
ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* @file Posix/pal_lld.c
* @brief Posix low level simulated PAL driver code.
*
* @addtogroup POSIX_PAL
* @{
*/
#include "ch.h"
#include "hal.h"
#if HAL_USE_PAL || defined(__DOXYGEN__)
/*===========================================================================*/
/* Driver exported variables. */
/*===========================================================================*/
/**
* @brief VIO1 simulated port.
*/
sim_vio_port_t vio_port_1;
/**
* @brief VIO2 simulated port.
*/
sim_vio_port_t vio_port_2;
/*===========================================================================*/
/* Driver local variables and types. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver local functions. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver interrupt handlers. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver exported functions. */
/*===========================================================================*/
/**
* @brief Pads mode setup.
* @details This function programs a pads group belonging to the same port
* with the specified mode.
*
* @param[in] port the port identifier
* @param[in] mask the group mask
* @param[in] mode the mode
*
* @note This function is not meant to be invoked directly by the application
* code.
* @note @p PAL_MODE_UNCONNECTED is implemented as push pull output with high
* state.
* @note This function does not alter the @p PINSELx registers. Alternate
* functions setup must be handled by device-specific code.
*/
void _pal_lld_setgroupmode(ioportid_t port,
ioportmask_t mask,
iomode_t mode) {
switch (mode) {
case PAL_MODE_RESET:
case PAL_MODE_INPUT:
port->dir &= ~mask;
break;
case PAL_MODE_UNCONNECTED:
port->latch |= mask;
case PAL_MODE_OUTPUT_PUSHPULL:
port->dir |= mask;
break;
}
}
#endif /* HAL_USE_PAL */
/** @} */

View File

@ -0,0 +1,206 @@
/*
ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* @file Posix/pal_lld.h
* @brief Posix low level simulated PAL driver header.
*
* @addtogroup POSIX_PAL
* @{
*/
#ifndef _PAL_LLD_H_
#define _PAL_LLD_H_
#if HAL_USE_PAL || defined(__DOXYGEN__)
/*===========================================================================*/
/* Unsupported modes and specific modes */
/*===========================================================================*/
#undef PAL_MODE_INPUT_PULLUP
#undef PAL_MODE_INPUT_PULLDOWN
#undef PAL_MODE_OUTPUT_OPENDRAIN
#undef PAL_MODE_INPUT_ANALOG
/*===========================================================================*/
/* I/O Ports Types and constants. */
/*===========================================================================*/
/**
* @brief VIO port structure.
*/
typedef struct {
/**
* @brief VIO_LATCH register.
* @details This register represents the output latch of the VIO port.
*/
uint32_t latch;
/**
* @brief VIO_PIN register.
* @details This register represents the logical level at the VIO port
* pin level.
*/
uint32_t pin;
/**
* @brief VIO_DIR register.
* @details Direction of the VIO port bits, 0=input, 1=output.
*/
uint32_t dir;
} sim_vio_port_t;
/**
* @brief Virtual I/O ports static initializer.
* @details An instance of this structure must be passed to @p palInit() at
* system startup time in order to initialized the digital I/O
* subsystem. This represents only the initial setup, specific pads
* or whole ports can be reprogrammed at later time.
*/
typedef struct {
/**
* @brief Virtual port 1 setup data.
*/
sim_vio_port_t VP1Data;
/**
* @brief Virtual port 2 setup data.
*/
sim_vio_port_t VP2Data;
} PALConfig;
/**
* @brief Width, in bits, of an I/O port.
*/
#define PAL_IOPORTS_WIDTH 32
/**
* @brief Whole port mask.
* @brief This macro specifies all the valid bits into a port.
*/
#define PAL_WHOLE_PORT ((ioportmask_t)0xFFFFFFFF)
/**
* @brief Digital I/O port sized unsigned type.
*/
typedef uint32_t ioportmask_t;
/**
* @brief Digital I/O modes.
*/
typedef uint32_t iomode_t;
/**
* @brief Port Identifier.
*/
typedef sim_vio_port_t *ioportid_t;
/*===========================================================================*/
/* I/O Ports Identifiers. */
/*===========================================================================*/
/**
* @brief VIO port 1 identifier.
*/
#define IOPORT1 (&vio_port_1)
/**
* @brief VIO port 2 identifier.
*/
#define IOPORT2 (&vio_port_2)
/*===========================================================================*/
/* Implementation, some of the following macros could be implemented as */
/* functions, if so please put them in pal_lld.c. */
/*===========================================================================*/
/**
* @brief Low level PAL subsystem initialization.
*
* @param[in] config architecture-dependent ports configuration
*
* @notapi
*/
#define pal_lld_init(config) \
(vio_port_1 = (config)->VP1Data, \
vio_port_2 = (config)->VP2Data)
/**
* @brief Reads the physical I/O port states.
*
* @param[in] port port identifier
* @return The port bits.
*
* @notapi
*/
#define pal_lld_readport(port) ((port)->pin)
/**
* @brief Reads the output latch.
* @details The purpose of this function is to read back the latched output
* value.
*
* @param[in] port port identifier
* @return The latched logical states.
*
* @notapi
*/
#define pal_lld_readlatch(port) ((port)->latch)
/**
* @brief Writes a bits mask on a I/O port.
*
* @param[in] port port identifier
* @param[in] bits bits to be written on the specified port
*
* @notapi
*/
#define pal_lld_writeport(port, bits) ((port)->latch = (bits))
/**
* @brief Pads group mode setup.
* @details This function programs a pads group belonging to the same port
* with the specified mode.
*
* @param[in] port port identifier
* @param[in] mask group mask
* @param[in] offset group bit offset within the port
* @param[in] mode group mode
*
* @notapi
*/
#define pal_lld_setgroupmode(port, mask, offset, mode) \
_pal_lld_setgroupmode(port, mask << offset, mode)
#if !defined(__DOXYGEN__)
extern sim_vio_port_t vio_port_1;
extern sim_vio_port_t vio_port_2;
extern const PALConfig pal_default_config;
#endif
#ifdef __cplusplus
extern "C" {
#endif
void _pal_lld_setgroupmode(ioportid_t port,
ioportmask_t mask,
iomode_t mode);
#ifdef __cplusplus
}
#endif
#endif /* HAL_USE_PAL */
#endif /* _PAL_LLD_H_ */
/** @} */

View File

@ -0,0 +1,7 @@
# List of all the Posix platform files.
PLATFORMSRC = ${CHIBIOS}/os/hal/platforms/Posix/hal_lld.c \
${CHIBIOS}/os/hal/platforms/Posix/pal_lld.c \
${CHIBIOS}/os/hal/platforms/Posix/serial_lld.c
# Required include directories
PLATFORMINC = ${CHIBIOS}/os/hal/platforms/Posix

View File

@ -0,0 +1,287 @@
/*
ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* @file Posix/serial_lld.c
* @brief Posix low level simulated serial driver code.
*
* @addtogroup POSIX_SERIAL
* @{
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/ioctl.h>
#include "ch.h"
#include "hal.h"
#if HAL_USE_SERIAL || defined(__DOXYGEN__)
/*===========================================================================*/
/* Driver exported variables. */
/*===========================================================================*/
/** @brief Serial driver 1 identifier.*/
#if USE_SIM_SERIAL1 || defined(__DOXYGEN__)
SerialDriver SD1;
#endif
/** @brief Serial driver 2 identifier.*/
#if USE_SIM_SERIAL2 || defined(__DOXYGEN__)
SerialDriver SD2;
#endif
/*===========================================================================*/
/* Driver local variables and types. */
/*===========================================================================*/
/** @brief Driver default configuration.*/
static const SerialConfig default_config = {
};
static u_long nb = 1;
/*===========================================================================*/
/* Driver local functions. */
/*===========================================================================*/
static void init(SerialDriver *sdp, uint16_t port) {
struct sockaddr_in sad;
struct protoent *prtp;
int sockval = 1;
socklen_t socklen = sizeof(sockval);
if ((prtp = getprotobyname("tcp")) == NULL) {
printf("%s: Error mapping protocol name to protocol number\n", sdp->com_name);
goto abort;
}
sdp->com_listen = socket(PF_INET, SOCK_STREAM, prtp->p_proto);
if (sdp->com_listen == INVALID_SOCKET) {
printf("%s: Error creating simulator socket\n", sdp->com_name);
goto abort;
}
setsockopt(sdp->com_listen, SOL_SOCKET, SO_REUSEADDR, &sockval, socklen);
if (ioctl(sdp->com_listen, FIONBIO, &nb) != 0) {
printf("%s: Unable to setup non blocking mode on socket\n", sdp->com_name);
goto abort;
}
memset(&sad, 0, sizeof(sad));
sad.sin_family = AF_INET;
sad.sin_addr.s_addr = INADDR_ANY;
sad.sin_port = htons(port);
if (bind(sdp->com_listen, (struct sockaddr *)&sad, sizeof(sad))) {
printf("%s: Error binding socket\n", sdp->com_name);
goto abort;
}
if (listen(sdp->com_listen, 1) != 0) {
printf("%s: Error listening socket\n", sdp->com_name);
goto abort;
}
printf("Full Duplex Channel %s listening on port %d\n", sdp->com_name, port);
return;
abort:
if (sdp->com_listen != INVALID_SOCKET)
close(sdp->com_listen);
exit(1);
}
static bool_t connint(SerialDriver *sdp) {
if (sdp->com_data == INVALID_SOCKET) {
struct sockaddr addr;
socklen_t addrlen = sizeof(addr);
if ((sdp->com_data = accept(sdp->com_listen, &addr, &addrlen)) == INVALID_SOCKET)
return FALSE;
if (ioctl(sdp->com_data, FIONBIO, &nb) != 0) {
printf("%s: Unable to setup non blocking mode on data socket\n", sdp->com_name);
goto abort;
}
chSysLockFromIsr();
chnAddFlagsI(sdp, CHN_CONNECTED);
chSysUnlockFromIsr();
return TRUE;
}
return FALSE;
abort:
if (sdp->com_listen != INVALID_SOCKET)
close(sdp->com_listen);
if (sdp->com_data != INVALID_SOCKET)
close(sdp->com_data);
exit(1);
}
static bool_t inint(SerialDriver *sdp) {
if (sdp->com_data != INVALID_SOCKET) {
int i;
uint8_t data[32];
/*
* Input.
*/
int n = recv(sdp->com_data, data, sizeof(data), 0);
switch (n) {
case 0:
close(sdp->com_data);
sdp->com_data = INVALID_SOCKET;
chSysLockFromIsr();
chnAddFlagsI(sdp, CHN_DISCONNECTED);
chSysUnlockFromIsr();
return FALSE;
case INVALID_SOCKET:
if (errno == EWOULDBLOCK)
return FALSE;
close(sdp->com_data);
sdp->com_data = INVALID_SOCKET;
return FALSE;
}
for (i = 0; i < n; i++) {
chSysLockFromIsr();
sdIncomingDataI(sdp, data[i]);
chSysUnlockFromIsr();
}
return TRUE;
}
return FALSE;
}
static bool_t outint(SerialDriver *sdp) {
if (sdp->com_data != INVALID_SOCKET) {
int n;
uint8_t data[1];
/*
* Input.
*/
chSysLockFromIsr();
n = sdRequestDataI(sdp);
chSysUnlockFromIsr();
if (n < 0)
return FALSE;
data[0] = (uint8_t)n;
n = send(sdp->com_data, data, sizeof(data), 0);
switch (n) {
case 0:
close(sdp->com_data);
sdp->com_data = INVALID_SOCKET;
chSysLockFromIsr();
chnAddFlagsI(sdp, CHN_DISCONNECTED);
chSysUnlockFromIsr();
return FALSE;
case INVALID_SOCKET:
if (errno == EWOULDBLOCK)
return FALSE;
close(sdp->com_data);
sdp->com_data = INVALID_SOCKET;
return FALSE;
}
return TRUE;
}
return FALSE;
}
/*===========================================================================*/
/* Driver interrupt handlers. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver exported functions. */
/*===========================================================================*/
/**
* @brief Low level serial driver initialization.
*/
void sd_lld_init(void) {
#if USE_SIM_SERIAL1
sdObjectInit(&SD1, NULL, NULL);
SD1.com_listen = INVALID_SOCKET;
SD1.com_data = INVALID_SOCKET;
SD1.com_name = "SD1";
#endif
#if USE_SIM_SERIAL2
sdObjectInit(&SD2, NULL, NULL);
SD2.com_listen = INVALID_SOCKET;
SD2.com_data = INVALID_SOCKET;
SD2.com_name = "SD2";
#endif
}
/**
* @brief Low level serial driver configuration and (re)start.
*
* @param[in] sdp pointer to a @p SerialDriver object
*/
void sd_lld_start(SerialDriver *sdp, const SerialConfig *config) {
if (config == NULL)
config = &default_config;
#if USE_SIM_SERIAL1
if (sdp == &SD1)
init(&SD1, SIM_SD1_PORT);
#endif
#if USE_SIM_SERIAL2
if (sdp == &SD2)
init(&SD2, SIM_SD2_PORT);
#endif
}
/**
* @brief Low level serial driver stop.
* @details De-initializes the USART, stops the associated clock, resets the
* interrupt vector.
*
* @param[in] sdp pointer to a @p SerialDriver object
*/
void sd_lld_stop(SerialDriver *sdp) {
(void)sdp;
}
bool_t sd_lld_interrupt_pending(void) {
bool_t b;
CH_IRQ_PROLOGUE();
b = connint(&SD1) || connint(&SD2) ||
inint(&SD1) || inint(&SD2) ||
outint(&SD1) || outint(&SD2);
CH_IRQ_EPILOGUE();
return b;
}
#endif /* HAL_USE_SERIAL */
/** @} */

View File

@ -0,0 +1,151 @@
/*
ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* @file Posix/serial_lld.h
* @brief Posix low level simulated serial driver header.
*
* @addtogroup POSIX_SERIAL
* @{
*/
#ifndef _SERIAL_LLD_H_
#define _SERIAL_LLD_H_
#if HAL_USE_SERIAL || defined(__DOXYGEN__)
/*===========================================================================*/
/* Driver constants. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver pre-compile time settings. */
/*===========================================================================*/
/**
* @brief Serial buffers size.
* @details Configuration parameter, you can change the depth of the queue
* buffers depending on the requirements of your application.
*/
#if !defined(SERIAL_BUFFERS_SIZE) || defined(__DOXYGEN__)
#define SERIAL_BUFFERS_SIZE 1024
#endif
/**
* @brief SD1 driver enable switch.
* @details If set to @p TRUE the support for SD1 is included.
* @note The default is @p TRUE.
*/
#if !defined(USE_SIM_SERIAL1) || defined(__DOXYGEN__)
#define USE_SIM_SERIAL1 TRUE
#endif
/**
* @brief SD2 driver enable switch.
* @details If set to @p TRUE the support for SD2 is included.
* @note The default is @p TRUE.
*/
#if !defined(USE_SIM_SERIAL2) || defined(__DOXYGEN__)
#define USE_SIM_SERIAL2 TRUE
#endif
/**
* @brief Listen port for SD1.
*/
#if !defined(SD1_PORT) || defined(__DOXYGEN__)
#define SIM_SD1_PORT 29001
#endif
/**
* @brief Listen port for SD2.
*/
#if !defined(SD2_PORT) || defined(__DOXYGEN__)
#define SIM_SD2_PORT 29002
#endif
/*===========================================================================*/
/* Derived constants and error checks. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver data structures and types. */
/*===========================================================================*/
/**
* @brief Generic Serial Driver configuration structure.
* @details An instance of this structure must be passed to @p sdStart()
* in order to configure and start a serial driver operations.
* @note This structure content is architecture dependent, each driver
* implementation defines its own version and the custom static
* initializers.
*/
typedef struct {
} SerialConfig;
/**
* @brief @p SerialDriver specific data.
*/
#define _serial_driver_data \
_base_asynchronous_channel_data \
/* Driver state.*/ \
sdstate_t state; \
/* Input queue.*/ \
InputQueue iqueue; \
/* Output queue.*/ \
OutputQueue oqueue; \
/* Input circular buffer.*/ \
uint8_t ib[SERIAL_BUFFERS_SIZE]; \
/* Output circular buffer.*/ \
uint8_t ob[SERIAL_BUFFERS_SIZE]; \
/* End of the mandatory fields.*/ \
/* Listen socket for simulated serial port.*/ \
SOCKET com_listen; \
/* Data socket for simulated serial port.*/ \
SOCKET com_data; \
/* Port readable name.*/ \
const char *com_name;
/*===========================================================================*/
/* Driver macros. */
/*===========================================================================*/
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
#if USE_SIM_SERIAL1 && !defined(__DOXYGEN__)
extern SerialDriver SD1;
#endif
#if USE_SIM_SERIAL2 && !defined(__DOXYGEN__)
extern SerialDriver SD2;
#endif
#ifdef __cplusplus
extern "C" {
#endif
void sd_lld_init(void);
void sd_lld_start(SerialDriver *sdp, const SerialConfig *config);
void sd_lld_stop(SerialDriver *sdp);
bool_t sd_lld_interrupt_pending(void);
#ifdef __cplusplus
}
#endif
#endif /* HAL_USE_SERIAL */
#endif /* _SERIAL_LLD_H_ */
/** @} */

View File

@ -59,7 +59,7 @@ public class AverageAngles {
System.out.println("Skipping due to NaN");
return;
}
current.add(new AngleEvent(angle));
current.add(new AngleEvent(angle, signal));
}
for (int i = 0; i < current.size(); i++) {
@ -73,7 +73,7 @@ public class AverageAngles {
}
public void printReport(Appendable stream) throws IOException {
List<Double> angles = new ArrayList<>();
List<AngleEvent> angles = new ArrayList<>();
stream.append("Based on " + angleData.size() + " charts\r\n");
@ -94,7 +94,7 @@ public class AverageAngles {
StandardDeviation sd = new StandardDeviation();
double sdv = sd.evaluate(values, mean);
angles.add(mean);
angles.add(new AngleEvent(mean, v.get(0).signal));
double diff = mean - prev;
prev = mean;
@ -102,19 +102,28 @@ public class AverageAngles {
}
if (angleData.isEmpty())
return;
Double lastValue = angles.get(angles.size() - 1);
stream.append("Last value = " + lastValue + "\r\n");
Double lastValue = angles.get(angles.size() - 1).angle;
stream.append("Last value = " + lastValue + ", using it to offset...\r\n");
double delta = 720 - lastValue;
for (double v : angles) {
stream.append((delta + v) + "\r\n");
stream.append("And the " + angles.size() + " angles are:\r\n");
for (AngleEvent v : angles) {
stream.append((delta + v.angle) + "\r\n");
}
stream.append("And the " + angles.size() + " lines of code are:\r\n");
for (AngleEvent v : angles) {
String signal = (v.signal / 1000) % 2 == 0 ? "TV_FALL" : "TV_RISE";
stream.append("s->addEvent(" + (delta + v.angle) + ", ch, " + signal + ");\r\n");
}
}
private static class AngleEvent {
private final double angle;
private final int signal;
public AngleEvent(double angle) {
public AngleEvent(double angle, int signal) {
this.angle = angle;
this.signal = signal;
}
public double getAngle() {

View File

@ -11,19 +11,39 @@ ifeq ($(USE_OPT),)
# this config if debugging is needed, but the binary is about 50M
# USE_OPT = -c -Wall -O0 -ggdb -g3 -Werror-implicit-function-declaration -Werror -Wno-error=pointer-sign -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=sign-compare -Wno-error=unused-parameter -Wno-error=missing-field-initializers -Wno-error=write-strings
# this config producec a smaller binary file
USE_OPT = -c -Wall -O2 -Werror-implicit-function-declaration -Werror -Wno-error=pointer-sign -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=sign-compare -Wno-error=unused-parameter -Wno-error=missing-field-initializers -Wno-error=write-strings -Wno-error=strict-aliasing
USE_OPT = -c -Wall -O2 -Werror-implicit-function-declaration -Wno-error=pointer-sign -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=sign-compare -Wno-error=unused-parameter -Wno-error=missing-field-initializers -Wno-error=write-strings -Wno-error=strict-aliasing
ifeq ($(OS),Windows_NT)
else
USE_OPT += -m32
endif
endif
# C specific options here (added to USE_OPT).
ifeq ($(USE_COPT),)
USE_COPT = -std=gnu99 -fgnu89-inline
ifeq ($(OS),Windows_NT)
else
USE_COPT += -Wno-error=attributes -Wno-error=implicit-function-declaration -include stdio.h
endif
endif
# C++ specific options here (added to USE_OPT).
ifeq ($(USE_CPPOPT),)
USE_CPPOPT = -std=c++11 -fno-rtti -fpermissive -fno-exceptions -fno-use-cxa-atexit
ifeq ($(OS),Windows_NT)
else
USE_CPPOPT += -include cstring -include cstdio -include cstdlib
endif
endif
# Enable this if you want the linker to remove unused code and data
ifeq ($(USE_LINK_GC),)
USE_LINK_GC = yes
@ -84,7 +104,13 @@ include $(PROJECT_DIR)/development/development.mk
include $(CHIBIOS)/boards/simulator/board.mk
include ${CHIBIOS}/os/hal/hal.mk
include ${CHIBIOS}/os/hal/platforms/Win32/platform.mk
ifeq ($(OS),Windows_NT)
include ${CHIBIOS}/os/hal/platforms/Win32/platform.mk
else
include ${CHIBIOS}/os/hal/platforms/Posix/platform.mk
endif
include ${CHIBIOS}/os/ports/GCC/SIMIA32/port.mk
include ${CHIBIOS}/os/kernel/kernel.mk
@ -239,7 +265,12 @@ DINCDIR =
DLIBDIR =
# List all default libraries here
DLIBS = -static-libgcc -static-libstdc++ -lws2_32
ifeq ($(OS),Windows_NT)
DLIBS = -static-libgcc -static-libstdc++ -lws2_32
else
DLIBS = -static-libgcc -lgcc -static-libstdc++ -m32
endif
#
# End of default section