moved g_* yo begin
This commit is contained in:
2
Makefile
2
Makefile
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
.SECONDARY:
|
.SECONDARY:
|
||||||
|
|
||||||
CFLAGS+= -I. -O1 -DSTM32F4 -std=c99
|
CFLAGS+= -I. -Os -DSTM32F4 -std=c99
|
||||||
#CFLAGS+= -mthumb
|
#CFLAGS+= -mthumb
|
||||||
#CFLAGS+= -march=armv7e-m
|
#CFLAGS+= -march=armv7e-m
|
||||||
CFLAGS+= -mfloat-abi=hard
|
CFLAGS+= -mfloat-abi=hard
|
||||||
|
|||||||
14
main.c
14
main.c
@@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2022 Oleg Borodin <borodin@unix7.org>
|
* Copyright 2022 Oleg Borodin <borodin@unix7.org>
|
||||||
*/
|
*/
|
||||||
@@ -10,7 +11,6 @@
|
|||||||
#include <libopencm3/stm32/gpio.h>
|
#include <libopencm3/stm32/gpio.h>
|
||||||
#include <libopencm3/stm32/usart.h>
|
#include <libopencm3/stm32/usart.h>
|
||||||
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
@@ -21,9 +21,12 @@
|
|||||||
#include "atomic.h"
|
#include "atomic.h"
|
||||||
#include "semaphore.h"
|
#include "semaphore.h"
|
||||||
|
|
||||||
|
static int g_uptime;
|
||||||
|
static sem_t g_sem;
|
||||||
|
static scheduler_t g_scheduler;
|
||||||
|
|
||||||
void delay(uint32_t n) {
|
void delay(uint32_t n) {
|
||||||
for (volatile int i = 0; i < n * 800; i++)
|
for (int i = 0; i < n * 800; i++)
|
||||||
__asm__("nop");
|
__asm__("nop");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,9 +62,6 @@ static void systick_setup(void) {
|
|||||||
systick_counter_enable();
|
systick_counter_enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
int g_uptime;
|
|
||||||
sem_t g_sem;
|
|
||||||
|
|
||||||
void task1(void) {
|
void task1(void) {
|
||||||
while (true) {
|
while (true) {
|
||||||
sem_wait(&g_sem);
|
sem_wait(&g_sem);
|
||||||
@@ -91,6 +91,7 @@ void task3(void) {
|
|||||||
|
|
||||||
void task4(void) {
|
void task4(void) {
|
||||||
static volatile int32_t t4;
|
static volatile int32_t t4;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
atomic_inc32(&t4, (int32_t)1);
|
atomic_inc32(&t4, (int32_t)1);
|
||||||
sem_wait(&g_sem);
|
sem_wait(&g_sem);
|
||||||
@@ -105,14 +106,13 @@ void sys_tick_handler(void) {
|
|||||||
scheduler_yield();
|
scheduler_yield();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
g_uptime = 0;
|
g_uptime = 0;
|
||||||
sem_init(&g_sem, 1);
|
sem_init(&g_sem, 1);
|
||||||
static scheduler_t g_scheduler;
|
|
||||||
|
|
||||||
clock_setup();
|
clock_setup();
|
||||||
usart_setup();
|
usart_setup();
|
||||||
|
|
||||||
scheduler_init(&g_scheduler);
|
scheduler_init(&g_scheduler);
|
||||||
scheduler_task(&g_scheduler, 0, task1);
|
scheduler_task(&g_scheduler, 0, task1);
|
||||||
scheduler_task(&g_scheduler, 1, task2);
|
scheduler_task(&g_scheduler, 1, task2);
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ static void task_exit_func(void) {
|
|||||||
#define STACK_FILL 0xA5
|
#define STACK_FILL 0xA5
|
||||||
|
|
||||||
void scheduler_init(scheduler_t *scheduler) {
|
void scheduler_init(scheduler_t *scheduler) {
|
||||||
|
int i;
|
||||||
for (int i = 0; i < SCHEDULER_NUM_TASKS; i++) {
|
for (i = 0; i < SCHEDULER_NUM_TASKS; i++) {
|
||||||
task_t *task = &(scheduler->tasks[i]);
|
task_t *task = &(scheduler->tasks[i]);
|
||||||
task->stack = NULL;
|
task->stack = NULL;
|
||||||
task->stack_size = 0;
|
task->stack_size = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user