Update code due to new rules
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017-2019 by Löwenware Ltd
|
||||
* Please, refer LICENSE file for legal information
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file arch.h
|
||||
* @author Ilja Kartašov <ik@lowenware.com>
|
||||
* @brief
|
||||
*
|
||||
* @see https://lowenware.com/
|
||||
*/
|
||||
|
||||
#ifndef ARCH_H_F63C116D_51C9_4E25_9B1F_126833937268
|
||||
#define ARCH_H_F63C116D_51C9_4E25_9B1F_126833937268
|
||||
|
||||
#include <aarch64/aarch64.h>
|
||||
|
||||
#define k_arch_init(...) aarch64_init(__VA_ARGS__)
|
||||
|
||||
#endif /* !ARCH_H */
|
||||
@@ -0,0 +1,82 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017-2019 by Löwenware Ltd
|
||||
* Please, refer LICENSE file for legal information
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file irq.c
|
||||
* @author Ilja Kartašov <ik@lowenware.com>
|
||||
* @brief
|
||||
*
|
||||
* @see https://lowenware.com/
|
||||
*/
|
||||
|
||||
#include <aarch64/bcm2837.h>
|
||||
#include "timer.h"
|
||||
#include "log.h"
|
||||
#include "task.h"
|
||||
#include "irq.h"
|
||||
|
||||
static const char *m_types[] = {
|
||||
"EL1t_SYNC",
|
||||
"EL1t_IRQ",
|
||||
"EL1t_FIQ",
|
||||
"EL1t_ERROR",
|
||||
"EL1h_SYNC",
|
||||
"EL1h_IRQ",
|
||||
"EL1h_FIQ",
|
||||
"EL1h_ERROR",
|
||||
"EL0_64_SYNC",
|
||||
"EL0_64_IRQ",
|
||||
"EL0_64_FIQ",
|
||||
"EL0_64_ERROR",
|
||||
"EL0_32_SYNC",
|
||||
"EL0_32_IRQ",
|
||||
"EL0_32_FIQ",
|
||||
"EL0_32_ERROR"
|
||||
};
|
||||
|
||||
|
||||
static unsigned long
|
||||
IRQ_onTimerInterrupt(void)
|
||||
{
|
||||
Timer_incFromISR();
|
||||
return Task_scheduleFromISR();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
IRQ_init()
|
||||
{
|
||||
AArch64_setReg32(ENABLE_IRQS_1, SYSTEM_TIMER_IRQ_1);
|
||||
}
|
||||
|
||||
unsigned long
|
||||
IRQ_onInterrupt(void)
|
||||
{
|
||||
unsigned int irq = AArch64_getReg32(IRQ_PENDING_1);
|
||||
|
||||
switch(irq) {
|
||||
case SYSTEM_TIMER_IRQ_1:
|
||||
return IRQ_onTimerInterrupt();
|
||||
|
||||
default:
|
||||
Log_putS("Unhandled irq: ");
|
||||
Log_putU(irq, 16);
|
||||
Log_putS("\n");
|
||||
}
|
||||
return 0; /* do not change stack pointer */
|
||||
}
|
||||
|
||||
void
|
||||
IRQ_fallback(int type, unsigned long esr, unsigned long address)
|
||||
{
|
||||
Log_putS(m_types[type]);
|
||||
Log_putS(" -> ESR: ");
|
||||
Log_putU(esr, 16);
|
||||
Log_putS(", address: ");
|
||||
Log_putU(address, 16);
|
||||
Log_putS("\r\n");
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017-2019 by Löwenware Ltd
|
||||
* Please, refer LICENSE file for legal information
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file irq.h
|
||||
* @author Ilja Kartašov <ik@lowenware.com>
|
||||
* @brief
|
||||
*
|
||||
* @see https://lowenware.com/
|
||||
*/
|
||||
|
||||
#ifndef IRQ_H_037ADD8D_3AAA_4541_A876_843DFF3A59E8
|
||||
#define IRQ_H_037ADD8D_3AAA_4541_A876_843DFF3A59E8
|
||||
|
||||
#include <aarch64/aarch64.h>
|
||||
|
||||
void
|
||||
IRQ_init(void);
|
||||
|
||||
unsigned long
|
||||
IRQ_onInterrupt(void);
|
||||
|
||||
void
|
||||
IRQ_fallback(int type, unsigned long esr, unsigned long address);
|
||||
|
||||
#define IRQ_enable(...) AArch64_enableIRQ(__VA_ARGS__)
|
||||
|
||||
#define IRQ_disable(...) AArch64_disableIRQ(__VA_ARGS__)
|
||||
|
||||
#endif /* !IRQ_H */
|
||||
@@ -0,0 +1,42 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017-2019 by Löwenware Ltd
|
||||
* Please, refer LICENSE file for legal information
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file main.c
|
||||
* @author Ilja Kartašov <ik@lowenware.com>
|
||||
* @brief
|
||||
*
|
||||
* @see https://lowenware.com/
|
||||
*/
|
||||
|
||||
#include <leos/log.h>
|
||||
#include <leos/arch.h>
|
||||
#include <leos/irq.h>
|
||||
#include <leos/timer.h>
|
||||
#include <leos/leos.h>
|
||||
|
||||
|
||||
void
|
||||
Leos_run(void)
|
||||
{
|
||||
Log_init();
|
||||
|
||||
Log_putS("Starting Lowe OS (EL");
|
||||
Log_putI(AArch64_getEL(), 10);
|
||||
Log_putS(")\r\n");
|
||||
|
||||
Arch_init();
|
||||
|
||||
Timer_init();
|
||||
IRQ_init();
|
||||
IRQ_enable();
|
||||
|
||||
for (;;) {
|
||||
__asm__("WFE");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017-2020 by Löwenware Ltd
|
||||
* Please, refer LICENSE file for legal information
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file leos.h
|
||||
* @author Ilja Kartašov <ik@lowenware.com>
|
||||
* @brief
|
||||
*
|
||||
* @see https://lowenware.com/
|
||||
*/
|
||||
|
||||
#ifndef LEOS_H_7087F58B_BDEB_433B_A013_5B5F854922AF
|
||||
#define LEOS_H_7087F58B_BDEB_433B_A013_5B5F854922AF
|
||||
|
||||
void
|
||||
Leos_run(void);
|
||||
|
||||
#endif /* !LEOS_H */
|
||||
@@ -0,0 +1,82 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017-2019 by Löwenware Ltd
|
||||
* Please, refer LICENSE file for legal information
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file log.c
|
||||
* @author Ilja Kartašov <ik@lowenware.com>
|
||||
* @brief
|
||||
*
|
||||
* @see https://lowenware.com/
|
||||
*/
|
||||
|
||||
#include <device/uart/uart.h>
|
||||
#include "log.h"
|
||||
|
||||
void
|
||||
Log_init(void)
|
||||
{
|
||||
UART_init();
|
||||
}
|
||||
|
||||
int
|
||||
Log_putS(const char *string)
|
||||
{
|
||||
char c;
|
||||
const char *p = string;
|
||||
while((c = *p) != 0) {
|
||||
if (UART_send(c))
|
||||
return -1;
|
||||
p++;
|
||||
}
|
||||
return (int)(p - string);
|
||||
}
|
||||
|
||||
int
|
||||
Log_putI(int64_t value, uint8_t base)
|
||||
{
|
||||
int result;
|
||||
|
||||
if (value < 0) {
|
||||
if (UART_send('-'))
|
||||
return -1;
|
||||
value = -value;
|
||||
result = 1;
|
||||
} else {
|
||||
result = 0;
|
||||
}
|
||||
result += k_logu(value, base);
|
||||
return (result) ? result : -1;
|
||||
}
|
||||
|
||||
int
|
||||
Log_putU(uint64_t value, uint8_t base)
|
||||
{
|
||||
int i = 0, result;
|
||||
char buffer[64];
|
||||
|
||||
if (!value) {
|
||||
return (UART_send('0')) ? -1 : 1;
|
||||
}
|
||||
|
||||
do {
|
||||
uint64_t r;
|
||||
if (!(i < (sizeof(buffer) / sizeof(buffer[0]))))
|
||||
return -1;
|
||||
|
||||
r = value % base;
|
||||
buffer[i++] = (r < 0x0A) ? '0' + r : 'A' + r - 0x0A;
|
||||
value /= base;
|
||||
} while (value);
|
||||
|
||||
result = i;
|
||||
|
||||
while (i--) {
|
||||
if (UART_send(buffer[i]))
|
||||
return -1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017-2019 by Löwenware Ltd
|
||||
* Please, refer LICENSE file for legal information
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file print.h
|
||||
* @author Ilja Kartašov <ik@lowenware.com>
|
||||
* @brief
|
||||
*
|
||||
* @see https://lowenware.com/
|
||||
*/
|
||||
|
||||
#ifndef LOG_H_AE38CD54_2822_47A5_AFB1_E785739FA01D
|
||||
#define LOG_H_AE38CD54_2822_47A5_AFB1_E785739FA01D
|
||||
|
||||
#include <core/types.h>
|
||||
|
||||
void
|
||||
Log_init(void);
|
||||
|
||||
int
|
||||
Log_putS(const char *string);
|
||||
|
||||
int
|
||||
Log_putI(int64_t value, uint8_t base);
|
||||
|
||||
int
|
||||
Log_putU(uint64_t value, uint8_t base);
|
||||
|
||||
#endif /* !LOG_H */
|
||||
@@ -0,0 +1,54 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017-2020 by Löwenware Ltd
|
||||
* Please, refer LICENSE file for legal information
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
unsigned
|
||||
* @file memory.c
|
||||
* @author Ilja Kartašov <ik@lowenware.com>
|
||||
* @brief
|
||||
*
|
||||
* @see https://lowenware.com/
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <aarch64/bcm2837.h>
|
||||
#include "memory.h"
|
||||
|
||||
static unsigned long m_map[MEMORY_PAGE_COUNT / sizeof(unsigned long) / 8] = {0,};
|
||||
static int m_ix = 0;
|
||||
|
||||
void *
|
||||
Memory_getPage(void)
|
||||
{
|
||||
int i, j;
|
||||
unsigned long map;
|
||||
|
||||
|
||||
for (i = m_ix; i < sizeof(m_map) / sizeof(m_map[0]); i++) {
|
||||
map = m_map[i];
|
||||
for (j = 0; j < 8 * sizeof(map); j++) {
|
||||
if (!(map & (1 << j))) {
|
||||
m_map[i] |= (1 << j);
|
||||
return (void *) ((i * sizeof(map) * 8 + j) * MEMORY_PAGE_SIZE);
|
||||
}
|
||||
}
|
||||
m_ix = i;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
Memory_freePage(void *p_addr)
|
||||
{
|
||||
int i, j, c;
|
||||
|
||||
c = ((unsigned long) p_addr) / MEMORY_PAGE_SIZE;
|
||||
i = c / sizeof(m_map[0]);
|
||||
j = c % sizeof(m_map[0]);
|
||||
m_map[i] &= ~(1 << j);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017-2020 by Löwenware Ltd
|
||||
* Please, refer LICENSE file for legal information
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file memory.h
|
||||
* @author Ilja Kartašov <ik@lowenware.com>
|
||||
* @brief
|
||||
*
|
||||
* @see https://lowenware.com/
|
||||
*/
|
||||
|
||||
#ifndef MEMORY_H_C583E24E_55B0_49EF_99C9_5A36B04468AC
|
||||
#define MEMORY_H_C583E24E_55B0_49EF_99C9_5A36B04468AC
|
||||
|
||||
void *
|
||||
Memory_getPage(void);
|
||||
|
||||
void
|
||||
Memory_freePage(void *p_addr);
|
||||
|
||||
|
||||
#endif /* !MEMORY_H */
|
||||
@@ -0,0 +1,92 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017-2020 by Löwenware Ltd
|
||||
* Please, refer LICENSE file for legal information
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file scheduler.c
|
||||
* @author Ilja Kartašov <ik@lowenware.com>
|
||||
* @brief
|
||||
*
|
||||
* @see https://lowenware.com/
|
||||
*/
|
||||
|
||||
#include "scheduler.h"
|
||||
|
||||
|
||||
static struct KTask *m_first = NULL, *m_last, *m_current = NULL;
|
||||
static KPid m_pid = 0;
|
||||
|
||||
static void
|
||||
_disable_preempt(void)
|
||||
{
|
||||
m_current->preempt++;
|
||||
}
|
||||
|
||||
static void
|
||||
_enable_preempt(void)
|
||||
{
|
||||
m_current->preempt--;
|
||||
}
|
||||
|
||||
static void
|
||||
_switch(void)
|
||||
{
|
||||
struct KTask *i, *next;
|
||||
long p = 0;
|
||||
|
||||
_disable_preempt();
|
||||
|
||||
for (;;) {
|
||||
/* check urgent tasks */
|
||||
for (i = m_first; i != NULL; i = i->next) {
|
||||
if (!i->state && i->counter > p) {
|
||||
p = i->counter;
|
||||
next = i;
|
||||
}
|
||||
i = i->next;
|
||||
}
|
||||
|
||||
if (p) {
|
||||
break;
|
||||
}
|
||||
|
||||
i = m_first;
|
||||
for (i = m_first; i != NULL; i = i->next) {
|
||||
i->counter = i->priority;
|
||||
}
|
||||
}
|
||||
|
||||
aarch64_switch(m_current, next);
|
||||
_enable_preempt();
|
||||
}
|
||||
|
||||
void
|
||||
scheduler_init(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
KPid
|
||||
scheduler_add(struct KTask *task)
|
||||
{
|
||||
KPid result = ++m_pid;
|
||||
task->pid = result;
|
||||
task->prev = m_last;
|
||||
m_last->next = task;
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
scheduler_switch(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
scheduler_switch_from_isr(void)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017-2019 by Löwenware Ltd
|
||||
* Please, refer LICENSE file for legal information
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file scheduler.h
|
||||
* @author Ilja Kartašov <ik@lowenware.com>
|
||||
* @brief
|
||||
*
|
||||
* @see https://lowenware.com/
|
||||
*/
|
||||
|
||||
#ifndef SCHEDULER_H_AE39DBC8_E643_4857_B319_9732123728A4
|
||||
#define SCHEDULER_H_AE39DBC8_E643_4857_B319_9732123728A4
|
||||
|
||||
void
|
||||
scheduler_init(void);
|
||||
|
||||
void
|
||||
scheduler_run(void);
|
||||
|
||||
void
|
||||
scheduler_switch(void);
|
||||
|
||||
KPid
|
||||
scheduler_add(struct KTask *task);
|
||||
|
||||
KRetCode
|
||||
scheduler_remove(struct KTask *task);
|
||||
|
||||
KRetCode
|
||||
scheduler_remove_pid(KPid pid);
|
||||
|
||||
|
||||
#endif /* !SCHEDULER_H */
|
||||
@@ -0,0 +1,36 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017-2019 by Löwenware Ltd
|
||||
* Please, refer LICENSE file for legal information
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file task.h
|
||||
* @author Ilja Kartašov <ik@lowenware.com>
|
||||
* @brief
|
||||
*
|
||||
* @see https://lowenware.com/
|
||||
*/
|
||||
|
||||
#ifndef TASK_H_AE13C166_79B5_4256_ABF3_74DF04E1CD18
|
||||
#define TASK_H_AE13C166_79B5_4256_ABF3_74DF04E1CD18
|
||||
|
||||
#include <core/types.h>
|
||||
|
||||
typedef void (*TaskCallback)(void *p_ctx);
|
||||
|
||||
struct Task {
|
||||
char name[CONFIG_TASK_MAX_NAME_LEN + 1];
|
||||
TaskCallback callback;
|
||||
uint64_t *stack;
|
||||
uint32_t stack_size;
|
||||
uint32_t priority;
|
||||
};
|
||||
|
||||
PID
|
||||
Task_create(struct Task *pTask, TaskCallback callback, uint64_t *stack
|
||||
, uint32_t stack_size);
|
||||
|
||||
|
||||
#endif /* !TASK_H */
|
||||
@@ -0,0 +1,25 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017-2019 by Löwenware Ltd
|
||||
* Please, refer LICENSE file for legal information
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file types.h
|
||||
* @author Ilja Kartašov <ik@lowenware.com>
|
||||
* @brief
|
||||
*
|
||||
* @see https://lowenware.com/
|
||||
*/
|
||||
|
||||
#ifndef TYPES_H_BC3DA9C0_C9EE_4853_B5F5_EAA4B801664C
|
||||
#define TYPES_H_BC3DA9C0_C9EE_4853_B5F5_EAA4B801664C
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef int RetCode;
|
||||
typedef unsigned int PID;
|
||||
|
||||
#endif /* !TYPES_H */
|
||||
Reference in New Issue
Block a user