/*
 *
 *  Semaphore Example
 *
 *
 */

#include <deblin/vhal.h>
#include <time.h>
#include <pthread.h>
#include <rtl_ipc.h>
#include <semaphore.h>
#include <rtl_barrier.h>
#include <rtl_conf.h>
#include <unistd.h>


static unsigned long valor7=0x0;
static unsigned long valor8=0x0;


pthread_t thread7;
pthread_t thread8;

#if _RTL_POSIX_SEMS 
sem_t sem;
#endif

void *task7(void *arg)
{
#if _RTL_POSIX_SEMS 
  pthread_make_periodic_np (pthread_self(), gethrtime(),3000000000ULL);
  
  while(1)
  {
    sem_wait(&sem);
    pthread_wait_np ();
    sem_post(&sem);
    
    hexatoascii(valor7,(char *) 0xb8000+3*5*2);
    valor7++;
  };
#else
  while(1) {};
#endif
  return 0;
};

void *task8(void *arg)
{
  int ret;
  int aux;
  
#if _RTL_POSIX_SEMS 
  while(1)
  {
    ret = sem_wait(&sem);
    hexatoascii(valor8,(char *) 0xb8000+4*5*2);
    valor8++;
    sem_post(&sem);
//    usleep(100);
    for (aux=0;aux<=0x10ffff;aux++) {};    
  };
#else
  while(1) {};
#endif
  return 0;
};




