#include <unistd.h>
#include <time.h> // For clock_nanosleep
-#include "frsh_error.h"
#include "fosa.h"
-#include "frsh_fosa.h"
#include "timespec_operations.h"
+#include <misc/error_checks.h>
+
+
+
/*************************/
/* D E F I N I T I O N S */
/*************************/
int main()
{
- int terror = -1;
- frsh_thread_attr_t periodic_attr;
- frsh_signal_t signal_set[1];
- frsh_thread_id_t periodic_tid;
+ fosa_thread_attr_t periodic_attr;
+ fosa_signal_t signal_set[1];
+ fosa_thread_id_t periodic_tid;
memset(&context, 0, sizeof(context) );
/* We set the signal mask */
signal_set[0] = FOSA_LONG_JUMP_SIGNAL;
- PRW( fosa_set_accepted_signals(signal_set, 1) );
+
+ CHK( fosa_set_accepted_signals(signal_set, 1) );
/* We create a new thread with a given priority */
- PRW( frsh_thread_attr_init(&periodic_attr) );
- PRW( fosa_thread_attr_set_prio(&periodic_attr, PERIODIC_THREAD_PRIORITY) );
- PRW( fosa_thread_create(&periodic_tid, &periodic_attr, periodic_code, NULL) );
+ CHK( fosa_thread_attr_init(&periodic_attr) );
+ CHK( fosa_thread_attr_set_prio(&periodic_attr, PERIODIC_THREAD_PRIORITY) );
+ CHK( fosa_thread_create(&periodic_tid, &periodic_attr, periodic_code, NULL) );
printf("Main goes to sleep...\n");
static void *periodic_code(void *thread_arg)
{
- int terror = -1;
-
struct timespec period = {2, 500000000}; // 2.5 secs
- frsh_thread_id_t jump_handler_thread;
+ fosa_thread_id_t jump_handler_thread;
- frsh_signal_t jump_signal;
- frsh_signal_info_t jump_signal_info;
+ fosa_signal_t jump_signal;
+ fosa_signal_info_t jump_signal_info;
fosa_clock_id_t clock_id;
fosa_timer_id_t jump_timer;
/* - This creates the thread that will wait for */
/* FOSA_JUMP_SIGNAL */
/************************************************/
- PXW( fosa_long_jump_install_handler(&jump_signal, &jump_handler_thread) );
+ CHK( fosa_long_jump_install_handler(&jump_signal, &jump_handler_thread) );
/* We create a budget timer using the thread's CPU clock */
/* */
/* */
/* This signal is delivered to the handler thread. */
/*********************************************************/
- PXW( fosa_thread_get_cputime_clock( fosa_thread_self(), &clock_id) );
+ CHK( fosa_thread_get_cputime_clock( fosa_thread_self(), &clock_id) );
jump_signal_info.sival_ptr = &context;
- PXW( fosa_timer_create_with_receiver(clock_id, jump_signal, jump_signal_info,
+ CHK( fosa_timer_create_with_receiver(clock_id, jump_signal, jump_signal_info,
&jump_timer, jump_handler_thread) );
jumped = 0;
/* For statistical purposes we read the activation time */
- PXW( fosa_clock_get_time(FOSA_CLOCK_REALTIME, &activation_time) );
+ CHK( fosa_clock_get_time(FOSA_CLOCK_REALTIME, &activation_time) );
/************************************/
/* We arm the jump_timer */
- PXW( fosa_timer_arm(jump_timer, false, &budget) );
+ CHK( fosa_timer_arm(jump_timer, false, &budget) );
/* This is the point where the jump returns */
- PXW( fosa_long_jump_save_context(&context) );
+ CHK( fosa_long_jump_save_context(&context) );
/* Query if we come from a jump */
- PXW( fosa_long_jump_was_performed(&context, &jumped) );
+ CHK( fosa_long_jump_was_performed(&context, &jumped) );
if (!jumped)
{
/* HERE COMES THE WORK THAT CAN BE INTERRUPTED */
work_under_a_interruptible_budget();
- PRW( fosa_timer_disarm(&jump_timer, NULL) );
+ CHK( fosa_timer_disarm(jump_timer, NULL) );
printf("NOT JUMPPED\n");
}
else
/* Now we measure the time duration of the block */
/*************************************************/
- PXW( fosa_clock_get_time(FOSA_CLOCK_REALTIME, &old_activation_time) );
+ CHK( fosa_clock_get_time(FOSA_CLOCK_REALTIME, &old_activation_time) );
decr_timespec(&old_activation_time, &activation_time);
printf("Execution time: %6.3f\n", t2d(old_activation_time) );
i++;
printf("Start regular work\n");
- frsh_eat(&exec_time);
+ fosa_eat(&exec_time);
/* Once in every 5 executions we work over the budget */
if (i % 5 == 0)
{
- frsh_eat(&exec_time);
- frsh_eat(&exec_time);
- frsh_eat(&exec_time);
- frsh_eat(&exec_time);
- frsh_eat(&exec_time);
- frsh_eat(&exec_time);
+ fosa_eat(&exec_time);
+ fosa_eat(&exec_time);
+ fosa_eat(&exec_time);
+ fosa_eat(&exec_time);
+ fosa_eat(&exec_time);
+ fosa_eat(&exec_time);
}
printf("End regular work\n");