-/* Init
- *
- * This routine is the initialization task for this test program.
- * It is called from init_exec and has the responsibility for creating
- * and starting the tasks that make up the test. If the time of day
- * clock is required for the test, it should also be set to a known
- * value by this function.
- *
- * Input parameters: NONE
- *
- * Output parameters: NONE
- *
- * COPYRIGHT (c) 1989-1999.
- * On-Line Applications Research Corporation (OAR).
- *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rtems.com/license/LICENSE.
- *
- * $Id: init.c,v 1.12.4.1 2003/09/04 18:46:30 joel Exp $
- */
-
#define CONFIGURE_INIT
#include "system_def.h"
#include "system.h"
#include <rtems/monitor.h>
#include <rtems/shell.h>
+#include <errno.h>
#include <frsh.h>
+#include <getopt.h>
+#include <ul_logreg.h>
+#include <ul_log.h>
+#include <rtems/rtems_bsdnet.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+
+
+
+struct rtems_bsdnet_config rtems_bsdnet_config = {
+ NULL, /* Network interface */
+ NULL, /* Use fixed network configuration */
+ 0, /* Default network task priority */
+ 0, /* Default mbuf capacity */
+ 0, /* Default mbuf cluster capacity */
+ "testSystem", /* Host name */
+ "nowhere.com", /* Domain name */
+ "127.0.0.1", /* Gateway */
+ "127.0.0.1", /* Log host */
+ {"127.0.0.1" }, /* Name server(s) */
+ {"127.0.0.1" }, /* NTP server(s) */
+ 0,
+ 0,
+ 0,
+ 0,
+ 0
+};
+
#define BUILD_VERSION_STRING(major,minor,patch) \
rtems_shell_init(m_task_name,m_task_stacksize,m_task_priority,m_devname,m_forever,m_wait)
#endif
+//--------------------------
+#include <rtems/untar.h>
+
+extern int _binary_rootfs_tarfile_start;
+extern int _binary_rootfs_tarfile_size;
+#define TARFILE_START _binary_rootfs_tarfile_start
+#define TARFILE_SIZE _binary_rootfs_tarfile_size
+
+int setup_root_imfs (void) {
+ rtems_status_code status;
+ status = Untar_FromMemory((unsigned char *)(&TARFILE_START), (long)&TARFILE_SIZE);
+ printf("Untar_FromMemory returned %s\n",rtems_status_text(status));
+ return 0;
+}
+
+//--------------------------
+int ul_log_levels_forshell_cb(ul_log_domain_t *domain, void *context)
+{
+ char s[30];
+
+ s[sizeof(s)-1]=0;
+ printf("%s (%d)\n",domain->name, domain->level);
+ return 0;
+}
+
+int ul_log_levels_forshell(int argc, char **argv)
+{
+ int all_fl=0;
+ int res=0;
+ char *line;
+ line = argv[1];
+
+ if(argc<2) all_fl=1;
+ else if(!strcmp(line,"?")) all_fl=1;
+
+ if(all_fl) {
+ printf("Possible log domains are:\n");
+ ul_logreg_for_each_domain(ul_log_levels_forshell_cb, NULL);
+ } else {
+ res=ul_log_domain_arg2levels(line); // option: call this explicitly with "5" => debug mode
+ }
+
+ return res>=0?0:1;
+}
+
+//--------------------------
void
bad_rtems_status(rtems_status_code status, int fail_level, const char *text)
{
return 0;
}
+
+rtems_task Task_1(
+ rtems_task_argument argument
+)
+{
+ int ret;
+ unsigned long i = 0;
+ volatile int j;
+ frsh_vres_id_t vres_id;
+ frsh_rel_time_t budget;
+ frsh_rel_time_t period;
+
+ while(1) {
+ i++;
+
+ for (j=0; j<1000000; j++);
+
+ ret = frsh_thread_get_vres_id(fosa_thread_self(), &vres_id);
+ if (ret) PERROR_AND_EXIT(ret, "frsh_get_vres_id");
+
+ ret = frsh_vres_get_budget_and_period(vres_id, &budget, &period);
+ if (ret) PERROR_AND_EXIT(ret, "frsh_vres_get_budget_and_period");
+
+ printf("Consuming budget %ld ms - %lu\n",
+ fosa_rel_time_to_msec(budget), i);
+ }
+
+ return;
+}
+
+
+
+#define MSEC(x) { x/1000, (x%1000) * 1000000 }
+frsh_utilization_set_t utilization_set = {
+ .size = 3,
+ .utilizations = {
+ { .budget = MSEC(10), .period = MSEC(100), .deadline = MSEC(100) },
+ { .budget = MSEC(20), .period = MSEC(100), .deadline = MSEC(100) },
+ { .budget = MSEC(30), .period = MSEC(100), .deadline = MSEC(100) },
+ },
+};
+
rtems_task Init(
rtems_task_argument ignored
)
{
- rtems_status_code status;
- int ret;
+ frsh_vres_id_t vres;
+ frsh_thread_attr_t attr;
+ frsh_thread_id_t thread;
+ frsh_contract_t contract;
+ int ret;
+ rtems_status_code status;
printf( "\n\nRTEMS v "
BUILD_VERSION_STRING(__RTEMS_MAJOR__ ,__RTEMS_MINOR__ ,__RTEMS_REVISION__)
printf( "Starting application " SW_VER_ID " v "
BUILD_VERSION_STRING(SW_VER_MAJOR,SW_VER_MINOR,SW_VER_PATCH)
"\n" );
+
+ setup_root_imfs(); // file system
+
+ rtems_bsdnet_initialize_network();
-// Task 1 ==============================================
-/* Task_1_name = rtems_build_name( 'T', 'S', 'K', '1' );
+ ul_log_domain_arg2levels("5"); // log level
+
+ rtems_shell_init("SHLL",RTEMS_MINIMUM_STACK_SIZE+0x1000,
+ SHELL_TASK_PRIORITY,"/dev/console",1,0, NULL);
+
+ rtems_shell_add_cmd("testcmd", "app",
+ "test command for shell",
+ testcmd_forshell);
+
+ rtems_shell_add_cmd("loglevel", "app",
+ "set log level for specific domain",
+ ul_log_levels_forshell);
+
+ rtems_monitor_wakeup();
+
+ printf("POSIX: m %d, c %d \n", Configuration_POSIX_API.maximum_mutexes,
+ Configuration_POSIX_API.maximum_condition_variables);
+// status = rtems_task_delete( RTEMS_SELF );
+
+ ret = frsh_init();
+ if (ret) PERROR_AND_EXIT(ret, "frsh_init");
+
+ Task_1_name = rtems_build_name( 'T', 'W', 'R', 'K' );
status = rtems_task_create(
Task_1_name,
check_rtems_status(status, 0, "rtems_task_create of Task_1");
status = rtems_task_start( Task_1_id, Task_1, 0 );
check_rtems_status(status, 0, "rtems_task_start of Task_1\n");
-*/
-
-// Task 2 ==============================================
-/* Task_2_name = rtems_build_name( 'T', 'S', 'K', '2' );
-
- status = rtems_task_create(
- Task_2_name,
- TASK_2_PRIORITY,
- RTEMS_MINIMUM_STACK_SIZE+0x10000,
- RTEMS_DEFAULT_MODES & ~(RTEMS_TIMESLICE_MASK) | RTEMS_TIMESLICE,
- RTEMS_DEFAULT_ATTRIBUTES,
- &Task_2_id
- );
-
- check_rtems_status(status, 0, "rtems_task_create of Task_2");
- status = rtems_task_start( Task_2_id, Task_2, 0 );
- check_rtems_status(status, 0, "rtems_task_start of Task_2\n");
-*/
-// ====================================================
+
+ /* Contract negotiation for CPU */
+ ret = frsh_contract_init(&contract);
+ if (ret) PERROR_AND_EXIT(ret, "frsh_contract_init");
- ret = frsh_init();
-
- rtems_shell_init("SHLL",RTEMS_MINIMUM_STACK_SIZE+0x1000,
- SHELL_TASK_PRIORITY,"/dev/console",1,0, NULL);
+ int variant = 0;
+ bool first = true;
+ while (1) {
+
+ ret = frsh_contract_set_basic_params(&contract,
+ &utilization_set.utilizations[variant].budget,
+ &utilization_set.utilizations[variant].period,
+ FRSH_WT_BOUNDED,
+ FRSH_CT_REGULAR);
+ if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_basic_params");
- rtems_shell_add_cmd("testcmd", "app",
- "test command for shell",
- testcmd_forshell);
+ ret = frsh_contract_set_resource_and_label(&contract, FRSH_RT_PROCESSOR,
+ FRSH_CPU_ID_DEFAULT, "renegotiation test");
+ if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_resource_and_label");
- //rtems_monitor_wakeup();
+ if (first) {
+ ret = frsh_contract_negotiate(&contract, &vres);
+ if (ret) PERROR_AND_EXIT(ret, "frsh_contract_negotiate");
+
+ printf("Aqcpu vres negotiated, vres-ID: %p\n", vres);
+ pthread_attr_init(&attr); //FIXME: fosa
+ ret = frsh_thread_create_and_bind(vres, &thread, &attr,
+ (void*) NULL, (void*) NULL);
+ if (ret) PERROR_AND_EXIT(ret, "frsh_thread_create_and_bind");
+ first = false;
+ } else {
+ ret = frsh_contract_renegotiate_sync(&contract, vres);
+ if (ret == 0) {
+ printf("Renegotiation accepted\n");
+ } else if (ret == FRSH_ERR_CONTRACT_REJECTED) {
+ printf("Renegotiaton REJECTED\n");
+ } else
+ PERROR_AND_EXIT(ret, "frsh_contract_renegotiate_sync");
+ }
+ sleep(5);
+ variant++;
+ if (variant >= utilization_set.size) variant = 0;
+ }
+
+ pthread_join(thread.pthread_id, (void**) NULL); //FIXME:fosa
+
+ ret = frsh_contract_cancel(vres);
+ if (ret) PERROR_AND_EXIT(ret, "frsh_contract_cancel");
status = rtems_task_delete( RTEMS_SELF );
printf( "*** END OF TEST3 ***\n" );
- exit( 0 );
+ exit( 0 );
}
+