This module provides functions for converting 2D vectors from
polar to cartesian and vice versa.
+CONFIG_MODULE_HOSTSIM
+ AVR simulator. This code is used on host (PC for instance) to
+ generate a signal that will call other aversive modules like
+ scheduler or uart. The goal is to simulate the behaviour of
+ hardware interrupts in a unix application. This has no effect
+ when compiling for AVR.
+
CONFIG_MODULE_SCHEDULER
The 'scheduler' module is NOT a scheduler in the same way than in
dep_bool 'Geometry lib' CONFIG_MODULE_GEOMETRY \
$CONFIG_MATH_LIB
+#### Hostsim
+bool 'Hostsim' CONFIG_MODULE_HOSTSIM
+
#### SCHEDULER
bool 'Scheduler' CONFIG_MODULE_SCHEDULER
#
MODULES_LIST="CONFIG_MODULE_BRUSHLESS_3PHASE_DIGITAL_HALL,/devices/brushless_motors/brushless_3phase_digital_hall
CONFIG_MODULE_BRUSHLESS_3PHASE_DIGITAL_HALL_DOUBLE,/devices/brushless_motors/brushless_3phase_digital_hall_double
+ CONFIG_MODULE_HOSTSIM,base/hostsim
CONFIG_MODULE_MENU,ihm/menu
CONFIG_MODULE_PARSE,ihm/parse
CONFIG_MODULE_RDLINE,ihm/rdline
echo "CFLAGS += -D__STDIO_FDEVOPEN_COMPAT_12" >> $2
fi
+if grep "CONFIG_MODULE_HOSTSIM=y" $1 > /dev/null 2> /dev/null
+ then
+ echo "PTHREAD_LDFLAGS = -lpthread" >> $2
+fi
+
####
\r
#ifdef HOST_VERSION\r
\r
-#define wait_3cyc(n) do {} while(0)\r
-#define wait_4cyc(n) do {} while(0)\r
-#define wait_ms(n) do {} while(0)\r
+#include <unistd.h>\r
+\r
+#define wait_3cyc(n) do { volatile int a = 0; a++; } while (0)\r
+#define wait_4cyc(n) do { volatile int a = 0; a++; } while (0)\r
+#define wait_ms(n) host_wait_ms(n)\r
\r
#else /* HOST_VERSION */\r
\r
LDFLAGS += -mmcu=$(MCU) $(PRINTF_LDFLAGS)
LDFLAGS += -Wl,-Map=$(addprefix compiler_files/,$(TARGET).map),--cref
else
-LDFLAGS +=
+LDFLAGS += $(PTHREAD_LDFLAGS)
endif
LDFLAGS += $(MATH_LIB)
--- /dev/null
+TARGET = hostsim
+
+SRC = hostsim.c
+
+###########################################
+
+include $(AVERSIVE_DIR)/mk/aversive_module.mk
--- /dev/null
+/*
+ * Copyright Droids Corporation
+ * Olivier Matz <zer0@droids-corp.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Revision : $Id: main.c,v 1.10 2009-11-08 17:24:33 zer0 Exp $
+ *
+ */
+
+#ifdef HOST_VERSION
+/*
+ * AVR simulator. This code is used on host (PC for instance) to
+ * generate a signal that will call other aversive modules like
+ * scheduler or uart. The goal is to simulate the behaviour of
+ * hardware interrupts in a unix application.
+ */
+
+#include <aversive.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+#include <string.h>
+#include <pthread.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#ifdef CONFIG_MODULE_SCHEDULER
+#include <scheduler.h>
+#endif
+
+pthread_mutex_t mut;
+static volatile int cpt = 0;
+
+#ifdef SA_SIGINFO
+static void sigusr1(__attribute__((unused)) int sig,
+ __attribute__((unused)) siginfo_t *info,
+ __attribute__((unused)) void *uc)
+#else
+void sigusr1(__attribute__((unused)) int sig)
+#endif
+{
+ pthread_mutex_unlock(&mut);
+
+#ifdef CONFIG_MODULE_SCHEDULER
+ scheduler_interrupt();
+#endif
+}
+
+void host_wait_ms(int ms)
+{
+ struct timeval tv, tv2, diff;
+
+ gettimeofday(&tv, NULL);
+ diff.tv_sec = (1000 * ms) / 1000000;
+ diff.tv_usec = (1000 * ms) % 1000000;
+ timeradd(&tv, &diff, &tv);
+ gettimeofday(&tv2, NULL);
+
+ while (timercmp(&tv2, &tv, <)) {
+ usleep(1000);
+ gettimeofday(&tv2, NULL);
+ }
+}
+
+
+/* sends signal to child */
+void *parent(void *arg)
+{
+ pthread_t *thread = arg;
+ struct timeval cur_tv, prev_tv, tv_millisec;
+ int n;
+
+ gettimeofday(&prev_tv, NULL);
+
+ while (1) {
+ usleep(1000);
+ gettimeofday(&cur_tv, NULL);
+
+ n = 0;
+ while (timercmp(&prev_tv, &cur_tv, <)) {
+ if (n > 5) {
+ /* give some time between subsequent
+ * signals */
+ usleep(100);
+ n = 0;
+ }
+ pthread_mutex_lock(&mut);
+ pthread_kill(*thread, SIGUSR1);
+
+ /* signal was acked */
+ tv_millisec.tv_sec = 0;
+ tv_millisec.tv_usec = 1000;
+ timeradd(&prev_tv, &tv_millisec, &prev_tv);
+ n ++;
+ }
+ }
+
+ pthread_exit(NULL);
+ return NULL;
+}
+
+int hostsim_init(void)
+{
+ struct sigaction sigact;
+ pthread_t parent_id, child_id;
+ int ret;
+
+ pthread_mutex_init(&mut, NULL);
+
+ parent_id = pthread_self();
+
+ pthread_mutex_lock(&mut);
+ ret = pthread_create(&child_id, NULL, parent, (void *)&parent_id);
+ if (ret) {
+ printf("pthread_create() returned %d\n", ret);
+ pthread_mutex_unlock(&mut);
+ return -1;
+ }
+
+ /* register a signal handler, which is interruptible */
+ memset(&sigact, 0, sizeof(sigact));
+ sigemptyset(&sigact.sa_mask);
+ sigact.sa_flags |= SA_NODEFER;
+ sigact.sa_sigaction = sigusr1;
+ sigaction(SIGUSR1, &sigact, NULL);
+
+ /* */
+ if (siginterrupt (SIGUSR1, 0) != 0)
+ return -1;
+
+ pthread_mutex_unlock(&mut);
+
+ return 0;
+}
+#endif /* HOST_VERSION */
--- /dev/null
+/*
+ * Copyright Droids Corporation
+ * Olivier Matz <zer0@droids-corp.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Revision : $Id: main.c,v 1.10 2009-11-08 17:24:33 zer0 Exp $
+ *
+ */
+
+/* initialize hostsim framework */
+int hostsim_init(void);
+
+/* replacement for wait_ms() */
+void host_wait_ms(int ms);
priority_running = old_prio;
}
-/**
+/**
* this function is called from a timer interruption. If an event has
* to be scheduled, it will execute the fonction (IRQ are allowed
* during the execution of the function). This interruption can be
* interrupted by itself too, in this case only events with a higher
* priority can be scheduled.
- *
+ *
* We assume that this function is called from a SIGNAL(), with
* global interrupt flag disabled --> that's why we can use cli() and
* sei() instead of IRQ_LOCK(flags).
#
-# Automatically generated make config: don't edit
+# Automatically generated by make menuconfig: don't edit
#
#
# CONFIG_MCU_ATMEGA645 is not set
# CONFIG_MCU_ATMEGA6450 is not set
CONFIG_MCU_ATMEGA128=y
+# CONFIG_MCU_ATMEGA1281 is not set
# CONFIG_MCU_AT90CAN128 is not set
# CONFIG_MCU_AT94K is not set
# CONFIG_MCU_AT90S1200 is not set
+# CONFIG_MCU_ATMEGA2560 is not set
+# CONFIG_MCU_ATMEGA256 is not set
CONFIG_QUARTZ=16000000
#
CONFIG_OPTM_S=y
CONFIG_MATH_LIB=y
# CONFIG_FDEVOPEN_COMPAT is not set
+# CONFIG_NO_PRINTF is not set
# CONFIG_MINIMAL_PRINTF is not set
CONFIG_STANDARD_PRINTF=y
# CONFIG_ADVANCED_PRINTF is not set
#
# Base modules
#
-
-#
-# Enable math library in generation options to see all modules
-#
CONFIG_MODULE_CIRBUF=y
# CONFIG_MODULE_CIRBUF_LARGE is not set
# CONFIG_MODULE_FIXED_POINT is not set
# CONFIG_MODULE_VECT2 is not set
+# CONFIG_MODULE_GEOMETRY is not set
+CONFIG_MODULE_HOSTSIM=y
CONFIG_MODULE_SCHEDULER=y
+# CONFIG_MODULE_SCHEDULER_STATS is not set
CONFIG_MODULE_SCHEDULER_CREATE_CONFIG=y
# CONFIG_MODULE_SCHEDULER_USE_TIMERS is not set
-CONFIG_MODULE_SCHEDULER_TIMER0=y
-# CONFIG_MODULE_SCHEDULER_MANUAL is not set
+# CONFIG_MODULE_SCHEDULER_TIMER0 is not set
+CONFIG_MODULE_SCHEDULER_MANUAL=y
# CONFIG_MODULE_TIME is not set
# CONFIG_MODULE_TIME_CREATE_CONFIG is not set
+# CONFIG_MODULE_TIME_EXT is not set
+# CONFIG_MODULE_TIME_EXT_CREATE_CONFIG is not set
#
# Communication modules
#
-
-#
-# uart needs circular buffer, mf2 client may need scheduler
-#
CONFIG_MODULE_UART=y
+# CONFIG_MODULE_UART_9BITS is not set
# CONFIG_MODULE_UART_CREATE_CONFIG is not set
+# CONFIG_MODULE_SPI is not set
+# CONFIG_MODULE_SPI_CREATE_CONFIG is not set
# CONFIG_MODULE_I2C is not set
# CONFIG_MODULE_I2C_MASTER is not set
# CONFIG_MODULE_I2C_MULTIMASTER is not set
#
# Hardware modules
#
-# CONFIG_MODULE_TIMER is not set
+CONFIG_MODULE_TIMER=y
# CONFIG_MODULE_TIMER_CREATE_CONFIG is not set
# CONFIG_MODULE_TIMER_DYNAMIC is not set
# CONFIG_MODULE_PWM is not set
# CONFIG_MODULE_PWM_CREATE_CONFIG is not set
+# CONFIG_MODULE_PWM_NG is not set
# CONFIG_MODULE_ADC is not set
# CONFIG_MODULE_ADC_CREATE_CONFIG is not set
# CONFIG_MODULE_RDLINE_KILL_BUF is not set
# CONFIG_MODULE_RDLINE_HISTORY is not set
# CONFIG_MODULE_PARSE is not set
+# CONFIG_MODULE_PARSE_NO_FLOAT is not set
#
# External devices modules
# CONFIG_MODULE_LCD_CREATE_CONFIG is not set
# CONFIG_MODULE_MULTISERVO is not set
# CONFIG_MODULE_MULTISERVO_CREATE_CONFIG is not set
+# CONFIG_MODULE_AX12 is not set
+# CONFIG_MODULE_AX12_CREATE_CONFIG is not set
#
# Brushless motor drivers (you should enable pwm modules to see all)
# CONFIG_MODULE_BRUSHLESS_3PHASE_DIGITAL_HALL_DOUBLE_CREATE_CONFIG is not set
#
-# Encoders
+# Encoders (you need comm/spi for encoders_spi)
#
# CONFIG_MODULE_ENCODERS_MICROB is not set
# CONFIG_MODULE_ENCODERS_MICROB_CREATE_CONFIG is not set
# CONFIG_MODULE_ENCODERS_EIRBOT is not set
# CONFIG_MODULE_ENCODERS_EIRBOT_CREATE_CONFIG is not set
+# CONFIG_MODULE_ENCODERS_SPI is not set
+# CONFIG_MODULE_ENCODERS_SPI_CREATE_CONFIG is not set
#
-# Robot specific modules
+# Robot specific modules (fixed point lib may be needed)
#
# CONFIG_MODULE_ROBOT_SYSTEM is not set
+# CONFIG_MODULE_ROBOT_SYSTEM_USE_F64 is not set
# CONFIG_MODULE_ROBOT_SYSTEM_MOT_AND_EXT is not set
# CONFIG_MODULE_POSITION_MANAGER is not set
+# CONFIG_MODULE_COMPENSATE_CENTRIFUGAL_FORCE is not set
# CONFIG_MODULE_TRAJECTORY_MANAGER is not set
# CONFIG_MODULE_BLOCKING_DETECTION_MANAGER is not set
# CONFIG_MODULE_OBSTACLE_AVOIDANCE is not set
+# CONFIG_MODULE_OBSTACLE_AVOIDANCE_CREATE_CONFIG is not set
#
# Control system modules
#
# CONFIG_MODULE_CONTROL_SYSTEM_MANAGER is not set
-
-#
-# Filters
-#
# CONFIG_MODULE_PID is not set
# CONFIG_MODULE_PID_CREATE_CONFIG is not set
# CONFIG_MODULE_RAMP is not set
# CONFIG_MODULE_BIQUAD is not set
#
-# Crypto modules
+# Radio devices
#
+# CONFIG_MODULE_CC2420 is not set
+# CONFIG_MODULE_CC2420_CREATE_CONFIG is not set
#
-# Crypto modules depend on utils module
+# Crypto modules
#
# CONFIG_MODULE_AES is not set
# CONFIG_MODULE_AES_CTR is not set
#
# Encodings modules
#
-
-#
-# Encoding modules depend on utils module
-#
# CONFIG_MODULE_BASE64 is not set
# CONFIG_MODULE_HAMMING is not set
#
# Debug modules
#
-
-#
-# Debug modules depend on utils module
-#
# CONFIG_MODULE_DIAGNOSTIC is not set
# CONFIG_MODULE_DIAGNOSTIC_CREATE_CONFIG is not set
CONFIG_MODULE_ERROR=y
# CONFIG_AVRDUDE_PROG_BSD is not set
# CONFIG_AVRDUDE_PROG_DAPA is not set
# CONFIG_AVRDUDE_PROG_JTAG1 is not set
+# CONFIG_AVRDUDE_PROG_AVR109 is not set
CONFIG_AVRDUDE_PORT="/dev/parport0"
+CONFIG_AVRDUDE_BAUDRATE=19200
#
# Avarice
CONFIG_AVARICE_DEBUG_PORT=1234
CONFIG_AVARICE_PROG_MKI=y
# CONFIG_AVARICE_PROG_MKII is not set
+# CONFIG_AVRDUDE_CHECK_SIGNATURE is not set
#include <aversive/wait.h>\r
#include <stdio.h>\r
#include <uart.h>\r
+//#include <timer.h>\r
+#include <hostsim.h>\r
\r
uint8_t event_id;\r
\r
\r
void supp(void * nothing)\r
{\r
- scheduler_del_event(event_id);\r
+ scheduler_del_event(event_id);\r
}\r
\r
int main(void)\r
wait_ms(2000);\r
printf("init3\n");\r
\r
+#ifdef HOST_VERSION\r
+ hostsim_init();\r
+#endif\r
+\r
event_id = scheduler_add_periodical_event_priority(f1, NULL, 500000l/SCHEDULER_UNIT, 200);\r
scheduler_add_periodical_event_priority(f2, NULL, 500000l/SCHEDULER_UNIT, 100);\r
scheduler_add_periodical_event(f3, NULL, 1000000l/SCHEDULER_UNIT);\r
- \r
- // scheduler_add_single_event(supp,65);\r
- \r
\r
-#ifdef HOST_VERSION\r
- for (i=0 ; i<50000 ; i++)\r
- scheduler_interrupt();\r
-#endif\r
+ scheduler_add_single_event(supp, NULL, 5000000l/SCHEDULER_UNIT);\r
+\r
+ while (1);\r
+\r
return 0;\r
}\r
\r
SRC += uart_recv9.c uart_recv9_nowait.c
endif
-else # is it ok ??
-SRC = uart_host.c
+else
+SRC = uart_host.c uart_events.c
endif
include $(AVERSIVE_DIR)/mk/aversive_module.mk
#include <uart.h>
#include <uart_private.h>
-
/* this file os a stub for host */
void uart_init(void)
return put_char(c);
}
-void uart_register_tx_event(uint8_t num, void (*f)(char))
-{
- tx_event = f;
-}
-
-void uart_register_rx_event(uint8_t num, void (*f)(char))
-{
- rx_event = f;
-}
TARGET = timer
# List C source files here. (C dependencies are automatically generated.)
+ifeq ($(HOST),avr)
SRC = timer_init.c \
timer_intr.c \
timer_conf_check.c \
timer3_prescaler.c \
timer4_prescaler.c \
timer5_prescaler.c
+else
+SRC = timer_host.c
+endif
include $(AVERSIVE_DIR)/mk/aversive_module.mk
--- /dev/null
+/*
+ * Copyright Droids Corporation, Microb Technology, (2010)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Revision : $Id: timer_init.c,v 1.1.2.4 2009-01-30 20:18:36 zer0 Exp $
+ *
+ */
+
+void timer_init(void)
+{
+}