C8051F32x firmware infrastructure
Sign in or create your account | Project List | Help
C8051F32x firmware infrastructure Git Source Tree
Root/
| 1 | /* |
| 2 | * f32x/rt.c - Enable/disable real-time scheduling priority |
| 3 | * |
| 4 | * Written 2008 by Werner Almesberger |
| 5 | * Copyright 2008 Werner Almesberger |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | */ |
| 12 | |
| 13 | /* |
| 14 | * The full ritual would also include mlock'ing, but we skip that. |
| 15 | */ |
| 16 | |
| 17 | |
| 18 | #include <stdlib.h> |
| 19 | #include <stdio.h> |
| 20 | #include <sched.h> |
| 21 | |
| 22 | |
| 23 | static void realtimize(void) |
| 24 | { |
| 25 | struct sched_param prm; |
| 26 | |
| 27 | prm.sched_priority = sched_get_priority_max(SCHED_FIFO); |
| 28 | if (prm.sched_priority < 0) { |
| 29 | perror("sched_get_priority_max SCHED_FIFO"); |
| 30 | exit(1); |
| 31 | } |
| 32 | if (sched_setscheduler(0, SCHED_FIFO, &prm) < 0) { |
| 33 | perror("sched_setscheduler SCHED_FIFO"); |
| 34 | exit(1); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | |
| 39 | static void unrealtime(void) |
| 40 | { |
| 41 | struct sched_param prm = { .sched_priority = 0 }; |
| 42 | |
| 43 | if (sched_setscheduler(0, SCHED_OTHER, &prm) < 0) { |
| 44 | perror("sched_setscheduler SCHED_OTHER"); |
| 45 | exit(1); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | |
| 50 | void rt(int on) |
| 51 | { |
| 52 | if (on) |
| 53 | realtimize(); |
| 54 | else |
| 55 | unrealtime(); |
| 56 | } |
| 57 |
Branches:
master
