Support kernel semaphore.
This commit is contained in:
@@ -33,9 +33,9 @@ INC_DIR = -I$(KERNEL_ROOT)/services/shell/letter-shell \
|
||||
-I$(KERNEL_ROOT)/services/app
|
||||
|
||||
ifeq ($(BOARD), imx6q-sabrelite)
|
||||
all: init test_fault simple_client simple_server shell fs_server semaphore_server test_ipc_null test_thread test_irq_hdlr test_irq_block test_irq_send eth_driver epit_server readme.txt | bin
|
||||
all: init test_fault simple_client simple_server shell fs_server semaphore_server test_semaphore test_ipc_null test_thread test_irq_hdlr test_irq_block test_irq_send eth_driver epit_server readme.txt | bin
|
||||
else
|
||||
all: init test_fault simple_client simple_server shell fs_server readme.txt | bin
|
||||
all: init test_fault simple_client simple_server shell fs_server test_ipc_null test_thread test_semaphore readme.txt | bin
|
||||
endif
|
||||
../tools/mkfs/mkfs ./fs.img $^
|
||||
@mv $(filter-out readme.txt, $^) bin
|
||||
@@ -59,6 +59,10 @@ epit_server: timer.o epit.o ccm_pll.o usyscall.o arch_usyscall.o libserial.o pri
|
||||
@${objdump} -S $@ > $@.asm
|
||||
endif
|
||||
|
||||
test_semaphore: test_semaphore.o libserial.o printf.o usyscall.o arch_usyscall.o
|
||||
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
||||
@${objdump} -S $@ > $@.asm
|
||||
|
||||
test_ipc_null: test_ipc_null.o libserial.o printf.o usyscall.o arch_usyscall.o libipc.o session.o
|
||||
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
||||
@${objdump} -S $@ > $@.asm
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include "libserial.h"
|
||||
#include "usyscall.h"
|
||||
|
||||
#define BLOCK_SIZE 256
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
printf("Test memry error %s.\n", 0x50000000);
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
#include <stdint.h>
|
||||
|
||||
#include "libserial.h"
|
||||
#include "usyscall.h"
|
||||
|
||||
enum {
|
||||
NR_THREADS = 16,
|
||||
LOOP_TIMES = 0x1000000,
|
||||
};
|
||||
|
||||
static int sem_id = -1;
|
||||
static uint32_t sum = 0;
|
||||
static int nr_thds = NR_THREADS;
|
||||
|
||||
int do_calculation(int argc, char** argv)
|
||||
{
|
||||
for (uint32_t i = 0; i < LOOP_TIMES; i++) {
|
||||
sum++;
|
||||
}
|
||||
|
||||
printf("test semaphore thd signal.\n");
|
||||
semaphore_signal(sem_id);
|
||||
|
||||
char* params[] = { "do_cal", NULL };
|
||||
if (nr_thds != 0) {
|
||||
int tid = thread(do_calculation, "test_sem_thd", params);
|
||||
nr_thds--;
|
||||
}
|
||||
|
||||
exit(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
printf("Test Semaphore.\n");
|
||||
sem_id = semaphore_new(0);
|
||||
if (sem_id < 0) {
|
||||
printf("new a kernel sem failed.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
sum = 0;
|
||||
|
||||
nr_thds = NR_THREADS;
|
||||
char* params[] = { "do_cal", NULL };
|
||||
if (nr_thds != 0) {
|
||||
int tid = thread(do_calculation, "test_sem_thd", params);
|
||||
nr_thds--;
|
||||
}
|
||||
|
||||
for (int i = 0; i < NR_THREADS; i++) {
|
||||
semaphore_wait(sem_id);
|
||||
}
|
||||
|
||||
printf("test thread sum after %d signal: 0x%x\n", NR_THREADS, sum);
|
||||
|
||||
exit(0);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user