2010-08-15 13:58:08 +00:00
/*
* Copyright 2010 Stefan Lankes , Chair for Operating Systems ,
* RWTH Aachen University
*
* Licensed under the Apache License , Version 2.0 ( the " License " ) ;
* you may not use this file except in compliance with the License .
* You may obtain a copy of the License at
*
* http : //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing , software
* distributed under the License is distributed on an " AS IS " BASIS ,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
* See the License for the specific language governing permissions and
* limitations under the License .
*
* This file is part of MetalSVM .
*/
# include <metalsvm/stddef.h>
# include <metalsvm/stdio.h>
# include <metalsvm/time.h>
# include <metalsvm/tasks.h>
# include <metalsvm/semaphore.h>
# include <metalsvm/mailbox.h>
# include <metalsvm/syscall.h>
2011-04-24 07:27:27 -07:00
# ifdef CONFIG_ROCKCREEK
# include <asm/icc.h>
2011-06-21 12:31:01 +02:00
# include "server.h"
# include "client.h"
# include <asm/RCCE_lib.h>
# include <asm/RCCE.h>
# include <asm/RCCE_lib.h>
# include <asm/iRCCE.h>
# include <asm/iRCCE_lib.h>
# include <asm/SCC_API.h>
2011-04-24 07:27:27 -07:00
# endif
2010-08-15 13:58:08 +00:00
static sem_t consuming , producing ;
static mailbox_int32_t mbox ;
static int val = 0 ;
static int STDCALL consumer ( void * arg )
{
int i , m = 0 ;
for ( i = 0 ; i < 5 ; i + + ) {
sem_wait ( & consuming ) ;
kprintf ( " Consumer got %d \n " , val ) ;
val = 0 ;
sem_post ( & producing ) ;
}
for ( i = 0 ; i < 5 ; i + + ) {
mailbox_int32_fetch ( & mbox , & m ) ;
kprintf ( " Got mail %d \n " , m ) ;
}
return 0 ;
}
static int STDCALL producer ( void * arg )
{
int i ;
int mail [ 5 ] = { 1 , 2 , 3 , 4 , 5 } ;
for ( i = 0 ; i < 5 ; i + + ) {
sem_wait ( & producing ) ;
kprintf ( " Produce value: current val %d \n " , val ) ;
val = 42 ;
sem_post ( & consuming ) ;
}
for ( i = 0 ; i < 5 ; i + + ) {
//kprintf("Send mail %d\n", mail[i]);
mailbox_int32_post ( & mbox , mail [ i ] ) ;
}
return 0 ;
}
static int STDCALL foo ( void * arg )
{
int i ;
if ( ! arg )
return 0 ;
for ( i = 0 ; i < 5 ; i + + ) {
kputs ( ( char * ) arg ) ;
sleep ( 1 ) ;
}
return 42 ;
}
2011-04-24 07:27:27 -07:00
# ifdef CONFIG_ROCKCREEK
static int STDCALL ping ( void * arg )
{
int i ;
for ( i = 0 ; i < 20 ; i + + ) {
icc_ping ( 1 ) ;
2011-05-17 08:13:20 -07:00
HALT ;
2011-04-24 07:27:27 -07:00
}
return 0 ;
}
# endif
2010-08-15 13:58:08 +00:00
static int STDCALL join_test ( void * arg )
{
2011-03-02 13:49:36 +01:00
tid_t id , ret ;
int result = - 1234 ;
2010-08-15 13:58:08 +00:00
2011-03-02 13:49:36 +01:00
create_kernel_task ( & id , foo , " Hello from foo2 \n " ) ;
kprintf ( " Wait for child %u \n " , id ) ;
do {
ret = wait ( & result ) ;
} while ( ret ! = id ) ;
kprintf ( " Child %u finished: result = %d \n " , id , result ) ;
2010-08-15 13:58:08 +00:00
return 0 ;
}
2011-05-29 15:54:33 +02:00
void ping_send_now ( ) ;
2011-06-21 12:31:01 +02:00
__inline int get_core_no ( void )
{
unsigned int tmp ;
unsigned int pid ;
unsigned int x , y , z ;
/* Determine the local IP address from the core number in the
* tile ID register
*/
tmp = ReadConfigReg ( local_crb + RCK_TILEID ) ;
x = ( tmp > > 3 ) & 0x0f ; /* bits 06:03 */
y = ( tmp > > 7 ) & 0x0f ; /* bits 10:07 */
z = ( tmp ) & 0x07 ; /* bits 02:00 */
pid = 12 * y + 2 * x + z ;
/* Add 1 to the processor ID to avoid *.*.*.0 IP addresses */
return pid ;
}
void * server_task ( void * e )
{
int i = 0 ;
char msg [ 7 ] [ 60 ] = { " Hello you0 i have muc fun thogh! " , " Hello you1 here is a little smily for you! " , " Hello you2 whaaaaaaaaaaaaaaaaaaaaaaaaats uuuuuuuuuuuuuuuuuuuuuuuuuuuuup! " , " Hello you3! see this? this is fun ufun funfunfunfunf " , " Hello you4! "
, " Hello you5! ogogogogoogoggoogogogogogog " , " Hello you6!AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAa " } ;
server_init ( 5555 , 2 ) ;
Sleep ( 500 ) ;
srv_sendBuffer ( 0 , " Hello you! " , sizeof ( " Hello you! " ) ) ;
Sleep ( 800 ) ;
while ( 1 )
{
srv_sendBuffer ( 0 , msg [ i ] , sizeof ( msg [ i ] ) ) ;
i = ( + + i ) % 7 ;
Sleep ( 100 ) ;
}
return NULL ;
}
void * client_task ( void * e )
{
client_init ( ) ;
Sleep ( 1000 ) ;
while (
cli_ConnectTo ( " 192.168.0.1 " , 5555 , 0 ) ) ;
Sleep ( 1000 ) ;
cli_sendBuffer ( " Hallo Welt " , sizeof ( " Hallo Welt " ) ) ;
Sleep ( 2000 ) ;
while ( 1 )
{
cli_sendBuffer ( netbuffer , sizeof ( netbuffer ) ) ;
Sleep ( 1000 ) ;
}
return NULL ;
}
2010-08-15 13:58:08 +00:00
int test_init ( void )
{
2011-06-21 12:31:01 +02:00
if ( " get_core_no())
create_kernel_task ( NULL , server_task , NULL ) ;
else
create_kernel_task ( NULL , client_task , NULL ) ;
// char* argv[] = {"/bin/tests", NULL};
2010-08-15 13:58:08 +00:00
2011-06-21 12:31:01 +02:00
// sem_init(&producing, 1);
// sem_init(&consuming, 0);
// mailbox_int32_init(&mbox);
2010-08-15 13:58:08 +00:00
2011-06-21 12:31:01 +02:00
// create_kernel_task(NULL, foo, "Hello from foo1\n");
2011-03-02 23:08:01 +01:00
//create_kernel_task(NULL, join_test, NULL);
2011-02-18 21:20:15 +01:00
//create_kernel_task(NULL, producer, NULL);
//create_kernel_task(NULL, consumer, NULL);
2011-04-24 07:27:27 -07:00
//create_kernel_task(NULL, ping, NULL);
2011-03-09 18:35:23 +01:00
//create_user_task(NULL, "/bin/hello", argv);
2011-06-21 12:31:01 +02:00
// create_user_task(NULL, "/bin/tests", argv);
2011-04-21 09:28:56 -07:00
//create_user_task(NULL, "/bin/jacobi", argv);
2011-05-28 23:35:46 +02:00
//create_user_task(NULL, "/bin/jacobi", argv);
2010-08-15 13:58:08 +00:00
2011-05-29 15:54:33 +02:00
# ifdef CONFIG_LWIP
// use ping to test LWIP
2011-06-21 12:31:01 +02:00
// ping_send_now();
2011-05-29 15:54:33 +02:00
# endif
2010-08-15 13:58:08 +00:00
return 0 ;
}