annotate projects/d-box/prio.cpp @ 39:638bc1ae2500 staging

Improved readibility of the DIGITAL code in the PRU, using register names instead of aliases and expanding some of the macros, removing unused macros. Binaries were not modified
author Giulio Moro <giuliomoro@yahoo.it>
date Wed, 13 May 2015 12:18:10 +0100
parents 8a575ba3ab52
children
rev   line source
andrewm@0 1 /*
andrewm@0 2 * prio.cpp
andrewm@0 3 *
andrewm@0 4 * Created on: May 14, 2014
andrewm@0 5 * Author: Victor Zappi
andrewm@0 6 */
andrewm@0 7
andrewm@0 8 #include "prio.h"
andrewm@0 9 using namespace std;
andrewm@0 10 //-----------------------------------------------------------------------------------------------------------
andrewm@0 11 // set wanted real-time priority to this thread
andrewm@0 12 //-----------------------------------------------------------------------------------------------------------
andrewm@0 13 void set_realtime_priority(int order)
andrewm@0 14 {
andrewm@0 15 int ret;
andrewm@0 16
andrewm@0 17 // We'll operate on the currently running thread.
andrewm@0 18 pthread_t this_thread = pthread_self();
andrewm@0 19 // struct sched_param is used to store the scheduling priority
andrewm@0 20 struct sched_param params;
andrewm@0 21 // We'll set the priority to the maximum.
andrewm@0 22 params.sched_priority = sched_get_priority_max(SCHED_FIFO) - order;
andrewm@0 23
andrewm@0 24 // Attempt to set thread real-time priority to the SCHED_FIFO policy
andrewm@0 25 ret = pthread_setschedparam(this_thread, SCHED_FIFO, &params);
andrewm@0 26 if (ret != 0) {
andrewm@0 27 // Print the error
andrewm@0 28 cout << "Unsuccessful in setting thread realtime prio" << endl;
andrewm@0 29 return;
andrewm@0 30 }
andrewm@0 31
andrewm@0 32 // Now verify the change in thread priority
andrewm@0 33 int policy = 0;
andrewm@0 34 ret = pthread_getschedparam(this_thread, &policy, &params);
andrewm@0 35 if (ret != 0) {
andrewm@0 36 cout << "Couldn't retrieve real-time scheduling parameters" << endl;
andrewm@0 37 return;
andrewm@0 38 }
andrewm@0 39
andrewm@0 40 // Check the correct policy was applied
andrewm@0 41 if(policy != SCHED_FIFO) {
andrewm@0 42 cout << "Scheduling is NOT SCHED_FIFO!" << endl;
andrewm@0 43 }
andrewm@0 44 }
andrewm@0 45
andrewm@0 46 //-----------------------------------------------------------------------------------------------------------
andrewm@0 47
andrewm@0 48