Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMustafa Ozcelikors2017-10-11 14:13:12 +0000
committerMustafa Ozcelikors2017-10-11 14:13:12 +0000
commita00af06ffb02d43992a9b50b6b5869b12e030b7b (patch)
tree28fbd2e2d2616da9e9a092f94bebfae029853a99
parent27db3549bd59458424b7c09fd681d5cff3055c57 (diff)
downloadorg.eclipse.app4mc.examples-a00af06ffb02d43992a9b50b6b5869b12e030b7b.tar.gz
org.eclipse.app4mc.examples-a00af06ffb02d43992a9b50b6b5869b12e030b7b.tar.xz
org.eclipse.app4mc.examples-a00af06ffb02d43992a9b50b6b5869b12e030b7b.zip
ROVER - Buzzer, button handler task added
Signed-off-by: Mustafa Ozcelikors <mozcelikors@gmail.com>
-rw-r--r--rover/src/tasks/external_gpio_task.cpp107
-rw-r--r--rover/src/tasks/external_gpio_task.h40
2 files changed, 147 insertions, 0 deletions
diff --git a/rover/src/tasks/external_gpio_task.cpp b/rover/src/tasks/external_gpio_task.cpp
new file mode 100644
index 0000000..dee9559
--- /dev/null
+++ b/rover/src/tasks/external_gpio_task.cpp
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 2017 Eclipse Foundation, FH Dortmund and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Description:
+ * External GPIO task for handling buttons and buzzer for Rover
+ *
+ * Contributors:
+ * M.Ozcelikors <mozcelikors@gmail.com>, created 11.10.2017
+ *
+*/
+
+#include "external_gpio_task.h"
+
+#include <ctime>
+#include <wiringPi.h>
+#include <softTone.h>
+#include <unistd.h>
+#include "../timing/timing.h"
+#include "../api/basic_psys_rover.h"
+#include "../interfaces.h"
+#include <pthread.h>
+
+#include "../pthread_monitoring/collect_thread_name.h"
+#include "../RaspberryTest.h"
+
+void setupBuzzer (void)
+{
+ softToneCreate(BUZZER_PIN);
+}
+
+/* Checks global variable buzzer_status */
+/* 1-> ON 0-> OFF */
+void buzzerHandler (void)
+{
+ if ( buzzer_status_shared == 0 )
+ {
+ softToneWrite (BUZZER_PIN, BUZZER_OFF_FREQ);
+ }
+ else
+ {
+ softToneWrite (BUZZER_PIN, BUZZER_ON_FREQ);
+ }
+}
+
+void turnBuzzerOn (void)
+{
+ pthread_mutex_lock(&buzzer_status_shared_lock);
+ buzzer_status_shared = 1;
+ pthread_mutex_unlock(&buzzer_status_shared_lock);
+}
+
+void turnBuzzerOff (void)
+{
+ pthread_mutex_lock(&buzzer_status_shared_lock);
+ buzzer_status_shared = 0;
+ pthread_mutex_unlock(&buzzer_status_shared_lock);
+}
+
+void *External_GPIO_Task(void *arg)
+{
+ timing extgpio_task_tmr;
+
+ CollectThreadName("External_GPIO_Task");
+
+ extgpio_task_tmr.setTaskID("GPIO");
+ extgpio_task_tmr.setDeadline(1);
+ extgpio_task_tmr.setPeriod(1);
+
+ /* Setup Buzzer */
+ setupBuzzer();
+
+ while (1)
+ {
+ extgpio_task_tmr.recordStartTime();
+ extgpio_task_tmr.calculatePreviousSlackTime();
+
+ //Task content starts here -----------------------------------------------
+
+ /* Handle buzzer operation */
+ buzzerHandler();
+
+ //Task content ends here -------------------------------------------------
+
+ extgpio_task_tmr.recordEndTime();
+ extgpio_task_tmr.calculateExecutionTime();
+ extgpio_task_tmr.calculateDeadlineMissPercentage();
+ extgpio_task_tmr.incrementTotalCycles();
+ pthread_mutex_lock(&extgpio_task_ti_l);
+ extgpio_task_ti.deadline = extgpio_task_tmr.getDeadline();
+ extgpio_task_ti.deadline_miss_percentage = extgpio_task_tmr.getDeadlineMissPercentage();
+ extgpio_task_ti.execution_time = extgpio_task_tmr.getExecutionTime();
+ extgpio_task_ti.period = extgpio_task_tmr.getPeriod();
+ extgpio_task_ti.prev_slack_time = extgpio_task_tmr.getPrevSlackTime();
+ extgpio_task_ti.task_id = extgpio_task_tmr.getTaskID();
+ extgpio_task_ti.start_time = extgpio_task_tmr.getStartTime();
+ extgpio_task_ti.end_time = extgpio_task_tmr.getEndTime();
+ pthread_mutex_unlock(&extgpio_task_ti_l);
+ extgpio_task_tmr.sleepToMatchPeriod();
+ }
+
+ /* the function must return something - NULL will do */
+ return NULL;
+}
diff --git a/rover/src/tasks/external_gpio_task.h b/rover/src/tasks/external_gpio_task.h
new file mode 100644
index 0000000..822ecd3
--- /dev/null
+++ b/rover/src/tasks/external_gpio_task.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2017 Eclipse Foundation, FH Dortmund and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Description:
+ * External GPIO task for handling buttons and buzzer for Rover - Header file
+ *
+ * Contributors:
+ * M.Ozcelikors <mozcelikors@gmail.com>, created 11.10.2017
+ *
+*/
+
+#ifndef TASKS_EXTERNAL_GPIO_TASK_H_
+#define TASKS_EXTERNAL_GPIO_TASK_H_
+
+#include <stdio.h>
+#include <stdlib.h>
+
+/* Defines */
+
+/* Buzzer */
+#define BUZZER_PIN 28 //BCM-20, wiringpi 28
+#define BUZZER_ON_FREQ 200
+#define BUZZER_OFF_FREQ 0
+
+/* Shutdown Button */
+#define SHUTDOWN_BUTTON_PIN 24 //BCM-21, wiringpi 24
+
+/* User Button */
+#define USER_BUTTON_PIN 27 //BCM-16, wiringpi 27
+
+/* Interfaces */
+void *External_GPIO_Task(void * arg);
+void turnBuzzerOn (void);
+void turnBuzzerOff (void);
+
+#endif /* TASKS_EXTERNAL_GPIO_TASK_H_ */

Back to the top