This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Problem with cosine and multithread...


Hi again, I manage to compile eCos so I wrote a little program to try it:

-------------------------------------------
#include <cyg/kernel/kapi.h>

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include "led.h"

/* now declare (and allocate space for) some kernel objects,
   like the two threads we will use */
cyg_thread thread_s[2];  /* space for two thread objects */

char stack[2][4096];  /* space for two 4K stacks */

/* now the handles for the threads */
cyg_handle_t cosine_handle, led_handle;

/* and now variables for the procedure which is the thread */
cyg_thread_entry_t cosine_prog, led_prog;

/* and now a mutex to protect calls to the C library */
cyg_mutex_t cliblock;

/* we install our own startup routine which sets up threads */

void cyg_user_start(void)
{
  printf("Entering twothreads' cyg_user_start() function\n");

  cyg_mutex_init(&cliblock);

  cyg_thread_create(4, cosine_prog, (cyg_addrword_t) 0,
      "Coseno", (void *) stack[0], 4096,
      &cosine_handle, &thread_s[0]);
  cyg_thread_create(4, led_prog, (cyg_addrword_t) 1,
      "LED's", (void *) stack[1], 4096,
      &led_handle, &thread_s[1]);

  cyg_thread_resume(cosine_handle);
  cyg_thread_resume(led_handle);
  cyg_scheduler_start();

  cyg_mutex_lock(&cliblock);
  printf("Won't reach here ...??\n");
  cyg_mutex_unlock(&cliblock);
}


void led_prog(cyg_addrword_t data)
{
   int i=0;
 do
 { /*yg_mutex_lock(&cliblock);
  printf("Green Led On!!\nWaiting 3 seconds\n\n");
    cyg_mutex_unlock(&cliblock);*/
  LED_4_ON;
  cyg_thread_delay(100);
  /*cyg_mutex_lock(&cliblock);
  printf("Green Led Off!!\nWaiting 0,03 seconds\n\n");
  cyg_mutex_unlock(&cliblock);*/
        LED_4_OFF;
  cyg_thread_delay(100);
  i++;
   } while (i<=9);

}

void cosine_prog(cyg_addrword_t data)
{
 int i=0;
 cyg_mutex_lock(&cliblock);
 printf("\nCosine of %d is %2.4g\n",i,cos(i));
 cyg_mutex_unlock(&cliblock);
 i++;
 cyg_thread_delay(50);
}
----------------------------------
Don't know why but the led_prog runs great. The cosine_prog doesn't,It rans
once and then it doens't run anymore.
BTW how can I reset the board or anything similar so that every time I need
to run the prog in gdb I don't have to press the reset button.
Another question is how can I build a program without debug info and all
that .text and place it in flash so I can do a GO 0X4(where I dl the prog)
and ran it without the gdb if that possible.
Thanks in advance for the help.

Best regards Carlos Sobrinho
PS: One small question.What's the difference between cyg_thread thread_s[2];
char stack[2][4096] AND static cyg_thread thread_s[2]; static char
stack[2][4096]; and what does volatile do in C,Sorry for the anoying
questions that this should be for you but they aren't for me...


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]