summaryrefslogtreecommitdiff
path: root/cesar/test_general/ecos/src
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/test_general/ecos/src')
-rw-r--r--cesar/test_general/ecos/src/bentry.c81
-rw-r--r--cesar/test_general/ecos/src/exception.c72
-rw-r--r--cesar/test_general/ecos/src/hello_world.c22
-rw-r--r--cesar/test_general/ecos/src/interrupt.c101
-rw-r--r--cesar/test_general/ecos/src/mesbox.c91
-rw-r--r--cesar/test_general/ecos/src/mutex.c105
-rw-r--r--cesar/test_general/ecos/src/one_thread.c51
-rw-r--r--cesar/test_general/ecos/src/pci_int.c130
-rw-r--r--cesar/test_general/ecos/src/threaddelay.c50
-rw-r--r--cesar/test_general/ecos/src/timer_int.c137
-rw-r--r--cesar/test_general/ecos/src/two_thread.c79
11 files changed, 919 insertions, 0 deletions
diff --git a/cesar/test_general/ecos/src/bentry.c b/cesar/test_general/ecos/src/bentry.c
new file mode 100644
index 0000000000..31126e4e1f
--- /dev/null
+++ b/cesar/test_general/ecos/src/bentry.c
@@ -0,0 +1,81 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file test_general/ecos-test/src/bentry.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * Function test of the alignement on the targets
+ */
+#include "common/std.h"
+
+#include <cyg/kernel/kapi.h>
+#include <cyg/hal/hal_arch.h>
+
+struct cp_bentry_sai_stpf_t
+{
+ BITFIELDS_WORD
+ (
+ /** Start Time Present Flag. */
+ uint stpf:1;,
+ /** Global Link Id. */
+ uint glid:7;,
+ /** Start Time. */
+ uint st:12;,
+ /** End Time. */
+ uint et:12;
+ );
+};
+typedef struct cp_bentry_sai_stpf_t cp_bentry_sai_stpf_t;
+
+struct cp_bentry_persistent_schedule_struct_t
+{
+ BITFIELDS_WORD
+ (
+ uint behdr:8;,
+ uint belen:8;,
+ uint pscd:3;,
+ uint cscd:3;,
+ uint rsvd1:2;,
+ uint ns:6;,
+ uint rsvd2:2;,
+ );
+ u8 sai;
+};
+typedef struct cp_bentry_persistent_schedule_struct_t cp_bentry_persistent_schedule_struct_t;
+
+void
+cyg_user_start (void)
+{
+ u8 blk[512];
+
+ cp_bentry_persistent_schedule_struct_t *bentry;
+ cp_bentry_sai_stpf_t *sai;
+
+ // laranjeiro
+ // date : 2008/01/07
+ // TODO fill this correctly
+ // Actually only a schedule is generated for the CSMA mode only.
+
+ bentry = (cp_bentry_persistent_schedule_struct_t *) &blk[11];
+
+ bentry->behdr = 0x1;
+ bentry->belen = 0x6;
+ bentry->pscd = 0x2;
+ bentry->cscd = 0x3;
+
+ // First allocation of persistent schedule.
+ // Configuration on CSMA only mode, the glid = 0xff.
+ bentry->ns = 1;
+ sai = (cp_bentry_sai_stpf_t *) &bentry->sai;
+ sai->stpf = true;
+ sai->glid = 0xFF;
+ sai->st = 0x0;
+ sai->et = 3905;
+}
+
diff --git a/cesar/test_general/ecos/src/exception.c b/cesar/test_general/ecos/src/exception.c
new file mode 100644
index 0000000000..09f6dbd55f
--- /dev/null
+++ b/cesar/test_general/ecos/src/exception.c
@@ -0,0 +1,72 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file exception.c
+ * \brief how to catch an exception
+ * \ingroup
+ *
+ * this is a test program to check eCos well work
+ */
+
+#include <cyg/kernel/kapi.h>
+#include <cyg/infra/diag.h>
+#include <cyg/hal/hal_intr.h>
+#include "common/std.h"
+
+void system_call_exception(cyg_addrword_t data, cyg_code_t number, cyg_addrword_t info)
+{
+ switch(number)
+ {
+ case CYGNUM_HAL_EXCEPTION_ILLEGAL_INSTRUCTION:
+ diag_printf("eCos: Exception Error (Illegal Instruction)!!!\n");
+ break;
+
+ case CYGNUM_HAL_EXCEPTION_DATA_UNALIGNED_ACCESS:
+ diag_printf("eCos: Exception Error (Data Access Unaligned)!!!\n");
+ break;
+ default:
+ diag_printf("eCos: Exception Error (Unknown)!!!\n");
+ }
+// cyg_hal_sys_exit(1);
+}
+
+void cyg_user_start(void)
+{
+ unsigned int *ptr = (unsigned int*)0x00000001;
+ cyg_exception_handler_t *oldHandler;
+ cyg_addrword_t oldData;
+
+ //config UART
+ unsigned int *uart_scaler = (unsigned int*)0x8000007C;
+ unsigned int *uart_ctrl = (unsigned int*)0x80000078;
+ *uart_scaler = 0xF4; //soit 75MHz / (8 * 38400)
+ *uart_ctrl = 0x3; //enable TX and RX
+
+ diag_write_string("debut du main\n");
+
+ cyg_exception_set_handler(CYGNUM_HAL_EXCEPTION_ILLEGAL_INSTRUCTION,
+ &system_call_exception,
+ 0,
+ &oldHandler,
+ &oldData);
+ cyg_exception_set_handler(CYGNUM_HAL_EXCEPTION_DATA_UNALIGNED_ACCESS,
+ &system_call_exception,
+ 0,
+ &oldHandler,
+ &oldData);
+
+ diag_write_string("exception enregistrees\n");
+
+ // 1st exception : undefined instruction
+ asm volatile ("unimp 0\n\t");
+ // 2nd exception : unaligned address
+ *ptr = 12;
+
+ diag_write_string("fin du main\n");
+}
+
diff --git a/cesar/test_general/ecos/src/hello_world.c b/cesar/test_general/ecos/src/hello_world.c
new file mode 100644
index 0000000000..6de4d5c0ce
--- /dev/null
+++ b/cesar/test_general/ecos/src/hello_world.c
@@ -0,0 +1,22 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file hello_world.c
+ * \brief hello world program
+ * \ingroup
+ */
+
+#include <cyg/infra/diag.h>
+#include "common/std.h"
+
+int main(void)
+{
+ diag_write_string("hello by eCos je ne sais plus quoi dire mais il faut bien faire une longue phrase ttttttttttttttt\n");
+ return 0;
+}
+
diff --git a/cesar/test_general/ecos/src/interrupt.c b/cesar/test_general/ecos/src/interrupt.c
new file mode 100644
index 0000000000..8679e9eaeb
--- /dev/null
+++ b/cesar/test_general/ecos/src/interrupt.c
@@ -0,0 +1,101 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file interrupt.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+
+#include <cyg/kernel/kapi.h>
+#include <cyg/infra/diag.h>
+
+static cyg_interrupt int1;
+static cyg_handle_t int1_handle;
+static cyg_sem_t data_ready;
+
+#define CYGNUM_HAL_PRI_HIGH 0
+
+//
+// Interrupt service routine for interrupt 1.
+//
+cyg_uint32 interrupt_1_isr(
+ cyg_vector_t vector,
+ cyg_addrword_t data)
+{
+ diag_write_char('i');
+ // Block this interrupt from occurring until
+ // the DSR completes.
+ cyg_interrupt_mask(vector);
+
+ // Tell the processor that we have received
+ // the interrupt.
+ cyg_interrupt_acknowledge(vector);
+
+ // Tell the kernel that chained interrupt processing
+ // is done and the DSR needs to be executed next.
+ return(CYG_ISR_HANDLED | CYG_ISR_CALL_DSR);
+}
+
+//
+// Deferred service routine for interrupt 1.
+//
+void interrupt_1_dsr(
+ cyg_vector_t vector,
+ cyg_ucount32 count,
+ cyg_addrword_t data)
+{
+ diag_write_char('d');
+ // Signal the thread to run for further processing.
+ cyg_semaphore_post(&data_ready);
+
+ // Allow this interrupt to occur again.
+ cyg_interrupt_unmask(vector);
+}
+
+//
+// Main starting point for the application.
+//
+void cyg_user_start(
+ void)
+{
+ cyg_vector_t int1_vector = CYGNUM_HAL_INTERRUPT_8;
+ cyg_priority_t int1_priority = CYGNUM_HAL_PRI_HIGH;
+
+ // Initialize the semaphore used for interrupt 1.
+ cyg_semaphore_init(&data_ready, 0);
+
+ //
+ // Create interrupt 1.
+ //
+ cyg_interrupt_create(
+ int1_vector,
+ int1_priority,
+ 0,
+ &interrupt_1_isr,
+ &interrupt_1_dsr,
+ &int1_handle,
+ &int1);
+
+ // Attach the interrupt created to the vector.
+ cyg_interrupt_attach(int1_handle);
+
+ // Unmask the interrupt we just configured.
+ cyg_interrupt_unmask(int1_vector);
+
+ diag_write_char('m');
+ while(1)
+ {
+// diag_write_string("Waiting semaphore...\n");
+// // Wait semaphore
+// cyg_semaphore_wait(&data_ready);
+// diag_write_string("Thank you DSR, I will continue\n\n");
+ }
+}
+
diff --git a/cesar/test_general/ecos/src/mesbox.c b/cesar/test_general/ecos/src/mesbox.c
new file mode 100644
index 0000000000..f7f463f1c1
--- /dev/null
+++ b/cesar/test_general/ecos/src/mesbox.c
@@ -0,0 +1,91 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file mesbox.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+
+#include <cyg/kernel/kapi.h>
+#include <cyg/infra/diag.h>
+
+#define THREAD_STACK_SIZE (20480 / sizeof(int))
+
+int thread_a_stack[THREAD_STACK_SIZE];
+cyg_handle_t thread_a_handle;
+cyg_thread thread_a_obj;
+int thread_b_stack[THREAD_STACK_SIZE];
+cyg_handle_t thread_b_handle;
+cyg_thread thread_b_obj;
+
+cyg_mbox mbox;
+cyg_handle_t mbox_handle;
+
+char transfert_mess[] = "oh what a wonderful mailbox";
+
+//
+// Thread A.
+//
+void thread_a(cyg_addrword_t index)
+{
+ while (1)
+ {
+ // Delay for 5 seconds (10ms * 500ticks).
+ cyg_thread_delay(500);
+
+ // Send a message to Thread B.
+ cyg_mbox_put(mbox_handle, (void *)transfert_mess);
+ }
+}
+
+//
+// Thread B.
+//
+void thread_b(cyg_addrword_t index)
+{
+ char *message;
+
+ while (1)
+ {
+ // Wait for the message.
+ message = (char*) cyg_mbox_get(mbox_handle);
+
+ // Make sure we received the message before attempting
+ // to process it.
+ if ( message != NULL )
+ {
+ // Process the message.
+ diag_printf("Message received : %s\n", message);
+ }
+ }
+}
+
+//
+// Main.
+//
+void cyg_user_start(void)
+{
+ cyg_thread_create(12, thread_a, (cyg_addrword_t) 0,
+ "Thread A", &thread_a_stack, THREAD_STACK_SIZE,
+ &thread_a_handle, &thread_a_obj);
+ cyg_thread_create(13, thread_b, (cyg_addrword_t) 0,
+ "Thread B", &thread_b_stack, THREAD_STACK_SIZE,
+ &thread_b_handle, &thread_b_obj);
+
+ cyg_mbox_create(&mbox_handle, &mbox);
+
+ cyg_thread_resume(thread_a_handle);
+ cyg_thread_resume(thread_b_handle);
+
+ diag_write_string("Starting Scheduler...\n");
+
+ cyg_scheduler_start();
+}
+
diff --git a/cesar/test_general/ecos/src/mutex.c b/cesar/test_general/ecos/src/mutex.c
new file mode 100644
index 0000000000..390bbc4a39
--- /dev/null
+++ b/cesar/test_general/ecos/src/mutex.c
@@ -0,0 +1,105 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file mutex.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+#include <cyg/kernel/kapi.h>
+#include <cyg/infra/diag.h>
+#include <cyg/io/io.h>
+#include <stdio.h>
+
+#define THREAD_STACK_SIZE (40960 / sizeof(int))
+
+int thread_a_stack[THREAD_STACK_SIZE];
+cyg_handle_t thread_a_handle;
+cyg_thread thread_a_obj;
+int thread_b_stack[THREAD_STACK_SIZE];
+cyg_handle_t thread_b_handle;
+cyg_thread thread_b_obj;
+
+cyg_mutex_t mut_shared;
+
+unsigned char transfert_message[] = "Nobody";
+
+//
+// Thread A.
+//
+void thread_a(cyg_addrword_t index)
+{
+ unsigned char write_buffer[] = "Thread A";
+
+ // Run this thread forever.
+ while (1)
+ {
+ // Delay for 5 seconds (10ms * 500ticks).
+ cyg_thread_delay(500);
+
+ // Get the mutex.
+ cyg_mutex_lock(&mut_shared);
+
+ diag_printf("Thrd A : %s\n",transfert_message);
+ // Write data to the global buffer.
+ memcpy(transfert_message, write_buffer, sizeof(write_buffer));
+
+ // Release the mutex.
+ cyg_mutex_unlock(&mut_shared);
+ }
+}
+
+//
+// Thread B.
+//
+void thread_b(cyg_addrword_t index)
+{
+ unsigned char write_buffer[] = "Thread B";
+
+ // Run this thread forever.
+ while (1)
+ {
+ // Delay for 2 seconds (10ms * 200ticks).
+ cyg_thread_delay(200);
+
+ // Get the mutex.
+ cyg_mutex_lock(&mut_shared);
+
+ diag_printf("Thrd B : %s\n",transfert_message);
+ // Write data to the global buffer.
+ memcpy(transfert_message, write_buffer, sizeof(write_buffer));
+
+ // Release the mutex.
+ cyg_mutex_unlock(&mut_shared);
+ }
+}
+
+//
+// Main.
+//
+void cyg_user_start(void)
+{
+ cyg_thread_create(12, thread_a, (cyg_addrword_t) 0,
+ "Thread A", &thread_a_stack, THREAD_STACK_SIZE,
+ &thread_a_handle, &thread_a_obj);
+ cyg_thread_create(12, thread_b, (cyg_addrword_t) 0,
+ "Thread B", &thread_b_stack, THREAD_STACK_SIZE,
+ &thread_b_handle, &thread_b_obj);
+
+ // Mutex creation
+ cyg_mutex_init(&mut_shared);
+
+ cyg_thread_resume(thread_a_handle);
+ cyg_thread_resume(thread_b_handle);
+
+ diag_write_string("Starting Scheduler...\n");
+
+ cyg_scheduler_start();
+}
+
diff --git a/cesar/test_general/ecos/src/one_thread.c b/cesar/test_general/ecos/src/one_thread.c
new file mode 100644
index 0000000000..12bade4ad4
--- /dev/null
+++ b/cesar/test_general/ecos/src/one_thread.c
@@ -0,0 +1,51 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file one_thread.c
+ * \brief test program with only one thread
+ * \ingroup
+ *
+ * this is a test program to check eCos well work
+ */
+
+#include <cyg/kernel/kapi.h>
+#include <cyg/infra/diag.h>
+
+#define MY_THREAD_STACK_SIZE (4096 / sizeof(int))
+
+int my_thread_stack[MY_THREAD_STACK_SIZE];
+cyg_handle_t my_thread_handle;
+cyg_thread my_thread_obj;
+
+void my_thread(cyg_addrword_t index)
+{
+ unsigned int my_counter = 0;
+// while(my_counter < 30)
+ while(1)
+ {
+ diag_printf("ct=%d\n",my_counter);
+// diag_printf("la valeur de mon compteur qui est le meilleur et qui va marcher maintenant est ct=%d\n",my_counter);
+// diag_write_string("la valeur de mon compteur qui est le meilleur et qui va marcher maintenant est de on sait pas encore ahahahahah\n");
+// diag_printf("la valeur de mon compteur qui est le meilleur et qui va marcher maintenant est de on sait pas encore ahahahahah\n");
+ my_counter++;
+ }
+}
+
+void cyg_user_start(void)
+{
+
+ cyg_thread_create(12, my_thread, (cyg_addrword_t) 0,
+ "My Thread", &my_thread_stack, MY_THREAD_STACK_SIZE,
+ &my_thread_handle, &my_thread_obj);
+
+ cyg_thread_resume(my_thread_handle);
+// diag_write_string("scheduler starting...\n");
+
+ cyg_scheduler_start();
+}
+
diff --git a/cesar/test_general/ecos/src/pci_int.c b/cesar/test_general/ecos/src/pci_int.c
new file mode 100644
index 0000000000..c547c2e120
--- /dev/null
+++ b/cesar/test_general/ecos/src/pci_int.c
@@ -0,0 +1,130 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file pci_int.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+
+#include <cyg/kernel/kapi.h>
+#include <cyg/hal/drv_api.h>
+#include <cyg/infra/diag.h>
+
+//
+// Local defines
+//
+#define MY_THREAD_STACK_SIZE (4096 / sizeof(int))
+#define CYGNUM_HAL_PRI_HIGH 0
+#define PCI_INT CYGNUM_HAL_INTERRUPT_5
+
+//
+// Static variables
+//
+static int my_thread_stack[MY_THREAD_STACK_SIZE];
+static cyg_handle_t my_thread_handle;
+static cyg_thread my_thread_obj;
+
+static cyg_interrupt intpci;
+static cyg_handle_t intpci_handle;
+static cyg_sem_t data_ready;
+
+//
+// Thread.
+//
+void my_thread(cyg_addrword_t index)
+{
+ while(1)
+ {
+ diag_write_string("Waiting pci_handler semaphore...\n");
+ // Wait semaphore
+ cyg_semaphore_wait(&data_ready);
+ diag_write_string("Thank you PCI DSR, I will continue\n\n");
+ }
+}
+
+//
+// Interrupt service routine for interrupt pci.
+//
+cyg_uint32 interrupt_pci_isr(
+ cyg_vector_t vector,
+ cyg_addrword_t data)
+{
+ // Block this interrupt from occurring until
+ // the DSR completes.
+ cyg_drv_interrupt_mask(vector);
+
+ // Tell the processor that we have received
+ // the interrupt.
+ cyg_drv_interrupt_acknowledge(vector);
+
+ diag_write_char('i');
+ // Tell the kernel that chained interrupt processing
+ // is done and the DSR needs to be executed next.
+ return CYG_ISR_CALL_DSR;
+}
+
+//
+// Deferred service routine for interrupt pci.
+//
+void interrupt_pci_dsr(
+ cyg_vector_t vector,
+ cyg_ucount32 count,
+ cyg_addrword_t data)
+{
+ // Signal the thread to run for further processing.
+ cyg_semaphore_post(&data_ready);
+
+ // Allow this interrupt to occur again.
+ cyg_drv_interrupt_unmask(vector);
+}
+
+//
+// Main.
+//
+void cyg_user_start(void)
+{
+ cyg_vector_t intpci_vector = PCI_INT;
+ cyg_priority_t intpci_priority = CYGNUM_HAL_PRI_HIGH;
+
+
+ // Thread Creation
+ cyg_thread_create(12, my_thread, (cyg_addrword_t) 0,
+ "My Thread", &my_thread_stack, MY_THREAD_STACK_SIZE,
+ &my_thread_handle, &my_thread_obj);
+
+
+ // Initialize the semaphore used for interrupt pci.
+ cyg_semaphore_init(&data_ready, 0);
+
+ // Create interrupt pci
+ cyg_drv_interrupt_create(
+ intpci_vector,
+ intpci_priority,
+ 0,
+ &interrupt_pci_isr,
+ &interrupt_pci_dsr,
+ &intpci_handle,
+ &intpci);
+
+ // Attach the interrupt created to the vector.
+ cyg_drv_interrupt_attach(intpci_handle);
+
+ // Unmask the interrupt we just configured.
+ diag_write_string("Unmasking Interrupts....\n");
+ cyg_drv_interrupt_unmask(intpci_vector);
+
+ // Starting Thread
+ diag_write_string("Starting Thread....\n\n");
+ cyg_thread_resume(my_thread_handle);
+
+ // Starting Scheduler for Thread and DSR
+ cyg_scheduler_start();
+}
+
diff --git a/cesar/test_general/ecos/src/threaddelay.c b/cesar/test_general/ecos/src/threaddelay.c
new file mode 100644
index 0000000000..ce15022a66
--- /dev/null
+++ b/cesar/test_general/ecos/src/threaddelay.c
@@ -0,0 +1,50 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file threaddelay.c
+ * \brief test program for eCos compilation
+ * \ingroup
+ *
+ * this is a test program to check eCos well work with the tick timer
+ */
+
+#include <cyg/kernel/kapi.h>
+#include <cyg/infra/diag.h>
+
+#define MY_THREAD_STACK_SIZE (8192 / sizeof(int))
+
+int my_thread_stack[MY_THREAD_STACK_SIZE];
+cyg_handle_t my_thread_handle;
+cyg_thread my_thread_obj;
+
+void my_thread(cyg_addrword_t index)
+{
+ unsigned long my_counter = 0;
+ diag_write_string("my thread started\n");
+ while(1)
+ {
+ diag_printf("count=%ld, time=%lld\n",my_counter, cyg_current_time());
+ cyg_thread_delay(1000); //wait 10 seconds (1000 ecos ticks)
+ my_counter++;
+ }
+}
+
+void cyg_user_start(void)
+{
+
+ cyg_thread_create(12, my_thread, (cyg_addrword_t) 0,
+ "My Thread", &my_thread_stack, MY_THREAD_STACK_SIZE,
+ &my_thread_handle, &my_thread_obj);
+
+ cyg_thread_resume(my_thread_handle);
+
+ diag_write_string("Starting Scheduler... ");
+
+ cyg_scheduler_start();
+}
+
diff --git a/cesar/test_general/ecos/src/timer_int.c b/cesar/test_general/ecos/src/timer_int.c
new file mode 100644
index 0000000000..5c729e1037
--- /dev/null
+++ b/cesar/test_general/ecos/src/timer_int.c
@@ -0,0 +1,137 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file timer_int.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+
+#include <cyg/kernel/kapi.h>
+#include <cyg/hal/drv_api.h>
+#include <cyg/infra/diag.h>
+
+//
+// Local defines
+//
+#define MY_THREAD_STACK_SIZE (4096 / sizeof(int))
+#define CYGNUM_HAL_PRI_HIGH 0
+#define TIMER2_INT CYGNUM_HAL_INTERRUPT_9
+#define TIMER2_CONF 0x80000058
+#define TIMER2_RELOAD 0x80000054
+
+//
+// Static variables
+//
+static int my_thread_stack[MY_THREAD_STACK_SIZE];
+static cyg_handle_t my_thread_handle;
+static cyg_thread my_thread_obj;
+
+static cyg_interrupt inttimer;
+static cyg_handle_t inttimer_handle;
+static cyg_sem_t data_ready;
+
+//
+// Thread.
+//
+void my_thread(cyg_addrword_t index)
+{
+ while(1)
+ {
+ diag_write_string("Waiting timer2 semaphore...\n");
+ // Wait semaphore
+ cyg_semaphore_wait(&data_ready);
+ diag_write_string("Thank you timer2 DSR, I will continue\n\n");
+ }
+}
+
+//
+// Interrupt service routine for interrupt timer2.
+//
+cyg_uint32 interrupt_timer_isr(
+ cyg_vector_t vector,
+ cyg_addrword_t data)
+{
+ // Block this interrupt from occurring until
+ // the DSR completes.
+ cyg_drv_interrupt_mask(vector);
+
+ // Tell the processor that we have received
+ // the interrupt.
+ cyg_drv_interrupt_acknowledge(vector);
+
+ diag_write_char('i');
+ // Tell the kernel that chained interrupt processing
+ // is done and the DSR needs to be executed next.
+ return CYG_ISR_CALL_DSR;
+}
+
+//
+// Deferred service routine for interrupt timer2.
+//
+void interrupt_timer_dsr(
+ cyg_vector_t vector,
+ cyg_ucount32 count,
+ cyg_addrword_t data)
+{
+ // Signal the thread to run for further processing.
+ cyg_semaphore_post(&data_ready);
+
+ // Allow this interrupt to occur again.
+ cyg_drv_interrupt_unmask(vector);
+}
+
+//
+// Main.
+//
+void cyg_user_start(void)
+{
+ cyg_vector_t inttimer_vector = TIMER2_INT;
+ cyg_priority_t inttimer_priority = CYGNUM_HAL_PRI_HIGH;
+ unsigned int *timer2_conf = (unsigned int*)TIMER2_CONF;
+ unsigned int *timer2_reload = (unsigned int*)TIMER2_RELOAD;
+
+
+ // Thread Creation
+ cyg_thread_create(12, my_thread, (cyg_addrword_t) 0,
+ "My Thread", &my_thread_stack, MY_THREAD_STACK_SIZE,
+ &my_thread_handle, &my_thread_obj);
+
+ // Configure the timer2
+ *timer2_reload = (5000000 - 1); //corresponding to 2seconds (1us * 5000000)
+ *timer2_conf = 0x3; //enable the timer2 with autoreload mode
+
+ // Initialize the semaphore used for interrupt timer2.
+ cyg_semaphore_init(&data_ready, 0);
+
+ // Create interrupt timer2
+ cyg_drv_interrupt_create(
+ inttimer_vector,
+ inttimer_priority,
+ 0,
+ &interrupt_timer_isr,
+ &interrupt_timer_dsr,
+ &inttimer_handle,
+ &inttimer);
+
+ // Attach the interrupt created to the vector.
+ cyg_drv_interrupt_attach(inttimer_handle);
+
+ // Unmask the interrupt we just configured.
+ diag_write_string("Unmasking Interrupts....\n");
+ cyg_drv_interrupt_unmask(inttimer_vector);
+
+ // Starting Thread
+ diag_write_string("Starting Thread....\n\n");
+ cyg_thread_resume(my_thread_handle);
+
+ // Starting Scheduler for Thread and DSR
+ cyg_scheduler_start();
+}
+
diff --git a/cesar/test_general/ecos/src/two_thread.c b/cesar/test_general/ecos/src/two_thread.c
new file mode 100644
index 0000000000..d99f5dec87
--- /dev/null
+++ b/cesar/test_general/ecos/src/two_thread.c
@@ -0,0 +1,79 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file two_thread.c
+ * \brief test program with only two threads
+ * \ingroup
+ *
+ * this is a test program to check eCos well work
+ */
+
+#include <cyg/kernel/kapi.h>
+#include <cyg/infra/diag.h>
+
+#define THREAD_STACK_SIZE (4096 / sizeof(int))
+
+int thread_a_stack[THREAD_STACK_SIZE];
+int thread_b_stack[THREAD_STACK_SIZE];
+cyg_handle_t thread_a_handle;
+cyg_handle_t thread_b_handle;
+cyg_thread thread_a_obj;
+cyg_thread thread_b_obj;
+
+//
+// Thread A.
+//
+void thread_a(cyg_addrword_t index)
+{
+ unsigned int my_counter = 0;
+ while(1)
+ {
+ diag_printf("A: ct=%d\n",my_counter);
+ my_counter++;
+
+ // Delay for 5 seconds (10ms * 500ticks).
+ cyg_thread_delay(500);
+ }
+}
+
+//
+// Thread B.
+//
+void thread_b(cyg_addrword_t index)
+{
+ unsigned int my_counter = 0;
+ while(1)
+ {
+ diag_printf("B: ct=%d\n",my_counter);
+ my_counter++;
+
+ // Delay for 2 seconds (10ms * 200ticks).
+ cyg_thread_delay(200);
+ }
+}
+
+//
+// Main.
+//
+void cyg_user_start(void)
+{
+
+ cyg_thread_create(12, thread_a, (cyg_addrword_t) 0,
+ "Thread B", &thread_a_stack, THREAD_STACK_SIZE,
+ &thread_a_handle, &thread_a_obj);
+ cyg_thread_create(12, thread_b, (cyg_addrword_t) 0,
+ "Thread A", &thread_b_stack, THREAD_STACK_SIZE,
+ &thread_b_handle, &thread_b_obj);
+
+ cyg_thread_resume(thread_a_handle);
+ cyg_thread_resume(thread_b_handle);
+ diag_write_string("scheduler starting...\n");
+
+ cyg_scheduler_start();
+}
+