Hi
I am havinf trouble getting my litle program to work.
I make two threads each writting to the seriel port, I exspected them
to both get some output on the port, probably mixed in strange ways.
(It should be a demo of when to use syncronisation objects.)
But all runtime is given to just the one thread.
They have the same priority, mlque is used as scheduler, and
CYGSEM_KERNEL_SCHED_TIMESLICE is true
It does not apear the that it is the serial port that somehows just
belongs to one thread or other error, setting a breakpoint in the
other thread will newer trigger
Below is my small program, it gives just BBBB... on seriel console
#include <cyg/kernel/kapi.h> // Kernel API.
#include <cyg/hal/hal_arch.h> // hal specific defines.
#include <cyg/io/io.h>
#include <cyg/io/serialio.h>
#include <cyg/error/strerror.h>
#include <stdio.h>
#define THREAD_STACK_SIZE (CYGNUM_HAL_STACK_SIZE_TYPICAL )
#define THREAD_PRIORITY 12
int thread_b_stack[ THREAD_STACK_SIZE ];
int thread_c_stack[ THREAD_STACK_SIZE ];
cyg_thread thread_b_obj;
cyg_thread thread_c_obj;
cyg_handle_t thread_b_hdl;
cyg_handle_t thread_c_hdl;
cyg_io_handle_t serhand;
// Thread B
void thread_b( cyg_addrword_t data )
{
char * strW = "BBBBBBBBBBBBBBBBBBBBBB\n";
cyg_uint32 len;
len = strlen(strW);
while( 1 )
{
cyg_io_write(serhand, strW , &len);
}
}
// Thread C
void thread_c( cyg_addrword_t data )
{
char * strW = "CCCCCCCCCCCCCCC\n";
cyg_uint32 len;
len = strlen(strW);
while( 1 )
{
cyg_io_write(serhand, strW , &len); /*breakpoint here wil only
trigger once, then never again.*/
}
}
int main( void )
{
cyg_io_lookup("/dev/ser0", serhand);
Cyg_ErrNo error;
error = cyg_io_lookup("/dev/ser0", &serhand );
if (error < 0) {
printf("Error %d = %s opening serial port.\n",
errno, strerror(error));
return -1;
}
//
// Create our two threads.
//
cyg_thread_create(
THREAD_PRIORITY,
thread_b,
(cyg_addrword_t) 68,
"Thread B",
(void *)thread_b_stack,
THREAD_STACK_SIZE,
&thread_b_hdl,
&thread_b_obj );
cyg_thread_create(
THREAD_PRIORITY ,
thread_c,
(cyg_addrword_t) 68,
"Thread C",
(void *)thread_c_stack,
THREAD_STACK_SIZE,
&thread_c_hdl,
&thread_c_obj );
// Resume the threads so they start when the scheduler begins.
cyg_thread_resume( thread_b_hdl );
cyg_thread_resume( thread_c_hdl );
return 0;
}