mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #567 from mehlis/tests-astyle
tests: use astyle to adopt current code style guide
This commit is contained in:
commit
ef54fa4016
@ -17,7 +17,7 @@
|
||||
int main(void)
|
||||
{
|
||||
struct bloom_t *bloom = bloom_new(1 << 7, 6, fnv_hash, sax_hash, sdbm_hash,
|
||||
djb2_hash, kr_hash, dek_hash, rotating_hash, one_at_a_time_hash);
|
||||
djb2_hash, kr_hash, dek_hash, rotating_hash, one_at_a_time_hash);
|
||||
|
||||
printf("Testing Bloom filter.\n\n");
|
||||
printf("m: %zd\nk: %zd\n\n", bloom->m, bloom->k);
|
||||
@ -33,7 +33,8 @@ int main(void)
|
||||
for (int i = 0; i < lenA; i++) {
|
||||
if (bloom_check(bloom, (const uint8_t *) A[i], strlen(A[i]))) {
|
||||
in++;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
not_in++;
|
||||
}
|
||||
}
|
||||
|
@ -39,30 +39,33 @@ int main(void)
|
||||
hwtimer_init();
|
||||
|
||||
struct bloom_t *bloom = bloom_new(1 << 12, 8, fnv_hash, sax_hash, sdbm_hash,
|
||||
djb2_hash, kr_hash, dek_hash, rotating_hash, one_at_a_time_hash);
|
||||
djb2_hash, kr_hash, dek_hash, rotating_hash, one_at_a_time_hash);
|
||||
|
||||
printf("Testing Bloom filter.\n\n");
|
||||
printf("m: %" PRIu32 " k: %" PRIu32 "\n\n", (uint32_t) bloom->m,
|
||||
(uint32_t) bloom->k);
|
||||
(uint32_t) bloom->k);
|
||||
|
||||
genrand_init(myseed);
|
||||
|
||||
unsigned long t1 = hwtimer_now();
|
||||
|
||||
for (int i = 0; i < lenB; i++) {
|
||||
buf_fill(buf, BUF_SIZE);
|
||||
buf[0] = MAGIC_B;
|
||||
bloom_add(bloom,
|
||||
(uint8_t *) buf,
|
||||
BUF_SIZE * sizeof(uint32_t)/ sizeof(uint8_t));
|
||||
BUF_SIZE * sizeof(uint32_t) / sizeof(uint8_t));
|
||||
}
|
||||
|
||||
unsigned long t2 = hwtimer_now();
|
||||
printf("adding %d elements took %" PRIu32 "ms\n", lenB,
|
||||
(uint32_t) HWTIMER_TICKS_TO_US(t2-t1) / 1000);
|
||||
(uint32_t) HWTIMER_TICKS_TO_US(t2 - t1) / 1000);
|
||||
|
||||
int in = 0;
|
||||
int not_in = 0;
|
||||
|
||||
unsigned long t3 = hwtimer_now();
|
||||
|
||||
for (int i = 0; i < lenA; i++) {
|
||||
buf_fill(buf, BUF_SIZE);
|
||||
buf[0] = MAGIC_A;
|
||||
@ -71,13 +74,15 @@ int main(void)
|
||||
(uint8_t *) buf,
|
||||
BUF_SIZE * sizeof(uint32_t) / sizeof(uint8_t))) {
|
||||
in++;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
not_in++;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned long t4 = hwtimer_now();
|
||||
printf("checking %d elements took %" PRIu32 "ms\n", lenA,
|
||||
(uint32_t) HWTIMER_TICKS_TO_US(t4-t3) / 1000);
|
||||
(uint32_t) HWTIMER_TICKS_TO_US(t4 - t3) / 1000);
|
||||
|
||||
printf("\n");
|
||||
printf("%d elements probably in the filter.\n", in);
|
||||
|
@ -4,14 +4,17 @@
|
||||
|
||||
int main(void)
|
||||
{
|
||||
double x = 1234567./1024., z;
|
||||
while (1) {
|
||||
x += 0.1;
|
||||
z = x - floor(x);
|
||||
if (z >= 1) {
|
||||
putchar('+');
|
||||
} else {
|
||||
putchar('-');
|
||||
}
|
||||
double x = 1234567. / 1024., z;
|
||||
|
||||
while (1) {
|
||||
x += 0.1;
|
||||
z = x - floor(x);
|
||||
|
||||
if (z >= 1) {
|
||||
putchar('+');
|
||||
}
|
||||
else {
|
||||
putchar('-');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
#include "hwtimer.h"
|
||||
|
||||
void callback(void* ptr)
|
||||
void callback(void *ptr)
|
||||
{
|
||||
puts((char*) ptr);
|
||||
puts((char *) ptr);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
@ -20,21 +20,21 @@ int main(void)
|
||||
#define DELTA_DELAY (1000UL * 1000UL)
|
||||
#define MSGLEN 12 // == strlen("callback %2i")
|
||||
char msg[MSGLEN * ARCH_MAXTIMERS]; // == [callback 1\0callback 2\0...]
|
||||
unsigned long delay = BASE_DELAY + ((ARCH_MAXTIMERS-1) * DELTA_DELAY);
|
||||
unsigned long delay = BASE_DELAY + ((ARCH_MAXTIMERS - 1) * DELTA_DELAY);
|
||||
|
||||
/* make the first timer first to fire so timers do not run out linearly */
|
||||
char *msgn = msg;
|
||||
snprintf(msgn, MSGLEN, "callback %2x", 1);
|
||||
hwtimer_set(HWTIMER_TICKS(BASE_DELAY), callback, (void*) msgn);
|
||||
hwtimer_set(HWTIMER_TICKS(BASE_DELAY), callback, (void *) msgn);
|
||||
printf("set %s\n", msgn);
|
||||
|
||||
/* set up to ARCH_MAXTIMERS-1 because hwtimer_wait below also
|
||||
* needs a timer */
|
||||
for (int i = 1; i < (ARCH_MAXTIMERS - 1); i++) {
|
||||
msgn = msg + (i*MSGLEN);
|
||||
msgn = msg + (i * MSGLEN);
|
||||
delay -= DELTA_DELAY;
|
||||
snprintf(msgn, MSGLEN, "callback %2x", i+1);
|
||||
hwtimer_set(HWTIMER_TICKS(delay), callback, (void*) msgn);
|
||||
snprintf(msgn, MSGLEN, "callback %2x", i + 1);
|
||||
hwtimer_set(HWTIMER_TICKS(delay), callback, (void *) msgn);
|
||||
printf("set %s\n", msgn);
|
||||
}
|
||||
|
||||
|
@ -18,8 +18,9 @@
|
||||
int main(void)
|
||||
{
|
||||
printf("when the race condition is hit, hwtimer will wait a very very long time...\n");
|
||||
while(1) {
|
||||
for (unsigned long i = 256; i; i = i>>1) {
|
||||
|
||||
while (1) {
|
||||
for (unsigned long i = 256; i; i = i >> 1) {
|
||||
printf("wait %lu\n", i);
|
||||
hwtimer_wait(i);
|
||||
}
|
||||
|
@ -18,9 +18,11 @@ void busy_thread(void)
|
||||
printf("busy_thread starting\n");
|
||||
|
||||
i = 0;
|
||||
|
||||
while (busy) {
|
||||
k = j = ++i;
|
||||
}
|
||||
|
||||
printf("i: %i\n", i);
|
||||
printf("j: %i\n", j);
|
||||
printf("k: %i\n", k);
|
||||
@ -36,8 +38,8 @@ int main(void)
|
||||
busy = 1;
|
||||
k = 23;
|
||||
thread_create(busy_stack, KERNEL_CONF_STACKSIZE_PRINTF,
|
||||
PRIORITY_MAIN+1, CREATE_WOUT_YIELD, busy_thread,
|
||||
"busy_thread");
|
||||
PRIORITY_MAIN + 1, CREATE_WOUT_YIELD, busy_thread,
|
||||
"busy_thread");
|
||||
printf("busy_thread created\n");
|
||||
|
||||
printf("hwtimer_wait()\n");
|
||||
|
@ -32,7 +32,8 @@ uint8_t receiving = 1;
|
||||
unsigned int last_seq = 0, missed_cnt = 0;
|
||||
int first = -1;
|
||||
|
||||
void radio(void) {
|
||||
void radio(void)
|
||||
{
|
||||
msg_t m;
|
||||
radio_packet_t *p;
|
||||
unsigned int tmp = 0, cur_seq = 0;
|
||||
@ -40,27 +41,34 @@ void radio(void) {
|
||||
msg_init_queue(msg_q, RCV_BUFFER_SIZE);
|
||||
|
||||
puts("Start receiving");
|
||||
|
||||
while (receiving) {
|
||||
msg_receive(&m);
|
||||
|
||||
if (m.type == PKT_PENDING) {
|
||||
p = (radio_packet_t*) m.content.ptr;
|
||||
p = (radio_packet_t *) m.content.ptr;
|
||||
|
||||
if ((p->src == SENDER_ADDR) && (p->length == PACKET_SIZE)) {
|
||||
puts("received");
|
||||
cur_seq = (p->data[0] << 8) + p->data[1];
|
||||
|
||||
if (first < 0) {
|
||||
first = cur_seq;
|
||||
}
|
||||
else {
|
||||
tmp = cur_seq - last_seq;
|
||||
|
||||
if (last_seq && (tmp > 1)) {
|
||||
missed_cnt += (tmp - 1);
|
||||
}
|
||||
}
|
||||
|
||||
last_seq = cur_seq;
|
||||
}
|
||||
else {
|
||||
printf("sender was %i\n", p->src);
|
||||
}
|
||||
|
||||
p->processing--;
|
||||
}
|
||||
else if (m.type == ENOBUFFER) {
|
||||
@ -72,14 +80,15 @@ void radio(void) {
|
||||
}
|
||||
}
|
||||
|
||||
void sender(void) {
|
||||
unsigned int i=0;
|
||||
void sender(void)
|
||||
{
|
||||
unsigned int i = 0;
|
||||
msg_t mesg;
|
||||
transceiver_command_t tcmd;
|
||||
radio_packet_t p;
|
||||
|
||||
mesg.type = SND_PKT;
|
||||
mesg.content.ptr = (char*) &tcmd;
|
||||
mesg.content.ptr = (char *) &tcmd;
|
||||
|
||||
tcmd.transceivers = TRANSCEIVER_NATIVE;
|
||||
tcmd.data = &p;
|
||||
@ -88,6 +97,7 @@ void sender(void) {
|
||||
p.dst = 0;
|
||||
|
||||
puts("Start sending packets");
|
||||
|
||||
while (1) {
|
||||
/* filling uint8_t buffer with uint16_t sequence number */
|
||||
snd_buffer[0] = (i & 0xFF00) >> 8;
|
||||
@ -116,7 +126,7 @@ int main(void)
|
||||
|
||||
#ifndef SENDER
|
||||
printf("\n\tmain(): starting radio thread\n");
|
||||
radio_pid = thread_create(radio_stack_buffer, RADIO_STACK_SIZE, PRIORITY_MAIN-2, CREATE_STACKTEST, radio, "radio");
|
||||
radio_pid = thread_create(radio_stack_buffer, RADIO_STACK_SIZE, PRIORITY_MAIN - 2, CREATE_STACKTEST, radio, "radio");
|
||||
transceiver_register(TRANSCEIVER_NATIVE, radio_pid);
|
||||
#endif
|
||||
|
||||
|
@ -22,14 +22,16 @@
|
||||
|
||||
#define PORT (1234)
|
||||
|
||||
void init_local_address(uint16_t r_addr) {
|
||||
void init_local_address(uint16_t r_addr)
|
||||
{
|
||||
ipv6_addr_t std_addr;
|
||||
ipv6_addr_init(&std_addr, 0xabcd, 0xef12, 0, 0, 0x1034, 0x00ff, 0xfe00,
|
||||
ipv6_addr_init(&std_addr, 0xabcd, 0xef12, 0, 0, 0x1034, 0x00ff, 0xfe00,
|
||||
r_addr);
|
||||
sixlowpan_lowpan_adhoc_init(TRANSCEIVER, &std_addr, r_addr);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
int main(void)
|
||||
{
|
||||
int sockfd, res;
|
||||
struct sockaddr_in6 my_addr, their_addr = {
|
||||
.sin6_family = AF_INET6,
|
||||
@ -40,11 +42,19 @@ int main(void) {
|
||||
#endif
|
||||
.sin6_flowinfo = 0,
|
||||
#if R_ADDR == 1
|
||||
.sin6_addr = {{{0xab, 0xcd, 0xef, 0x12, 0x00, 0x00, 0x00, 0x00,
|
||||
0x10, 0x34, 0x00, 0xff, 0xfe, 0x00, 0x00, 0x02}}},
|
||||
.sin6_addr = {{{
|
||||
0xab, 0xcd, 0xef, 0x12, 0x00, 0x00, 0x00, 0x00,
|
||||
0x10, 0x34, 0x00, 0xff, 0xfe, 0x00, 0x00, 0x02
|
||||
}
|
||||
}
|
||||
},
|
||||
#else
|
||||
.sin6_addr = {{{0xab, 0xcd, 0xef, 0x12, 0x00, 0x00, 0x00, 0x00,
|
||||
0x10, 0x34, 0x00, 0xff, 0xfe, 0x00, 0x00, 0x01}}},
|
||||
.sin6_addr = {{{
|
||||
0xab, 0xcd, 0xef, 0x12, 0x00, 0x00, 0x00, 0x00,
|
||||
0x10, 0x34, 0x00, 0xff, 0xfe, 0x00, 0x00, 0x01
|
||||
}
|
||||
}
|
||||
},
|
||||
#endif
|
||||
.sin6_scope_id = 0,
|
||||
};
|
||||
@ -53,32 +63,36 @@ int main(void) {
|
||||
init_local_address(R_ADDR);
|
||||
|
||||
memcpy(buffer, "Hello, World!", 14);
|
||||
memcpy(&my_addr, &in6addr_any, sizeof (my_addr));
|
||||
memcpy(&my_addr, &in6addr_any, sizeof(my_addr));
|
||||
|
||||
my_addr.sin6_port = PORT;
|
||||
|
||||
sockfd = socket(AF_INET6, SOCK_DGRAM, 0);
|
||||
res = bind(sockfd, (struct sockaddr *)&my_addr, sizeof (my_addr));
|
||||
res = bind(sockfd, (struct sockaddr *)&my_addr, sizeof(my_addr));
|
||||
|
||||
if (res < 0) {
|
||||
perror("Socket could not be bind");
|
||||
return 1;
|
||||
}
|
||||
|
||||
#if R_ADDR == 1
|
||||
res = sendto(sockfd, buffer, strlen(buffer), 0,
|
||||
(struct sockaddr *)&their_addr,
|
||||
(socklen_t) sizeof (their_addr));
|
||||
res = sendto(sockfd, buffer, strlen(buffer), 0,
|
||||
(struct sockaddr *)&their_addr,
|
||||
(socklen_t) sizeof(their_addr));
|
||||
#else
|
||||
socklen_t their_len;
|
||||
res = recvfrom(sockfd, buffer, strlen(buffer), 0,
|
||||
(struct sockaddr *)&their_addr,
|
||||
&their_len);
|
||||
res = recvfrom(sockfd, buffer, strlen(buffer), 0,
|
||||
(struct sockaddr *)&their_addr,
|
||||
&their_len);
|
||||
|
||||
if (their_addr.sin6_addr.uint8[15] != 1) {
|
||||
fprintf(stderr, "Wrong sender address: %d\n", their_addr.sin6_addr.uint8[11]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Port: %d\n", their_addr.sin6_port);
|
||||
#endif
|
||||
|
||||
if (res < 0) {
|
||||
perror("Message error");
|
||||
return 1;
|
||||
|
@ -21,15 +21,19 @@ sem_t s;
|
||||
static void test1_second_thread(void)
|
||||
{
|
||||
puts("second: sem_trywait");
|
||||
|
||||
if (sem_trywait(&s) == 0) {
|
||||
puts("second: sem_trywait failed");
|
||||
}
|
||||
|
||||
puts("second: sem_trywait done with == 0");
|
||||
|
||||
puts("second: wait for post");
|
||||
|
||||
if (sem_wait(&s) != 1) {
|
||||
puts("second: sem_wait failed");
|
||||
}
|
||||
|
||||
puts("second: sem was posted");
|
||||
|
||||
puts("second: end");
|
||||
@ -38,24 +42,29 @@ static void test1_second_thread(void)
|
||||
static void test1(void)
|
||||
{
|
||||
puts("first: sem_init");
|
||||
|
||||
if (sem_init(&s, 0, 0) != 0) {
|
||||
puts("first: sem_init failed");
|
||||
}
|
||||
|
||||
puts("first: thread create");
|
||||
int pid = thread_create(test1_thread_stack, KERNEL_CONF_STACKSIZE_PRINTF,
|
||||
PRIORITY_MAIN - 1, CREATE_STACKTEST | CREATE_WOUT_YIELD,
|
||||
test1_second_thread, "second");
|
||||
PRIORITY_MAIN - 1, CREATE_STACKTEST | CREATE_WOUT_YIELD,
|
||||
test1_second_thread, "second");
|
||||
|
||||
if (pid < 0) {
|
||||
puts("first: thread create failed");
|
||||
}
|
||||
|
||||
puts("first: thread created");
|
||||
|
||||
puts("first: sem_getvalue");
|
||||
int val;
|
||||
|
||||
if (sem_getvalue(&s, &val) != 0 || val != 0) {
|
||||
puts("first: sem_getvalue failed");
|
||||
}
|
||||
|
||||
puts("first: sem_getvalue != 0");
|
||||
|
||||
puts("first: do yield");
|
||||
@ -65,20 +74,25 @@ static void test1(void)
|
||||
/*****************************************************************************/
|
||||
|
||||
puts("first: sem_trywait");
|
||||
|
||||
if (sem_trywait(&s) != -1) {
|
||||
puts("first: sem_trywait failed");
|
||||
}
|
||||
|
||||
puts("first: sem_trywait done");
|
||||
|
||||
puts("first: sem_post");
|
||||
|
||||
if (sem_post(&s) != 1) {
|
||||
puts("first: sem_post failed");
|
||||
}
|
||||
|
||||
puts("first: sem_post done");
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
puts("first: sem_destroy");
|
||||
|
||||
if (sem_destroy(&s) != 0) {
|
||||
puts("first: sem_destroy failed");
|
||||
}
|
||||
@ -96,6 +110,7 @@ char names[SEMAPHORE_TEST_THREADS][16];
|
||||
void test2(void)
|
||||
{
|
||||
puts("first: sem_init");
|
||||
|
||||
if (sem_init(&s, 0, 0) != 0) {
|
||||
puts("first: sem_init failed");
|
||||
}
|
||||
@ -106,15 +121,18 @@ void test2(void)
|
||||
snprintf(names[i], sizeof(names[i]), "priority %d", priority);
|
||||
printf("first: thread create: %d\n", priority);
|
||||
int pid = thread_create(test2_thread_stack[i],
|
||||
KERNEL_CONF_STACKSIZE_PRINTF, priority, CREATE_STACKTEST,
|
||||
priority_sema_thread, names[i]);
|
||||
KERNEL_CONF_STACKSIZE_PRINTF, priority, CREATE_STACKTEST,
|
||||
priority_sema_thread, names[i]);
|
||||
|
||||
if (pid < 0) {
|
||||
puts("first: thread create failed");
|
||||
}
|
||||
|
||||
printf("first: thread created: %s (%d/%d)\n", names[i], i + 1, SEMAPHORE_TEST_THREADS);
|
||||
}
|
||||
|
||||
puts("------------------------------------------");
|
||||
|
||||
for (int i = 0; i < SEMAPHORE_TEST_THREADS; i++) {
|
||||
printf("post no. %d\n", i);
|
||||
sem_post(&s);
|
||||
|
@ -24,30 +24,32 @@ void sha256_calc(const char *str, const char *expected)
|
||||
printf("Input: %s\n"
|
||||
"Expected: %s\n"
|
||||
"Calculated: ", str, expected);
|
||||
|
||||
for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) {
|
||||
printf("%02x", hash[i]);
|
||||
}
|
||||
|
||||
printf("\n\n");
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
sha256_calc("1234567890_1",
|
||||
"3eda9ffe5537a588f54d0b2a453e5fa932986d0bc0f9556924f5c2379b2c91b0");
|
||||
"3eda9ffe5537a588f54d0b2a453e5fa932986d0bc0f9556924f5c2379b2c91b0");
|
||||
sha256_calc("1234567890_2",
|
||||
"a144d0b4d285260ebbbab6840baceaa09eab3e157443c9458de764b7262c8ace");
|
||||
"a144d0b4d285260ebbbab6840baceaa09eab3e157443c9458de764b7262c8ace");
|
||||
sha256_calc("1234567890_3",
|
||||
"9f839169d293276d1b799707d2171ac1fd5b78d0f3bc7693dbed831524dd2d77");
|
||||
"9f839169d293276d1b799707d2171ac1fd5b78d0f3bc7693dbed831524dd2d77");
|
||||
sha256_calc("1234567890_4",
|
||||
"6c5fe2a8e3de58a5e5ac061031a8e802ae1fb9e7197862ec1aedf236f0e23475");
|
||||
"6c5fe2a8e3de58a5e5ac061031a8e802ae1fb9e7197862ec1aedf236f0e23475");
|
||||
sha256_calc("0123456789abcde-0123456789abcde-0123456789abcde-0123456789abcde-",
|
||||
"945ab9d52b069923680c2c067fa6092cbbd9234cf7a38628f3033b2d54d3d3bf");
|
||||
"945ab9d52b069923680c2c067fa6092cbbd9234cf7a38628f3033b2d54d3d3bf");
|
||||
sha256_calc("Franz jagt im komplett verwahrlosten Taxi quer durch Bayern",
|
||||
"d32b568cd1b96d459e7291ebf4b25d007f275c9f13149beeb782fac0716613f8");
|
||||
"d32b568cd1b96d459e7291ebf4b25d007f275c9f13149beeb782fac0716613f8");
|
||||
sha256_calc("Frank jagt im komplett verwahrlosten Taxi quer durch Bayern",
|
||||
"78206a866dbb2bf017d8e34274aed01a8ce405b69d45db30bafa00f5eeed7d5e");
|
||||
"78206a866dbb2bf017d8e34274aed01a8ce405b69d45db30bafa00f5eeed7d5e");
|
||||
sha256_calc("",
|
||||
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
|
||||
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ int main(void)
|
||||
|
||||
/* define own shell commands */
|
||||
shell_t shell;
|
||||
shell_init(&shell, shell_commands, SHELL_BUFSIZE, shell_readc,
|
||||
shell_init(&shell, shell_commands, SHELL_BUFSIZE, shell_readc,
|
||||
shell_putchar);
|
||||
shell_run(&shell);
|
||||
|
||||
|
@ -7,12 +7,13 @@
|
||||
|
||||
char t2_stack[STACK_SIZE];
|
||||
|
||||
void second_thread(void) {
|
||||
void second_thread(void)
|
||||
{
|
||||
puts("second thread\n");
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
(void) thread_create(t2_stack, STACK_SIZE, PRIORITY_MAIN-1, CREATE_WOUT_YIELD | CREATE_STACKTEST, second_thread, "nr2");
|
||||
(void) thread_create(t2_stack, STACK_SIZE, PRIORITY_MAIN - 1, CREATE_WOUT_YIELD | CREATE_STACKTEST, second_thread, "nr2");
|
||||
puts("first thread\n");
|
||||
}
|
||||
|
@ -7,26 +7,29 @@
|
||||
char second_thread_stack[KERNEL_CONF_STACKSIZE_MAIN];
|
||||
char third_thread_stack[KERNEL_CONF_STACKSIZE_MAIN];
|
||||
|
||||
void fourth_thread(void) {
|
||||
void fourth_thread(void)
|
||||
{
|
||||
puts("4th: starting");
|
||||
puts("4th: exiting");
|
||||
}
|
||||
|
||||
void third_thread(void) {
|
||||
void third_thread(void)
|
||||
{
|
||||
puts("3rd: starting");
|
||||
puts("3rd: exiting");
|
||||
}
|
||||
|
||||
void second_thread(void) {
|
||||
void second_thread(void)
|
||||
{
|
||||
puts("2nd: starting");
|
||||
|
||||
if ((thread_create(
|
||||
third_thread_stack,
|
||||
sizeof(third_thread_stack),
|
||||
PRIORITY_MAIN-2,
|
||||
CREATE_STACKTEST,
|
||||
third_thread,
|
||||
"nr3")
|
||||
third_thread_stack,
|
||||
sizeof(third_thread_stack),
|
||||
PRIORITY_MAIN - 2,
|
||||
CREATE_STACKTEST,
|
||||
third_thread,
|
||||
"nr3")
|
||||
) == -1) {
|
||||
puts("2nd: Error creating 3rd thread.");
|
||||
}
|
||||
@ -34,12 +37,12 @@ void second_thread(void) {
|
||||
/* thread should have returned already */
|
||||
|
||||
if ((thread_create(
|
||||
third_thread_stack,
|
||||
sizeof(third_thread_stack),
|
||||
PRIORITY_MAIN-1,
|
||||
CREATE_WOUT_YIELD | CREATE_STACKTEST,
|
||||
fourth_thread,
|
||||
"nr4")
|
||||
third_thread_stack,
|
||||
sizeof(third_thread_stack),
|
||||
PRIORITY_MAIN - 1,
|
||||
CREATE_WOUT_YIELD | CREATE_STACKTEST,
|
||||
fourth_thread,
|
||||
"nr4")
|
||||
) == -1) {
|
||||
puts("2nd: Error creating 4rd thread.");
|
||||
}
|
||||
@ -50,15 +53,17 @@ void second_thread(void) {
|
||||
int main(void)
|
||||
{
|
||||
puts("main: starting");
|
||||
|
||||
if ((thread_create(
|
||||
second_thread_stack,
|
||||
sizeof(second_thread_stack),
|
||||
PRIORITY_MAIN-1,
|
||||
CREATE_WOUT_YIELD | CREATE_STACKTEST,
|
||||
second_thread,
|
||||
"nr2")
|
||||
second_thread_stack,
|
||||
sizeof(second_thread_stack),
|
||||
PRIORITY_MAIN - 1,
|
||||
CREATE_WOUT_YIELD | CREATE_STACKTEST,
|
||||
second_thread,
|
||||
"nr2")
|
||||
) == -1) {
|
||||
puts("main: Error creating 3rd thread.");
|
||||
}
|
||||
|
||||
puts("main: exiting");
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ char timer_stack_local[KERNEL_CONF_STACKSIZE_PRINTF];
|
||||
struct timer_msg {
|
||||
vtimer_t timer;
|
||||
timex_t interval;
|
||||
char* msg;
|
||||
char *msg;
|
||||
};
|
||||
|
||||
timex_t now;
|
||||
@ -32,14 +32,15 @@ void timer_thread(void)
|
||||
while (1) {
|
||||
msg_t m;
|
||||
msg_receive(&m);
|
||||
struct timer_msg* tmsg = (struct timer_msg*) m.content.ptr;
|
||||
struct timer_msg *tmsg = (struct timer_msg *) m.content.ptr;
|
||||
vtimer_now(&now);
|
||||
printf("now=%" PRIu32 ":%" PRIu32 " -> every %u.%us: %s\n",
|
||||
now.seconds,
|
||||
now.microseconds,
|
||||
tmsg->interval.seconds,
|
||||
tmsg->interval.microseconds,
|
||||
tmsg->msg);
|
||||
now.seconds,
|
||||
now.microseconds,
|
||||
tmsg->interval.seconds,
|
||||
tmsg->interval.microseconds,
|
||||
tmsg->msg);
|
||||
|
||||
if (vtimer_set_msg(&tmsg->timer, tmsg->interval, thread_getpid(), tmsg) != 0) {
|
||||
puts("something went wrong");
|
||||
}
|
||||
@ -63,33 +64,35 @@ void timer_thread_local(void)
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
int main(void)
|
||||
{
|
||||
msg_t m;
|
||||
int pid = thread_create(
|
||||
timer_stack,
|
||||
sizeof timer_stack,
|
||||
PRIORITY_MAIN-1,
|
||||
CREATE_STACKTEST,
|
||||
timer_thread,
|
||||
"timer");
|
||||
timer_stack,
|
||||
sizeof timer_stack,
|
||||
PRIORITY_MAIN - 1,
|
||||
CREATE_STACKTEST,
|
||||
timer_thread,
|
||||
"timer");
|
||||
|
||||
puts("sending 1st msg");
|
||||
m.content.ptr = (char*) &msg_a;
|
||||
m.content.ptr = (char *) &msg_a;
|
||||
msg_send(&m, pid, false);
|
||||
|
||||
puts("sending 2nd msg");
|
||||
m.content.ptr = (char*) &msg_b;
|
||||
m.content.ptr = (char *) &msg_b;
|
||||
msg_send(&m, pid, false);
|
||||
|
||||
int pid2 = thread_create(
|
||||
timer_stack_local,
|
||||
sizeof timer_stack_local,
|
||||
PRIORITY_MAIN-1,
|
||||
CREATE_STACKTEST,
|
||||
timer_thread_local,
|
||||
"timer local");
|
||||
timer_stack_local,
|
||||
sizeof timer_stack_local,
|
||||
PRIORITY_MAIN - 1,
|
||||
CREATE_STACKTEST,
|
||||
timer_thread_local,
|
||||
"timer local");
|
||||
|
||||
timex_t sleep = timex_set(1, 0);
|
||||
|
||||
while (1) {
|
||||
vtimer_sleep(sleep);
|
||||
msg_send(&m, pid2, 0);
|
||||
|
Loading…
Reference in New Issue
Block a user