added licensing

master
Clyne Sullivan 7 years ago
parent 5c5c93db40
commit 603d04992c

@ -1,7 +1,7 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
@ -645,7 +645,7 @@ the "copyright" line and a pointer to where the full notice is found.
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
@ -664,11 +664,12 @@ might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
<https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
<https://www.gnu.org/licenses/why-not-lgpl.html>.

@ -1,3 +1,23 @@
##
# @file Makefile
# Script to build source files
#
# Copyright (C) 2018 Clyne Sullivan
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
CROSS = arm-none-eabi-
CC = gcc
AS = as

@ -1,7 +1,10 @@
# calculator
An OS for an STM32-based calculator
A from-scratch operating system for a graphing calculator.
Trying to make an operating system for a calculator based on the STM32L476RG, using its associated Nucleo board. Starting from scratch because it's fun.
The goal of this project is to design a functional operating system for a
graphing calculator based on the STM32L476RG processor. This OS has been
designed from scratch to optimize for speed and code size, targeting the
features necessary for a graphing calculator application.
Required packages:
* arm-none-eabi toolchain
@ -10,4 +13,10 @@ Required packages:
Use ```run.sh``` to upload the final output to the processor.
To make an initrd, add files to ```initrd/``` and then run ```./mkinitrd.sh```.
## design overview
The core of the operating system is written entirely in C and assembly. This
project is paired with the [interpreter project](https://code.bitgloo.com/clyne/interpreter)
(licensed under the GPL),
which parses script from C strings. The operating system exposes calls to the
script parser, and then loads the text file at ```initrd/init```.

@ -1,6 +1,21 @@
/**
* @file clock.h
* Basic clock utilities
*
* Copyright (C) 2018 Clyne Sullivan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef CLOCK_H_
@ -9,7 +24,7 @@
#include <stdint.h>
/**
* Sets HCLK (system clock) to 80MHz, the maximum.
* Initializes clocks, setting HCLK (system clock) to 80MHz, the maximum.
*/
extern void clock_init(void);

@ -1,6 +1,21 @@
/*
* @file display.h
* Display library for ILI9481 display.
* Display library for ILI9481 display
*
* Copyright (C) 2018 Clyne Sullivan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef DISPLAY_H_
@ -18,6 +33,11 @@
*/
#define LCD_HEIGHT 320
/**
* Initializes the display. Must be called before other display use.
*/
void dsp_init(void);
/**
* Returns the color integer for the given RGB values.
* Converts 8RGB to 5-6-5.
@ -52,9 +72,24 @@ void dsp_write_data(uint8_t data);
*/
uint8_t dsp_read_data(void);
/**
* Selects the area of pixels to draw to, from (x1, y1) inclusive to (x2, y2)
* exclusive.
* @param x1 starting x coordinate
* @param y1 starting y coordinate
* @param x2 ending x coordinate
* @param y2 ending y coordinate
*/
void dsp_set_addr(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
void dsp_set_addr_read(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
void dsp_init(void);
/**
* Selects the area of pixels to read from, in the range (x1, y1) inclusive to
* (x2, y2) exclusive.
* @param x1 starting x coordinate
* @param y1 starting y coordinate
* @param x2 ending x coordinate
* @param y2 ending y coordinate
*/
void dsp_set_addr_read(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
#endif // DISPLAY_H_

@ -1,6 +1,21 @@
/**
* @file display_draw.h
* Provides functions for drawing to the display
*
* Copyright (C) 2018 Clyne Sullivan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef DISPLAY_DRAW_H_

@ -1,11 +1,49 @@
/**
* @file flash.h
* Provides functionality for using an external SPI flash
*
* Copyright (C) 2018 Clyne Sullivan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef FLASH_H_
#define FLASH_H_
#include <stdint.h>
/**
* Initializes GPIO ports and variables for flash IO. Must be called before
* any reads or writes.
*/
void flash_init(void);
/**
* Does a blocking read of the flash chip into a pre-allocated buffer.
* @param buf the buffer to read in to
* @param addr the address to read from in the flash chip
* @param count the number of bytes to read from the chip
*/
void flash_read(char *buf, uint32_t addr, unsigned int count);
/**
* Does a blocking write to the flash chip using data from a pre-allocated
* buffer.
* @param buf the buffer to read data from
* @param addr the address to write to in the flash chip
* @param count the number of bytes to write to the chip
*/
void flash_write(const char *buf, uint32_t addr, unsigned int count);
#endif // FLASH_H_

@ -1,6 +1,21 @@
/**
* @file gpio.h
* Abstracts gpio access, makes things easier
*
* Copyright (C) 2018 Clyne Sullivan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef GPIO_H_

@ -1,6 +1,21 @@
/**
* @file heap.h
* A basic memory manager
*
* Copyright (C) 2018 Clyne Sullivan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef HEAP_H_

@ -4,6 +4,21 @@
* An archive file (made with ar) can be linked into the final executable to
* allow files to be loaded in memory on boot. See mkinitrd.sh or the Makefile
* for more info.
*
* Copyright (C) 2018 Clyne Sullivan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef INITRD_H_
@ -16,7 +31,7 @@
*/
typedef struct
{
char signature[8]; /**< The archive's signature. */
char signature[8]; /**< The archive's signature */
} __attribute__ ((packed)) initrd_header;
/**
@ -24,10 +39,10 @@ typedef struct
*/
typedef struct
{
char name[16]; /**< The name of the file. */
uint8_t unused[32]; /**< Unused information. */
char size[10]; /**< The file's size in bytes (as string). */
char sig[2]; /**< A signature to start file data. */
char name[16]; /**< The name of the file */
uint8_t unused[32]; /**< Unused information */
char size[10]; /**< The file's size in bytes (as string) */
char sig[2]; /**< A signature to start file data */
} __attribute__ ((packed)) initrd_file;
/**

@ -1,3 +1,23 @@
/**
* @file keypad.h
* Manages the GPIO keypad
*
* Copyright (C) 2018 Clyne Sullivan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef KEYPAD_H_
#define KEYPAD_H_
@ -16,9 +36,21 @@
#define KS (uint16_t)(1 << 10)
#define KP (uint16_t)(1 << 11)
/**
* Initializes GPIO for the keypad. Must be called before any keypad reading.
*/
void keypad_init(void);
/**
* Reads the state of the keypad and returns it.
* @return the keypad's state
*/
uint16_t keypad_get(void);
/**
* Tests if the given key is currently pressed, returning non-zero if it is.
* @return non-zero if pressed
*/
uint8_t keypad_isdown(uint16_t);
#endif // KEYPAD_H_

@ -1,6 +1,21 @@
/**
* @file lcd.h
* A basic library for writing a 16x2 text LCD.
*
* Copyright (C) 2018 Clyne Sullivan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef LCD_H_

@ -1,6 +1,21 @@
/**
* @file random.h
* Provides true random number generation functionality
*
* Copyright (C) 2018 Clyne Sullivan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef RANDOM_H_

@ -1,6 +1,21 @@
/**
* @file script.h
* Provides script library for using calculator hardware
*
* Copyright (C) 2018 Clyne Sullivan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef SCRIPT_H_
@ -9,7 +24,7 @@
#include <parser.h>
/**
* Loads the library for the given interpreter.
* Loads the library for the given interpreter instance.
* @param it the interpreter to use
*/
void script_loadlib(instance *it);

@ -1,6 +1,21 @@
/**
* @file serial.h
* Provides basic serial IO (through STM debug stuff)
*
* Copyright (C) 2018 Clyne Sullivan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef SERIAL_H_

@ -1,8 +1,51 @@
/**
* @file stdlib.h
* Provides missing C standard library functions
* The newlib versions of these calls are not being used due to dependence on
* unsupported system calls.
*
* Copyright (C) 2018 Clyne Sullivan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef STDLIB_H_
#define STDLIB_H_
/**
* Parses a formatted string, storing the result in the given buffer.
* @param buf the buffer to print the parsed string to
* @param max the maximum number of bytes to write to the buffer
* @param format the format string
* @return a pointer to the buffer
*/
char *snprintf(char *buf, unsigned int max, const char *format, ...);
/**
* Attempts to convert the given string to a float.
* @param s the string to convert
* @param endptr if not-null, set to the address of the character after the
* number
* @return the resulting float, or zero if an error occurred
*/
float strtof(const char *s, char **endptr);
/**
* Attempts to convert the given string to an integer.
* @param s the string to convert
* @return the resulting integer, or zero if an error occurred
*/
int atoi(const char *s);
#endif // STDLIB_H_

@ -1,6 +1,21 @@
/**
* @file task.h
* Provides multitasking functionality
*
* Copyright (C) 2018 Clyne Sullivan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef TASK_H_
@ -8,10 +23,13 @@
#include <stdint.h>
/**
* A structure to contain task data.
*/
typedef struct {
void *next;
uint32_t *stack;
uint32_t *sp;
void *next; /**< pointer to the next task_t instance */
uint32_t *stack; /**< pointer to the task's stack */
uint32_t *sp; /**< pointer to the task's last sp register value */
} task_t;
/**

@ -1 +0,0 @@
print "Hello, world!"

@ -0,0 +1,29 @@
print("Hello.\n")
fg = 32767
# draw bg, lines
rect(50, 50, 380, 220, 6375)
line(50, 160, 430, 160, fg)
line(240, 50, 240, 270, fg)
x = 50
while (x <= 430) {
line(x, 170, x, 150, fg)
x = x + 20
}
y = 50
while (y <= 270) {
line(230, y, 250, y, fg)
y = y + 20
}
while (1) {
x = rand(379) + 50
y = rand(219) + 50
i = 50 + rand(379)
j = 50 + rand(219)
line(x, y, i, j, 511)
}

Binary file not shown.

@ -1,162 +1,82 @@
/*
*****************************************************************************
**
** File : LinkerScript.ld
**
** Abstract : Linker script for STM32L476RGTx Device with
** 1024KByte FLASH, 96KByte RAM
**
** Set heap size, stack size and stack location according
** to application requirements.
**
** Set memory bank area and size if external memory is used.
**
** Target : STMicroelectronics STM32
**
**
** Distribution: The file is distributed as is, without any warranty
** of any kind.
**
** (c)Copyright Ac6.
** You may use this file as-is or modify it according to the needs of your
** project. Distribution of this file (unmodified or modified) is not
** permitted. Ac6 permit registered System Workbench for MCU users the
** rights to distribute the assembled, compiled & linked contents of this
** file as part of an application binary file, provided that it is built
** using the System Workbench for MCU toolchain.
**
*****************************************************************************
*/
/* Entry Point */
/**
* @file linker.ld
*
* Copyright (C) 2018 Clyne Sullivan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/* enter at the reset handler */
ENTRY(Reset_Handler)
/* Highest address of the user mode stack */
_estack = 0x20018000; /* end of RAM */
/* Specify the memory areas */
MEMORY
{
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 1024K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 96K
/* description of memory regions */
MEMORY {
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 96K
}
/* Define output sections */
SECTIONS
{
/* The startup code goes first into FLASH */
.isr_vector :
{
. = ALIGN(8);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(8);
} >FLASH
/* The program code and other data goes into FLASH */
.text :
{
. = ALIGN(8);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(8);
_etext = .; /* define a global symbols at end of code */
} >FLASH
/* Constant data goes into FLASH */
.rodata :
{
. = ALIGN(8);
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
. = ALIGN(8);
} >FLASH
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
.ARM : {
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} >FLASH
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array*))
PROVIDE_HIDDEN (__preinit_array_end = .);
} >FLASH
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array*))
PROVIDE_HIDDEN (__init_array_end = .);
} >FLASH
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT(.fini_array.*)))
KEEP (*(.fini_array*))
PROVIDE_HIDDEN (__fini_array_end = .);
} >FLASH
/* used by the startup to initialize data */
_sidata = LOADADDR(.data);
/* Initialized data sections goes into RAM, load LMA copy after code */
.data :
{
. = ALIGN(8);
_sdata = .; /* create a global symbol at data start */
*(.data) /* .data sections */
*(.data*) /* .data* sections */
. = ALIGN(8);
_edata = .; /* define a global symbol at data end */
} >RAM AT> FLASH
/* Uninitialized data section */
. = ALIGN(4);
.bss :
{
/* This is used by the startup in order to initialize the .bss secion */
_sbss = .; /* define a global symbol at bss start */
__bss_start__ = _sbss;
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(4);
_ebss = .; /* define a global symbol at bss end */
__bss_end__ = _ebss;
} >RAM
/* User_heap_stack section, used to check that there is enough RAM left */
._user_heap_stack :
{
. = ALIGN(8);
*(._user_heap_stack)
. = ALIGN(8);
} >RAM
/* Remove information from the standard libraries */
/DISCARD/ :
{
libc.a ( * )
libm.a ( * )
libgcc.a ( * )
}
.ARM.attributes 0 : { *(.ARM.attributes) }
/* description of ELF sections */
SECTIONS {
/* keep startup code at beginning */
.isr_vector : {
. = ALIGN(8);
KEEP(*(.isr_vector))
. = ALIGN(8);
} > FLASH
/* code sections */
.text : {
. = ALIGN(8);
*(.text)
. = ALIGN(8);
} > FLASH
/* readonly data */
.rodata : {
. = ALIGN(8);
*(.rodata)
. = ALIGN(8);
} > FLASH
/* init_array/fini_array (TODO understand this) */
.init_array : {
PROVIDE_HIDDEN(__init_array_start = .);
KEEP(*(.init_array))
PROVIDE_HIDDEN(__init_array_end = .);
} > FLASH
.fini_array : {
PROVIDE_HIDDEN(__fini_array_start = .);
KEEP(*(.fini_array))
PROVIDE_HIDDEN(__fini_array_end = .);
} > FLASH
/* initialized data */
_sidata = LOADADDR(.data);
.data : {
. = ALIGN(8);
_sdata = .;
*(.data)
. = ALIGN(8);
_edata = .;
} > RAM AT > FLASH
/* uninitialized data */
.bss : {
. = ALIGN(8);
__bss_start__ = .;
*(.bss)
__bss_end__ = .;
} > RAM
}

@ -1,4 +1,23 @@
#!/bin/bash
#
# @file run.sh
# Starts openocd and connects gdb to the target, for programming/debugging
#
# Copyright (C) 2018 Clyne Sullivan
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
openocd -f /usr/share/openocd/scripts/board/st_nucleo_l476rg.cfg > /dev/null &
gdb-multiarch -iex "target remote localhost:3333" out/main.elf

@ -1,3 +1,23 @@
/**
* @file clock.c
* Basic clock utilities
*
* Copyright (C) 2018 Clyne Sullivan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <clock.h>
#include <stm32l476xx.h>

@ -1,3 +1,23 @@
/*
* @file display.c
* Display library for ILI9481 display
*
* Copyright (C) 2018 Clyne Sullivan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <display.h>
#include <clock.h>

@ -1,3 +1,23 @@
/**
* @file display_draw.c
* Provides functions for drawing to the display
*
* Copyright (C) 2018 Clyne Sullivan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <display_draw.h>
#include <display.h>
#include <task.h>
@ -41,6 +61,7 @@ void dsp_putchar(int c)
dsp_rect(0, 0, LCD_WIDTH, LCD_HEIGHT, 0);
cury = 0;
}
UNLOCK;
return;
} else if (c == '\b') {
if (curx > 0)

@ -1,3 +1,23 @@
/**
* @file flash.c
* Provides functionality for using an external SPI flash
*
* Copyright (C) 2018 Clyne Sullivan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <stm32l476xx.h>
#include <gpio.h>
#include <clock.h>

@ -0,0 +1,110 @@
#include <stm32l476xx.h>
#include <gpio.h>
#include <clock.h>
#define READ 0x03
#define WRITE 0x02
#define WREN 0x06
#define WRDS 0x04
#define SCK GPIO_PORT(C, 9)
#define SI GPIO_PORT(B, 8)
#define SO GPIO_PORT(B, 9)
#define CS GPIO_PORT(C, 4)
void flash_out(uint8_t);
uint8_t flash_in(void);
void flash_init(void)
{
gpio_mode(SCK, OUTPUT);
gpio_mode(SI, OUTPUT);
gpio_mode(CS, OUTPUT);
gpio_mode(SO, OUTPUT);
gpio_dout(SO, 0);
gpio_mode(SO, INPUT);
gpio_dout(CS, 1);
gpio_dout(SCK, 0);
gpio_dout(SI, 0);
//RCC->AHB3ENR |= RCC_AHB3ENR_QSPIEN;
//// 10MHz operation, per datasheet
//QUADSPI->CR &= ~(0xFF << QUADSPI_CR_PRESCALER_Pos);
//QUADSPI->CR |= 7 << QUADSPI_CR_PRESCALER_Pos;
//// pick FSEL! 0=1, 1=2
//// FSIZE = 16, 2^17 bits = 1Mb
//QUADSPI->DCR = (16 << QUADSPI_DCR_FSIZE_Pos);
//// Memmap mode, single-spi
//QUADSPI->CCR = (3 << QUADSPI_CCR_FMODE_Pos) | (1 << QUADSPI_CCR_DMODE_Pos)
// | (2 << QUADSPI_CCR_ADSIZE_Pos) | (1 << QUADSPI_CCR_ADMODE_Pos)
// | (1 << QUADSPI_CCR_IMODE_Pos);
//// TODO CCR also takes instruction byte
//QUADSPI->CCR |= (READ << QUADSPI_CCR_INSTRUCTION_Pos);
//QUADSPI->CR |= QUADSPI_CR_EN;
}
void flash_out(uint8_t byte)
{
for (uint8_t i = 0; i < 8; i++) {
gpio_dout(SI, (byte & (1 << (7 - i))));
gpio_dout(SCK, 1);
gpio_dout(SCK, 0);
}
}
void flash_addr(uint32_t addr)
{
for (uint8_t i = 0; i < 24; i++) {
gpio_dout(SI, (addr & (1 << (23 - i))));
gpio_dout(SCK, 1);
gpio_dout(SCK, 0);
}
}
uint8_t flash_in(void)
{
uint8_t byte = 0;
for (uint8_t i = 0; i < 8; i++) {
gpio_dout(SCK, 1);
gpio_dout(SCK, 0);
if (gpio_din(SO))
byte |= (1 << (7 - i));
}
return byte;
}
void flash_read(char *buf, uint32_t addr, unsigned int count)
{
if (buf == 0)
return;
gpio_dout(CS, 0);
flash_out(READ);
flash_addr(addr);
for (unsigned int i = 0; i < count; i++)
buf[i] = flash_in();
gpio_dout(CS, 1);
}
void flash_write(const char *buf, uint32_t addr, unsigned int count)
{
if (buf == 0)
return;
gpio_dout(CS, 0);
flash_out(WREN);
gpio_dout(CS, 1);
gpio_dout(CS, 0);
flash_out(WRITE);
flash_addr(addr);
for (unsigned int i = 0; i < count; i++)
flash_out(buf[i]);
gpio_dout(CS, 1);
delay(100);
//gpio_dout(CS, 0);
//flash_out(WRDS);
//gpio_dout(CS, 1);
}

@ -1,3 +1,23 @@
/**
* @file gpio.c
* Abstracts gpio access, makes things easier
*
* Copyright (C) 2018 Clyne Sullivan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <gpio.h>
void gpio_init(void)

@ -1,3 +1,23 @@
/**
* @file heap.c
* A basic memory manager
*
* Copyright (C) 2018 Clyne Sullivan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <heap.h>
#define HEAP_ALIGN 4

@ -1,3 +1,26 @@
/**
* @file initrd.c
* Initrd image support
* An archive file (made with ar) can be linked into the final executable to
* allow files to be loaded in memory on boot. See mkinitrd.sh or the Makefile
* for more info.
*
* Copyright (C) 2018 Clyne Sullivan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <initrd.h>
extern uint8_t _binary_initrd_img_start[];

@ -1,3 +1,23 @@
/**
* @file keypad.c
* Manages the GPIO keypad
*
* Copyright (C) 2018 Clyne Sullivan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <keypad.h>
#include <gpio.h>

@ -1,3 +1,23 @@
/**
* @file keypad.c
* Manages the GPIO keypad using IO expanders
*
* Copyright (C) 2018 Clyne Sullivan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <stm32l476xx.h>
#include <gpio.h>

@ -1,3 +1,23 @@
/**
* @file lcd.c
* A basic library for writing a 16x2 text LCD.
*
* Copyright (C) 2018 Clyne Sullivan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <lcd.h>
#include <clock.h>
#include <gpio.h>

@ -1,3 +1,23 @@
/**
* @file main.c
* Entry point for operating system
*
* Copyright (C) 2018 Clyne Sullivan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <stm32l476xx.h>
#include <clock.h>
#include <heap.h>
@ -15,7 +35,7 @@
#include <keypad.h>
#include <flash.h>
extern uint8_t _ebss;
extern uint8_t __bss_end__;
extern char *itoa(int, char *, int);
void kmain(void);
@ -32,7 +52,7 @@ int main(void)
FLASH->ACR |= FLASH_ACR_LATENCY_4WS;
clock_init();
heap_init(&_ebss);
heap_init(&__bss_end__);
gpio_init();
keypad_init();
serial_init();

@ -1,3 +1,23 @@
/**
* @file random.c
* Provides true random number generation functionality
*
* Copyright (C) 2018 Clyne Sullivan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <random.h>
#include <stm32l476xx.h>

@ -1,3 +1,23 @@
/**
* @file script.c
* Provides script library for using calculator hardware
*
* Copyright (C) 2018 Clyne Sullivan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <script.h>
#include <builtins.h>
@ -24,19 +44,41 @@ int script_color(instance *it);
int script_rand(instance *it);
int script_getkey(instance *it);
int script_pixel(instance *it);
int script_menu(instance *it);
void script_loadlib(instance *it)
{
inew_cfunc(it, "print", script_puts);
inew_cfunc(it, "gets", script_gets);
inew_cfunc(it, "delay", script_delay);
inew_cfunc(it, "rect", script_rect);
inew_cfunc(it, "getkey", script_getkey);
inew_cfunc(it, "ppos", script_ppos);
inew_cfunc(it, "pixel", script_pixel);
inew_cfunc(it, "line", script_line);
inew_cfunc(it, "rect", script_rect);
inew_cfunc(it, "color", script_color);
inew_cfunc(it, "rand", script_rand);
inew_cfunc(it, "getkey", script_getkey);
inew_cfunc(it, "pixel", script_pixel);
inew_cfunc(it, "delay", script_delay);
inew_cfunc(it, "menu", script_menu);
}
int script_menu(instance *it)
{
char listbuf[4];
int nargs = igetarg_integer(it, 0);
float *resps = (float *)calloc(nargs, sizeof(float));
strncpy(listbuf, " : \0", 4);
for (int i = 0; i < nargs; i++) {
listbuf[0] = i + '0';
dsp_puts(listbuf);
dsp_puts((char *)igetarg(it, 1 + i * 2)->value.p);
dsp_puts("\n");
resps[i] = igetarg(it, 2 + i * 2)->value.f;
}
free(resps);
return 0;
}
int script_puts(instance *it)
@ -125,7 +167,7 @@ int script_rand(instance *it)
{
unsigned int mod = igetarg_integer(it, 0);
unsigned int val = random_get();
variable *v = make_varf(0, (float)(mod % val));
variable *v = make_varf(0, (float)(val % mod));
ipush(it, (uint32_t)v);
return 0;
}

@ -1,3 +1,23 @@
/**
* @file serial.c
* Provides basic serial IO (through STM debug stuff)
*
* Copyright (C) 2018 Clyne Sullivan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <stm32l476xx.h>
#include <gpio.h>
#include <clock.h>

@ -57,10 +57,8 @@ defined in linker script */
.word _sdata
/* end address for the .data section. defined in linker script */
.word _edata
/* start address for the .bss section. defined in linker script */
.word _sbss
/* end address for the .bss section. defined in linker script */
.word _ebss
.equ _estack, 0x20018000
.equ BootRAM, 0xF1E0F85F
/**
@ -94,7 +92,7 @@ LoopCopyDataInit:
adds r2, r0, r1
cmp r2, r3
bcc CopyDataInit
ldr r2, =_sbss
ldr r2, =__bss_start__
b LoopFillZerobss
/* Zero fill the bss segment. */
FillZerobss:
@ -102,7 +100,7 @@ FillZerobss:
str r3, [r2], #4
LoopFillZerobss:
ldr r3, = _ebss
ldr r3, = __bss_end__
cmp r2, r3
bcc FillZerobss

@ -1,3 +1,25 @@
/**
* @file stdlib.c
* Provides missing C standard library functions
* The newlib versions of these calls are not being used due to dependence on
* unsupported system calls.
*
* Copyright (C) 2018 Clyne Sullivan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <ctype.h>

@ -1,3 +1,23 @@
/**
* @file task.c
* Provides multitasking functionality
*
* Copyright (C) 2018 Clyne Sullivan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <task.h>
#include <heap.h>
#include <stm32l476xx.h>

@ -1,33 +0,0 @@
print "Hello."
set fg 32767
# draw bg, lines
rect 50 50 380 220 6375
line 50 160 430 160 fg
line 240 50 240 270 fg
set x 50
do
line x 170 x 150 fg
set x (x + 20)
while (x < 431)
set y 50
do
line 230 y 250 y fg
set y (y + 20)
while (y < 271)
do
rand 379 > x
rand 219 > y
rand 379 > i
rand 219 > j
set x (x + 50)
set y (y + 50)
set i (i + 50)
set j (j + 50)
line x y i j 511
while (1)

@ -1,21 +0,0 @@
do
getkey > input
print input
delay 1000
while (1)
#do
# getkey > input
# if (input & 4)
# rand 479 > x
# rand 319 > y
# rand 479 > i
# rand 319 > j
# rand 32767 > purple
#
# line x y i j purple
# end
#while (1)
#
#print "done"
Loading…
Cancel
Save