|
56 | 56 | #include "rtapi.h" |
57 | 57 | #include <hal.h> |
58 | 58 | #include "hal/hal_priv.h" |
59 | | -#include "uspace_rtapi.hh" |
60 | | - |
61 | | -std::atomic_int WithRoot::level; |
62 | | -static uid_t euid, ruid; |
63 | | - |
64 | | -#include "rtapi/uspace_common.h" |
65 | | - |
66 | | -WithRoot::WithRoot() { |
67 | | - if(!level++) { |
68 | | -#ifdef __linux__ |
69 | | - setfsuid(euid); |
70 | | -#endif |
71 | | - } |
72 | | -} |
73 | | - |
74 | | -WithRoot::~WithRoot() { |
75 | | - if(!--level) { |
76 | | -#ifdef __linux__ |
77 | | - setfsuid(ruid); |
78 | | -#endif |
79 | | - } |
80 | | -} |
| 59 | +#include "uspace_common.h" |
81 | 60 |
|
82 | 61 | namespace |
83 | 62 | { |
@@ -625,14 +604,6 @@ struct rtapi_module { |
625 | 604 | #define MAX_MODULES 64 |
626 | 605 | #define MODULE_OFFSET 32768 |
627 | 606 |
|
628 | | -rtapi_task::rtapi_task() |
629 | | - : magic{}, id{}, owner{}, uses_fp{}, stacksize{}, prio{}, |
630 | | - period{}, nextstart{}, |
631 | | - ratio{}, pll_correction{}, pll_correction_limit{}, |
632 | | - arg{}, taskcode{} |
633 | | - |
634 | | -{} |
635 | | - |
636 | 607 | namespace |
637 | 608 | { |
638 | 609 | struct PosixTask : rtapi_task |
@@ -887,130 +858,6 @@ RtapiApp &App() |
887 | 858 | /* data for all tasks */ |
888 | 859 | struct rtapi_task *task_array[MAX_TASKS]; |
889 | 860 |
|
890 | | -/* Priority functions. Uspace uses POSIX task priorities. */ |
891 | | - |
892 | | -int RtapiApp::prio_highest() const |
893 | | -{ |
894 | | - return sched_get_priority_max(policy); |
895 | | -} |
896 | | - |
897 | | -int RtapiApp::prio_lowest() const |
898 | | -{ |
899 | | - return sched_get_priority_min(policy); |
900 | | -} |
901 | | - |
902 | | -int RtapiApp::prio_higher_delta() const { |
903 | | - if(rtapi_prio_highest() > rtapi_prio_lowest()) { |
904 | | - return 1; |
905 | | - } |
906 | | - return -1; |
907 | | -} |
908 | | - |
909 | | -int RtapiApp::prio_bound(int prio) const { |
910 | | - if(rtapi_prio_highest() > rtapi_prio_lowest()) { |
911 | | - if (prio >= rtapi_prio_highest()) |
912 | | - return rtapi_prio_highest(); |
913 | | - if (prio < rtapi_prio_lowest()) |
914 | | - return rtapi_prio_lowest(); |
915 | | - } else { |
916 | | - if (prio <= rtapi_prio_highest()) |
917 | | - return rtapi_prio_highest(); |
918 | | - if (prio > rtapi_prio_lowest()) |
919 | | - return rtapi_prio_lowest(); |
920 | | - } |
921 | | - return prio; |
922 | | -} |
923 | | - |
924 | | -bool RtapiApp::prio_check(int prio) const { |
925 | | - if(rtapi_prio_highest() > rtapi_prio_lowest()) { |
926 | | - return (prio <= rtapi_prio_highest()) && (prio >= rtapi_prio_lowest()); |
927 | | - } else { |
928 | | - return (prio <= rtapi_prio_lowest()) && (prio >= rtapi_prio_highest()); |
929 | | - } |
930 | | -} |
931 | | - |
932 | | -int RtapiApp::prio_next_higher(int prio) const |
933 | | -{ |
934 | | - prio = prio_bound(prio); |
935 | | - if(prio != rtapi_prio_highest()) |
936 | | - return prio + prio_higher_delta(); |
937 | | - return prio; |
938 | | -} |
939 | | - |
940 | | -int RtapiApp::prio_next_lower(int prio) const |
941 | | -{ |
942 | | - prio = prio_bound(prio); |
943 | | - if(prio != rtapi_prio_lowest()) |
944 | | - return prio - prio_higher_delta(); |
945 | | - return prio; |
946 | | -} |
947 | | - |
948 | | -int RtapiApp::allocate_task_id() |
949 | | -{ |
950 | | - for(int n=0; n<MAX_TASKS; n++) |
951 | | - { |
952 | | - rtapi_task **taskptr = &(task_array[n]); |
953 | | - if(__sync_bool_compare_and_swap(taskptr, (rtapi_task*)0, TASK_MAGIC_INIT)) |
954 | | - return n; |
955 | | - } |
956 | | - return -ENOSPC; |
957 | | -} |
958 | | - |
959 | | -int RtapiApp::task_new(void (*taskcode) (void*), void *arg, |
960 | | - int prio, int owner, unsigned long int stacksize, int /*uses_fp*/) { |
961 | | - /* check requested priority */ |
962 | | - if (!prio_check(prio)) |
963 | | - { |
964 | | - rtapi_print_msg(RTAPI_MSG_ERR,"rtapi:task_new prio is not in bound lowest %i prio %i highest %i\n", |
965 | | - rtapi_prio_lowest(), prio, rtapi_prio_highest()); |
966 | | - return -EINVAL; |
967 | | - } |
968 | | - |
969 | | - /* label as a valid task structure */ |
970 | | - int n = allocate_task_id(); |
971 | | - if(n < 0) return n; |
972 | | - |
973 | | - struct rtapi_task *task = do_task_new(); |
974 | | - if(stacksize < (1024*1024)) stacksize = (1024*1024); |
975 | | - task->id = n; |
976 | | - task->owner = owner; |
977 | | - /* uses_fp is deprecated and ignored; always save FPU state */ |
978 | | - task->uses_fp = 1; |
979 | | - task->arg = arg; |
980 | | - task->stacksize = stacksize; |
981 | | - task->taskcode = taskcode; |
982 | | - task->prio = prio; |
983 | | - task->magic = TASK_MAGIC; |
984 | | - task_array[n] = task; |
985 | | - |
986 | | - /* and return handle to the caller */ |
987 | | - |
988 | | - return n; |
989 | | -} |
990 | | - |
991 | | -rtapi_task *RtapiApp::get_task(int task_id) { |
992 | | - if(task_id < 0 || task_id >= MAX_TASKS) return NULL; |
993 | | - /* validate task handle */ |
994 | | - rtapi_task *task = task_array[task_id]; |
995 | | - if(!task || task == TASK_MAGIC_INIT || task->magic != TASK_MAGIC) |
996 | | - return NULL; |
997 | | - |
998 | | - return task; |
999 | | -} |
1000 | | - |
1001 | | -void RtapiApp::unexpected_realtime_delay(rtapi_task *task, int /*nperiod*/) { |
1002 | | - static int printed = 0; |
1003 | | - if(!printed) |
1004 | | - { |
1005 | | - rtapi_print_msg(RTAPI_MSG_ERR, |
1006 | | - "Unexpected realtime delay on task %d with period %ld\n" |
1007 | | - "This Message will only display once per session.\n" |
1008 | | - "Run the Latency Test and resolve before continuing.\n", |
1009 | | - task->id, task->period); |
1010 | | - printed = 1; |
1011 | | - } |
1012 | | -} |
1013 | | - |
1014 | 861 | int Posix::task_delete(int id) |
1015 | 862 | { |
1016 | 863 | auto task = ::rtapi_get_task<PosixTask>(id); |
@@ -1286,16 +1133,7 @@ long rtapi_clock_set_period(long nsecs) |
1286 | 1133 | return App().clock_set_period(nsecs); |
1287 | 1134 | } |
1288 | 1135 |
|
1289 | | -long RtapiApp::clock_set_period(long nsecs) |
1290 | | -{ |
1291 | | - if(nsecs == 0) return period; |
1292 | | - if(period != 0) { |
1293 | | - rtapi_print_msg(RTAPI_MSG_ERR, "attempt to set period twice\n"); |
1294 | | - return -EINVAL; |
1295 | | - } |
1296 | | - period = nsecs; |
1297 | | - return period; |
1298 | | -} |
| 1136 | + |
1299 | 1137 |
|
1300 | 1138 |
|
1301 | 1139 | int rtapi_task_new(void (*taskcode) (void*), void *arg, |
|
0 commit comments