Subversion Repositories shark

Rev

Rev 1242 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1232 giacomo 1
#include <kernel/kern.h>
2
 
3
#include "fsf_contract.h"
4
#include "fsf_server.h"
1233 giacomo 5
#include "func.h"
1232 giacomo 6
 
7
/* Activate task output */
8
#define TASK_OUTPUT
9
 
1233 giacomo 10
int cal_cycles=0;
11
struct timespec zero_time;                                        
1243 giacomo 12
extern struct loader_task loader_task_list[];
1241 giacomo 13
extern int total_loader_task;
1232 giacomo 14
 
1239 giacomo 15
/* oneshot Soft and hard Task */
16
void *oneshot_task(void *arg)
1232 giacomo 17
{
18
  long long i,exec_cycles = 0;
19
  int act = 0;
1234 giacomo 20
  struct loader_task *l = (struct loader_task *)(arg);
1232 giacomo 21
  char tmp[20];
22
 
1236 giacomo 23
  #ifdef TASK_OUTPUT
24
    sprintf(tmp,"X[%06d]",act);
25
    printf_xy((get_current_exec_task() % 5) * 9 + 34,get_current_exec_task()  / 5 + 5, GREEN, tmp);
26
  #endif
1232 giacomo 27
 
1236 giacomo 28
  exec_cycles = (long long)(TIMESPEC2USEC(&l->exec[act])) * CALIBRATION_DELTA / cal_cycles;
1232 giacomo 29
 
1236 giacomo 30
  for (i=0;i<exec_cycles;i++) calibration_func();
1232 giacomo 31
 
1236 giacomo 32
  generic_task_endcycle();
1239 giacomo 33
 
34
  return NULL;
35
 
36
}
37
 
38
void * periodic_task(void *arg)
39
{
40
  long long i,exec_cycles = 0;
41
  int act = 0;
42
  struct loader_task *l = (struct loader_task *)(arg);
43
  char tmp[20];
44
 
45
  while(1) {
46
 
47
    #ifdef TASK_OUTPUT
48
      sprintf(tmp,"X[%06d]",act);
49
      printf_xy((get_current_exec_task() % 5) * 9 + 34,get_current_exec_task()  / 5 + 5, GREEN, tmp);
50
    #endif
1235 giacomo 51
 
1239 giacomo 52
    exec_cycles = (long long)(TIMESPEC2USEC(&l->exec[act])) * CALIBRATION_DELTA / cal_cycles;
53
 
54
    for (i=0;i<exec_cycles;i++) calibration_func();
55
 
56
    generic_task_endcycle();
57
 
58
    act++;
59
 
60
  }                                                                                                                
1232 giacomo 61
  return NULL;
62
 
63
}
64
 
1239 giacomo 65
void * back_task(void *arg)
66
{
67
  long long i,exec_cycles = 0;
68
  int act = 0;
69
  struct loader_task *l = (struct loader_task *)(arg);
70
  char tmp[20];
71
 
72
  while(1) {
73
 
74
    #ifdef TASK_OUTPUT
75
      sprintf(tmp,"X[%06d]",act);
76
      printf_xy((get_current_exec_task() % 5) * 9 + 34,get_current_exec_task()  / 5 + 5, GREEN, tmp);
77
    #endif
78
 
79
    exec_cycles = (long long)(TIMESPEC2USEC(&l->exec[0])) * CALIBRATION_DELTA / cal_cycles;
80
 
81
    for (i=0;i<exec_cycles;i++) calibration_func();
82
 
83
    act++;
84
 
85
  }                                                                                                                
86
  return NULL;
87
 
88
}
89
 
1232 giacomo 90
/* Task create */
1239 giacomo 91
/* this function create the task struct in memory */
92
 
1234 giacomo 93
void loader_task_create()
1232 giacomo 94
{
95
 
1234 giacomo 96
  struct loader_task *current = loader_task_list;
1241 giacomo 97
  int i=0, k=0;
1232 giacomo 98
 
1241 giacomo 99
  while (k <total_loader_task) {
1232 giacomo 100
    k++;
1243 giacomo 101
 
1232 giacomo 102
    for (i=0; i < current->number; i++) {
1239 giacomo 103
 
1232 giacomo 104
      pthread_t j;
1243 giacomo 105
      int err = 0;
1242 giacomo 106
 
1239 giacomo 107
      switch(current->task_type)  {
108
      case PAR_TASK_OS:
1242 giacomo 109
        err = generic_create_thread(current->server,&j,NULL,oneshot_task,(void *)current,generic_get_task_model(current));
1239 giacomo 110
        break;
111
      case PAR_TASK_BT:
1242 giacomo 112
        err = generic_create_thread(current->server,&j,NULL,back_task,(void *)current,generic_get_task_model(current));
1239 giacomo 113
        break;
114
      case PAR_TASK_CT:
1242 giacomo 115
        err = generic_create_thread(current->server,&j,NULL,periodic_task,(void *)current,generic_get_task_model(current));
1239 giacomo 116
        break;
117
      }
1232 giacomo 118
      if (err) {
119
        cprintf("Error fsf task creating\n");
120
        sys_end();
121
      }
122
 
123
    }
124
 
1234 giacomo 125
    current = &loader_task_list[k];
126
 
1232 giacomo 127
  }
128
 
1241 giacomo 129
  cprintf("Created %d loader tasks\n",k);
1234 giacomo 130
 
1232 giacomo 131
 
132
}
133
 
134
 
1239 giacomo 135
int start_environment()
1232 giacomo 136
{
137
 
1234 giacomo 138
  struct timespec total = {20,0};
1233 giacomo 139
 
1232 giacomo 140
  generic_calibrate_cycle();
1234 giacomo 141
 
1232 giacomo 142
  generic_fsfinit();
143
 
1234 giacomo 144
  loader_task_create();
1232 giacomo 145
 
1243 giacomo 146
  generic_start_simulation();
147
 
1233 giacomo 148
  generic_set_simulation_time(&total);
1232 giacomo 149
 
150
  return 0;
151
 
152
}