Include sleep into library

This commit is contained in:
Matte23
2024-11-03 15:01:54 +01:00
parent 6d0a60881c
commit ba22538626
5 changed files with 19 additions and 7 deletions

View File

@@ -8,7 +8,7 @@ LDFLAGS = -T linker.ld
CFLAGS = $(CPU) $(THUMB) -I libc/ -I ./
QEMU = qemu-system-arm
BOARD = netduino2
BOARD = netduinoplus2
# Output file
TARGET = main.elf

View File

@@ -1,6 +1,15 @@
#include "library.h"
#include "os/driver/usart.h"
#include "os/delay.h"
void puts(const char *s) {
usart_tx_write_string(s);
}
void usleep(unsigned int usec) {
delay_ms(usec);
}
void sleep(unsigned int sec) {
usleep(sec*1000);
}

View File

@@ -1 +1,3 @@
void puts(const char *s);
void usleep(unsigned int usec);
void sleep(unsigned int sec);

View File

@@ -1,4 +1,4 @@
#define CLOCK_FREQUENCY 120000
#define CLOCK_FREQUENCY 168000ULL
unsigned int ms_to_ticks(unsigned int ms) {
return ms * (CLOCK_FREQUENCY/3);
@@ -6,10 +6,9 @@ unsigned int ms_to_ticks(unsigned int ms) {
void delay_routine(unsigned int delay_counter) {
asm("mov r1, %[input]\n"
"loop_2:\n"
"delay_loop:\n"
"subs r1, #1\n"
"cmp r1, #0\n"
"bne loop_2\n"
"bne delay_loop\n"
: [input] "=r" (delay_counter));
}

View File

@@ -1,11 +1,13 @@
#include "library.h"
int task2(void) {
puts("Hello World from task 1\n");
puts("Hello World from task 2\n");
sleep(4);
return 0;
}
int task1(void) {
puts("Hello World from task 2\n");
puts("Hello World from task 1\n");
sleep(2);
return 0;
}