Browse Source

real-time functions

Cyrille 10 years ago
parent
commit
1a2f811625
3 changed files with 39 additions and 3 deletions
  1. 2 2
      emit/home_easy.c
  2. 25 0
      emit/utils.c
  3. 12 1
      emit/utils.h

+ 2 - 2
emit/home_easy.c

@@ -139,8 +139,8 @@ void sendHomeEasyCommand(unsigned char* id, char section, unsigned char nb, unsi
 	BYTE_BUFFER command;
 	unsigned int i;
 	command = createHomeEasyCommand(id, section, nb, on);
-	sendHomeEasyBit(TRIGGER0);
-	sendHomeEasyBit(TRIGGER1);
+	sendHomeEasyBit(START_OF_DATA);
+	sendHomeEasyBit(START_OF_FRAME);
 	for(i=0; i<repeat; i++) {
 		sendHomeEasyBytes(command);
 		sendHomeEasyBit(END_OF_FRAME);

+ 25 - 0
emit/utils.c

@@ -2,6 +2,7 @@
 #include <unistd.h>
 #include <sys/time.h>
 #include <malloc.h>
+#include <sched.h>
 #include "utils.h"
 
 
@@ -27,3 +28,27 @@ struct timeval* showTime(struct timeval* start)
     fprintf(stderr, "%lus %lums %luµs\n", tv_sec, tv_usec/1000, tv_sec % 1000);
     return stop;
 }
+
+/**
+ * Switch to real-time mode
+ */
+void scheduler_realtime()
+{
+    struct sched_param p;
+    p.__sched_priority = sched_get_priority_max(SCHED_RR);
+    if( sched_setscheduler( 0, SCHED_RR, &p ) == -1 ) {
+        perror("Failed to switch to realtime scheduler.");
+    }
+}
+
+/**
+ * Exit from real-time mode
+ */
+void scheduler_standard()
+{
+    struct sched_param p;
+    p.__sched_priority = 0;
+    if( sched_setscheduler( 0, SCHED_OTHER, &p ) == -1 ) {
+        perror("Failed to switch to normal scheduler.");
+    }
+}

+ 12 - 1
emit/utils.h

@@ -15,4 +15,15 @@
  */
 struct timeval* showTime(struct timeval* start);
 
-#endif
+/**
+ * Switch to real-time mode
+ */
+void scheduler_realtime();
+
+/**
+ * Exit from real-time mode
+ */
+void scheduler_standard();
+
+
+#endif