├── .gitignore ├── Kconfig ├── LICENSE ├── Makefile ├── README.md ├── STYLE ├── arch ├── Kconfig ├── Makefile ├── armv7a │ ├── Kconfig │ ├── Makefile │ ├── arch.c │ ├── chip │ │ ├── Kconfig │ │ ├── Makefile │ │ └── am335x │ │ │ ├── Kconfig │ │ │ ├── Makefile │ │ │ ├── chip.c │ │ │ ├── clocks.c │ │ │ ├── clocks.h │ │ │ ├── config.mk │ │ │ ├── interrupts.c │ │ │ ├── interrupts.h │ │ │ ├── memory_map.h │ │ │ ├── prcm.c │ │ │ ├── timer.c │ │ │ ├── timer.h │ │ │ └── usart.c │ ├── config.mk │ ├── exception_handlers.c │ ├── include │ │ ├── atomic.h │ │ ├── chip.h │ │ ├── svc.h │ │ └── system_regs.h │ ├── kernel │ │ ├── Makefile │ │ ├── sched.c │ │ ├── sched_asm.S │ │ ├── sched_asm.h │ │ └── svc.c │ ├── link.ld │ ├── power.c │ └── start.S └── armv7m │ ├── Kconfig │ ├── Makefile │ ├── arch.c │ ├── chip │ ├── Kconfig │ ├── Makefile │ ├── cortex-m4f.mk │ ├── lm4f120h5 │ │ ├── Kconfig │ │ ├── Makefile │ │ ├── boards │ │ │ ├── Makefile │ │ │ └── launchpad.c │ │ ├── clock.c │ │ ├── config.mk │ │ ├── dev │ │ │ ├── Makefile │ │ │ └── hw │ │ │ │ ├── Makefile │ │ │ │ └── usart.c │ │ ├── flash.sh │ │ ├── gpio.c │ │ ├── include │ │ │ ├── gpio.h │ │ │ ├── registers.h │ │ │ └── rom.h │ │ ├── sysctl.h │ │ └── vector.S │ ├── msp432p401x │ │ ├── Kconfig │ │ ├── Makefile │ │ ├── clock.c │ │ ├── config.mk │ │ ├── include │ │ │ └── rom.h │ │ └── vector.S │ └── stm32f40x │ │ ├── Kconfig │ │ ├── Makefile │ │ ├── adc.c │ │ ├── boards │ │ ├── Makefile │ │ ├── discovery.c │ │ └── px4.c │ │ ├── clock.c │ │ ├── config.mk │ │ ├── dev │ │ ├── Makefile │ │ └── hw │ │ │ ├── Makefile │ │ │ ├── i2c.c │ │ │ ├── perfcounter.c │ │ │ ├── spi.c │ │ │ └── usb │ │ │ ├── Makefile │ │ │ ├── usbdev_cdc.c │ │ │ ├── usbdev_char.c │ │ │ ├── usbdev_class.h │ │ │ ├── usbdev_core.c │ │ │ ├── usbdev_desc.c │ │ │ ├── usbdev_desc.h │ │ │ ├── usbdev_init.c │ │ │ ├── usbdev_int.c │ │ │ └── usbdev_internals.h │ │ ├── dma.c │ │ ├── flash.sh │ │ ├── gpio.c │ │ ├── include │ │ ├── adc.h │ │ ├── clock.h │ │ ├── dma.h │ │ ├── gpio.h │ │ ├── i2c.h │ │ ├── periph.h │ │ ├── rcc.h │ │ ├── registers.h │ │ ├── spi.h │ │ ├── timer.h │ │ └── usart.h │ │ ├── pwm.c │ │ ├── rcc.c │ │ ├── uart.c │ │ └── vector.S │ ├── config.mk │ ├── dev │ ├── Makefile │ └── hw │ │ ├── Makefile │ │ └── systick.c │ ├── fault.c │ ├── handlers.S │ ├── include │ ├── atomic.h │ ├── chip.h │ ├── svc.h │ └── system.h │ ├── kernel │ ├── Makefile │ ├── sched.c │ ├── sched.h │ ├── sched_asm.S │ └── svc.c │ ├── link.ld │ ├── math.c │ └── power.c ├── configs ├── 32f401cdiscovery.dts ├── 32f401cdiscovery_defconfig ├── Makefile.in ├── am335x_bone.dts ├── am33xx.dtsi ├── beaglebone_black_defconfig ├── msp432_launchpad.dts ├── msp432_launchpad_defconfig ├── px4_defconfig ├── stellaris_launchpad.dts ├── stellaris_launchpad_defconfig ├── stm32f4 │ ├── 01.dtsi │ ├── 01xc.dtsi │ ├── 05.dtsi │ ├── 05xg.dtsi │ ├── 07.dtsi │ ├── 07xg.dtsi │ └── common.dtsi ├── stm32f4_discovery_revb.dts ├── stm32f4_discovery_revb_defconfig ├── stm32f4_discovery_revc.dts ├── stm32f4_discovery_revc_defconfig └── stm32f4_px4.dts ├── dev ├── Kconfig ├── Makefile ├── accel │ ├── Kconfig │ ├── Makefile │ ├── accel.c │ ├── lis302dl.c │ └── lis302dl.h ├── baro │ ├── Kconfig │ ├── Makefile │ ├── baro.c │ └── ms5611.c ├── buf_stream.c ├── char.c ├── clocks.c ├── device.c ├── fdtparse.c ├── gyro │ ├── Kconfig │ ├── Makefile │ ├── gyro.c │ └── itg3200.c ├── hw │ ├── Makefile │ ├── adc.c │ ├── gpio.c │ ├── i2c.c │ ├── led.c │ ├── pwm.c │ ├── spi.c │ └── uart.c ├── mag │ ├── Kconfig │ ├── Makefile │ ├── hmc5883.c │ └── mag.c ├── mpu6000 │ ├── Kconfig │ ├── Makefile │ ├── accel.c │ ├── class.c │ ├── gyro.c │ ├── regs.h │ └── spi.c ├── resource.c ├── rotary_encoder │ ├── Kconfig │ ├── Makefile │ ├── as5048b.c │ └── rotary_encoder.c └── shared_mem.c ├── docs ├── am335x.md ├── arch_porting.md ├── armv7a.md ├── armv7m.md ├── fdt │ └── bindings │ │ ├── README │ │ ├── address-layout.txt │ │ ├── clocks │ │ ├── clocks.txt │ │ └── ti-am335x-prcm.txt │ │ ├── dma │ │ ├── dma-stm32f4.txt │ │ └── dma.txt │ │ ├── gpio │ │ ├── gpio-prop.txt │ │ └── gpio-stm32f4.txt │ │ ├── i2c │ │ ├── i2c-bus.txt │ │ └── i2c-stm32f4.txt │ │ ├── mpu6000.txt │ │ ├── spi │ │ ├── spi-bus.txt │ │ └── spi-stm32f4.txt │ │ └── uart │ │ └── uart-stm32f4.txt ├── stm32f4.md └── tivac.md ├── f4os.mk ├── include ├── atomic.h ├── compiler.h ├── dev │ ├── accel.h │ ├── arch.h │ ├── baro.h │ ├── buf_stream.h │ ├── char.h │ ├── clocks.h │ ├── device.h │ ├── fdtparse.h │ ├── gyro.h │ ├── hw │ │ ├── adc.h │ │ ├── gpio.h │ │ ├── i2c.h │ │ ├── led.h │ │ ├── perfcounter.h │ │ ├── pwm.h │ │ ├── spi.h │ │ ├── systick.h │ │ ├── uart.h │ │ ├── usart.h │ │ └── usbdev.h │ ├── mag.h │ ├── mpu6000 │ │ └── class.h │ ├── raw_mem.h │ ├── resource.h │ ├── rotary_encoder.h │ ├── sensors.h │ ├── shared_deq.h │ └── shared_mem.h ├── fdt.h ├── float.h ├── kernel │ ├── class.h │ ├── collection.h │ ├── fault.h │ ├── init.h │ ├── mutex.h │ ├── obj.h │ ├── power.h │ ├── reentrant_mutex.h │ ├── sched.h │ ├── sched_internals.h │ ├── svc.h │ └── system.h ├── libfdt.h ├── libfdt_env.h ├── limits.h ├── linker_array.h ├── list.h ├── math.h ├── mm │ └── mm.h ├── stdarg.h ├── stddef.h ├── stdint.h ├── stdio.h ├── stdlib.h ├── string.h └── time.h ├── kernel ├── Kconfig ├── Makefile ├── class.c ├── collection.c ├── fault.c ├── init.c ├── mutex.c ├── reentrant_mutex.c ├── sched │ ├── Makefile │ ├── kernel_task.c │ ├── sched_api.c │ ├── sched_end.c │ ├── sched_generic.c │ ├── sched_internals.h │ ├── sched_interrupts.c │ ├── sched_new.c │ ├── sched_start.c │ └── sched_switch.c └── system.c ├── lib ├── Makefile ├── libfdt │ ├── Makefile │ ├── fdt.c │ ├── fdt_empty_tree.c │ ├── fdt_ro.c │ ├── fdt_rw.c │ ├── fdt_strerror.c │ ├── fdt_sw.c │ ├── fdt_wip.c │ └── libfdt_internal.h ├── math │ ├── Makefile │ ├── math_other.c │ ├── math_pow.c │ └── newlib │ │ ├── LICENSE │ │ ├── Makefile │ │ ├── math_atangent.c │ │ ├── math_newlib.c │ │ ├── math_sine.c │ │ └── math_tangent.c ├── stdio.c ├── stdlib.c ├── string.c └── time.c ├── mm ├── Kconfig ├── Makefile ├── bitfield_mm_free.c ├── bitfield_mm_init.c ├── bitfield_mm_internals.h ├── bitfield_mm_malloc.c ├── bitfield_mm_space.c ├── buddy_mm_free.c ├── buddy_mm_init.c ├── buddy_mm_internals.h ├── buddy_mm_malloc.c ├── buddy_mm_space.c ├── mpu.c └── mpu.h ├── tools ├── build.mk ├── build_kconfig.sh ├── build_memory.sh ├── common.mk ├── device_tree.S ├── gdb │ ├── fpu_regs.py │ ├── null_curr_task.py │ ├── print_buddy.py │ └── print_list.py └── submake.mk └── usr ├── Makefile ├── shell ├── Makefile ├── accel.c ├── adc.c ├── app.h ├── baro.c ├── blink.c ├── char_dev.c ├── char_dev.h ├── device_lookup.c ├── device_lookup.h ├── getchar.c ├── gyro.c ├── ipctest.c ├── list_test.c ├── mag.c ├── main.c ├── mem_perf.c ├── pwm.c ├── rd_test.c ├── rotary_encoder.c ├── shared_deq_test.c ├── shell.c ├── shell.h ├── system_ctl.c ├── top.c ├── uart.c └── uname.c └── tests ├── Makefile ├── buf_stream.c ├── cooperate.c ├── init.c ├── main.c ├── mm.c ├── mutex.c ├── regression.c ├── shared_mem.c ├── stdlib.c ├── string.c ├── task_creation.c └── test.h /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.i 3 | *.s 4 | *.P 5 | *.elf 6 | *.bin 7 | *.hex 8 | *.swp 9 | *.fuse* 10 | *.pyc 11 | *.swo 12 | *.out 13 | *.log 14 | *.old 15 | .config* 16 | include/config 17 | tools/kconfig-frontends 18 | out/ 19 | tags 20 | core 21 | -------------------------------------------------------------------------------- /Kconfig: -------------------------------------------------------------------------------- 1 | mainmenu "F4OS Configuration" 2 | 3 | source arch/Kconfig 4 | 5 | menu "Drivers" 6 | source dev/Kconfig 7 | endmenu 8 | 9 | menu "Memory management" 10 | source mm/Kconfig 11 | endmenu 12 | 13 | menu "Kernel" 14 | source kernel/Kconfig 15 | endmenu 16 | 17 | config DEVICE_TREE 18 | string 19 | prompt "Device Tree Source File" 20 | ---help--- 21 | Source device tree file to be built into the OS for runtime 22 | configuration. This option should be a path to a device tree 23 | source file, relative to the root OS directory. 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The following copyright notice applies to all files included in F4OS, 2 | unless otherwise specified in the header or by a directory LICENSE or 3 | COPYING file. A full list of authors can be found in the commit logs. 4 | You can retrieve a list of all authors with 5 | `git log --format='%aN <%aE>' | sort -u`. 6 | 7 | -------------------------------------------------------------------------------- 8 | 9 | Copyright (C) 2013 F4OS Authors 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy of 12 | this software and associated documentation files (the "Software"), to deal in 13 | the Software without restriction, including without limitation the rights to 14 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 15 | of the Software, and to permit persons to whom the Software is furnished to do 16 | so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in all 19 | copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 27 | SOFTWARE. 28 | -------------------------------------------------------------------------------- /STYLE: -------------------------------------------------------------------------------- 1 | * Indentation is in the 1TBS variant of K&R style, with the execption that functions have their opening brace on the same line as the function declaration. 2 | * There should be a space before an opening brace 3 | * http://en.wikipedia.org/wiki/Indent_style#Variant:_1TBS 4 | * Example: 5 | 6 | int main(int argc, char *argv[]) { 7 | ... 8 | while (x == y) { 9 | something(); 10 | somethingelse(); 11 | 12 | if (some_error) { 13 | do_correct(); 14 | } 15 | else { 16 | continue_as_usual(); 17 | } 18 | } 19 | 20 | finalthing(); 21 | ... 22 | } 23 | 24 | * Macros are in ALL_CAPS 25 | * The preferred naming convention is lower_case_with_userscores 26 | * Caps are fine if referencing something uppercase, like a register 27 | * Dereferences go with variable name, not type (char *name) 28 | -------------------------------------------------------------------------------- /arch/Kconfig: -------------------------------------------------------------------------------- 1 | menu "Arch" 2 | 3 | choice 4 | prompt "Architecture" 5 | default ARCH_ARMV7M 6 | 7 | config ARCH_ARMV7M 8 | bool "armv7m" 9 | ---help--- 10 | ARMv7-M microcontroller profile 11 | 12 | config ARCH_ARMV7A 13 | bool "armv7a" 14 | ---help--- 15 | ARMv7-A profile 16 | 17 | endchoice 18 | 19 | config ARCH 20 | string 21 | default "armv7m" if ARCH_ARMV7M 22 | default "armv7a" if ARCH_ARMV7A 23 | 24 | if ARCH_ARMV7M 25 | source arch/armv7m/Kconfig 26 | endif 27 | 28 | if ARCH_ARMV7A 29 | source arch/armv7a/Kconfig 30 | endif 31 | 32 | endmenu 33 | -------------------------------------------------------------------------------- /arch/Makefile: -------------------------------------------------------------------------------- 1 | DIRS := $(CONFIG_ARCH)/ 2 | 3 | include $(BASE)/tools/submake.mk 4 | -------------------------------------------------------------------------------- /arch/armv7a/Makefile: -------------------------------------------------------------------------------- 1 | SRCS += arch.c 2 | SRCS += power.S 3 | SRCS += start.S 4 | SRCS += exception_handlers.c 5 | 6 | DIRS += chip/ 7 | DIRS += kernel/ 8 | 9 | include $(BASE)/tools/submake.mk 10 | -------------------------------------------------------------------------------- /arch/armv7a/arch.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | void init_arch(void) { 29 | init_chip(); 30 | } 31 | 32 | void arch_sched_start_system_tick(void) { 33 | /* 34 | * There is no universal timer for system ticks, 35 | * the chip will take care of things. 36 | */ 37 | chip_sched_start_system_tick(); 38 | } 39 | -------------------------------------------------------------------------------- /arch/armv7a/chip/Kconfig: -------------------------------------------------------------------------------- 1 | # Chip selection configuration 2 | 3 | choice 4 | prompt "Chip to target" 5 | default CHIP_AM335X 6 | 7 | config CHIP_AM335X 8 | bool "am335x" 9 | ---help--- 10 | TI Sitara series AM335x Cortex-A8 11 | 12 | endchoice 13 | 14 | config CHIP 15 | string 16 | default "am335x" if CHIP_AM335X 17 | 18 | if CHIP_AM335X 19 | source arch/armv7a/chip/am335x/Kconfig 20 | endif 21 | -------------------------------------------------------------------------------- /arch/armv7a/chip/Makefile: -------------------------------------------------------------------------------- 1 | DIRS += $(CONFIG_CHIP)/ 2 | 3 | include $(BASE)/tools/submake.mk 4 | -------------------------------------------------------------------------------- /arch/armv7a/chip/am335x/Kconfig: -------------------------------------------------------------------------------- 1 | menu "Clocks" 2 | 3 | config AM335X_REFERENCE_CLOCK 4 | int 5 | prompt "Reference clock speed (Hz)" 6 | default 24000000 7 | ---help--- 8 | This is the reference clock (crystal) on the board. 9 | All clocks in the system are referenced from this clock. 10 | 11 | config AM335X_DEFAULT_SYSTEM_CLOCK 12 | int 13 | prompt "Default system clock speed (MHz)" 14 | default 200 15 | ---help--- 16 | This is the default clock speed of the core. It may be 17 | modified by power management. 18 | 19 | endmenu 20 | -------------------------------------------------------------------------------- /arch/armv7a/chip/am335x/Makefile: -------------------------------------------------------------------------------- 1 | SRCS += chip.c 2 | SRCS += clocks.c 3 | SRCS += interrupts.c 4 | SRCS += prcm.c 5 | SRCS += timer.c 6 | 7 | SRCS_$(CONFIG_HAVE_USART) += usart.c 8 | 9 | binary: $(PREFIX)/MLO 10 | 11 | $(PREFIX)/MLO: $(PREFIX)/$(PROJ_NAME).bin 12 | $(call print_command,"MKIMAGE",$(call relative_path,$@)) 13 | $(VERBOSE)mkimage -T omapimage -a 402f0400 -d $< $@ 14 | 15 | include $(BASE)/tools/submake.mk 16 | -------------------------------------------------------------------------------- /arch/armv7a/chip/am335x/chip.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include "clocks.h" 25 | #include "timer.h" 26 | 27 | void init_chip(void) { 28 | am335x_clock_config(); 29 | } 30 | 31 | void chip_sched_start_system_tick(void) { 32 | /* Use DMTimer 1ms to handle system ticks */ 33 | am335x_dmtimer1ms_init_systick(); 34 | } 35 | -------------------------------------------------------------------------------- /arch/armv7a/chip/am335x/config.mk: -------------------------------------------------------------------------------- 1 | CFLAGS += -mcpu=cortex-a8 2 | CFLAGS += -mfloat-abi=hard # Use FPU and hard float point calling conventions 3 | CFLAGS += -mfpu=vfpv3-d16 # VFPv3 FPU 4 | 5 | # Cortex-A8 does not have a division instruction, use libgcc 6 | LFLAGS += -lgcc 7 | -------------------------------------------------------------------------------- /arch/armv7a/config.mk: -------------------------------------------------------------------------------- 1 | # Include chip-specific config 2 | include $(BASE)/arch/$(CONFIG_ARCH)/chip/$(CONFIG_CHIP)/config.mk 3 | 4 | CROSS_COMPILE ?= arm-none-eabi- 5 | 6 | CFLAGS += -march=armv7-a 7 | -------------------------------------------------------------------------------- /arch/armv7a/exception_handlers.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | 25 | void data_abort(void) { 26 | panic_print("Data abort!"); 27 | } 28 | 29 | void prefetch_abort(void) { 30 | panic_print("Prefetch abort!"); 31 | } 32 | 33 | void undefined_instruction(void) { 34 | panic_print("Undefined instruction!"); 35 | } 36 | -------------------------------------------------------------------------------- /arch/armv7a/include/chip.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #ifndef ARCH_CHIP_H_INCLUDED 24 | #define ARCH_CHIP_H_INCLUDED 25 | 26 | /* 27 | * Perform core chip setup 28 | * 29 | * Called extremely early in boot. This should perform core essential 30 | * chip setup, before anything else is run. Most notably, this includes 31 | * core clock setup. 32 | */ 33 | void init_chip(void) __attribute__((section(".kernel"))); 34 | 35 | /* 36 | * Handle IRQ 37 | * 38 | * Called when an IRQ interrupt is raised. Should determine the IRQ 39 | * source, and handle it appropriately. System state is saved before 40 | * calling this function, and restored when it returns. 41 | */ 42 | void irq_handler(void) __attribute__((section(".kernel"))); 43 | 44 | /* 45 | * Handle FIQ 46 | * 47 | * Called when an FIQ interrupt is raised. Should determine the FIQ 48 | * source, and handle it appropriately. System state is saved before 49 | * calling this function, and restored when it returns. 50 | */ 51 | void fiq_handler(void) __attribute__((section(".kernel"))); 52 | 53 | /** 54 | * Enable chip system tick timer 55 | * 56 | * Enable system tick timer, as described by the docs for 57 | * arch_sched_start_system_tick() in include/kernel/sched_internals.h. 58 | */ 59 | void chip_sched_start_system_tick(void); 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /arch/armv7a/include/system_regs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #ifndef ARCH_SYSTEM_REGS_H_INCLUDED 24 | #define ARCH_SYSTEM_REGS_H_INCLUDED 25 | 26 | #define CPSR_MODE (0x1f) /* CPSR processor mode mask */ 27 | #define CPSR_MODE_USR (0x10) /* User mode */ 28 | #define CPSR_MODE_FIQ (0x11) /* FIQ mode */ 29 | #define CPSR_MODE_IRQ (0x12) /* IRQ mode */ 30 | #define CPSR_MODE_SVC (0x13) /* SVC mode */ 31 | #define CPSR_MODE_MON (0x16) /* Monitor mode */ 32 | #define CPSR_MODE_ABT (0x17) /* Abort mode */ 33 | #define CPSR_MODE_HYP (0x1A) /* Hypervisor mode */ 34 | #define CPSR_MODE_UND (0x1B) /* Undefined mode */ 35 | #define CPSR_MODE_SYS (0x1F) /* System mode */ 36 | 37 | #define CPSR_THUMB (0x20) /* Thumb execution state */ 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /arch/armv7a/kernel/Makefile: -------------------------------------------------------------------------------- 1 | SRCS += sched.c 2 | SRCS += sched_asm.S 3 | SRCS += svc.c 4 | 5 | include $(BASE)/tools/submake.mk 6 | -------------------------------------------------------------------------------- /arch/armv7a/kernel/sched_asm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #ifndef ARCH_ARMV7A_KERNEL_SCHED_ASM_H_INCLUDED 24 | #define ARCH_ARMV7A_KERNEL_SCHED_ASM_H_INCLUDED 25 | 26 | struct stacked_registers { 27 | uint32_t cpsr; 28 | uint32_t r0; 29 | uint32_t r1; 30 | uint32_t r2; 31 | uint32_t r3; 32 | uint32_t r4; 33 | uint32_t r5; 34 | uint32_t r6; 35 | uint32_t r7; 36 | uint32_t r8; 37 | uint32_t r9; 38 | uint32_t r10; 39 | uint32_t r11; 40 | uint32_t r12; 41 | uint32_t pc; /* Address of instruction following SVC */ 42 | }; 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /arch/armv7a/power.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | 25 | int arch_wait_for_interrupt(void) { 26 | asm("wfe\n"); 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /arch/armv7m/Kconfig: -------------------------------------------------------------------------------- 1 | menu "Chip" 2 | source arch/armv7m/chip/Kconfig 3 | endmenu 4 | 5 | menu "Memory layout" 6 | 7 | config VECTOR_VMA_REGION 8 | string "VMA region for .vector section" 9 | default "flash" 10 | 11 | config VECTOR_LMA_REGION 12 | string "LMA region for .vector section" 13 | default VECTOR_VMA_REGION 14 | 15 | config KERNEL_VMA_REGION 16 | string "VMA region for .kernel section" 17 | default "flash" 18 | 19 | config KERNEL_LMA_REGION 20 | string "LMA region for .kernel section" 21 | default KERNEL_VMA_REGION 22 | 23 | config TEXT_VMA_REGION 24 | string "VMA region for .text section" 25 | default "flash" 26 | 27 | config TEXT_LMA_REGION 28 | string "LMA region for .text section" 29 | default TEXT_VMA_REGION 30 | 31 | config RODATA_VMA_REGION 32 | string "VMA region for .rodata section" 33 | default "flash" 34 | 35 | config RODATA_LMA_REGION 36 | string "LMA region for .rodata section" 37 | default RODATA_VMA_REGION 38 | 39 | config LINKER_ARRAY_VMA_REGION 40 | string "VMA region for .linker_array section" 41 | default "flash" 42 | 43 | config LINKER_ARRAY_LMA_REGION 44 | string "LMA region for .linker_array section" 45 | default LINKER_ARRAY_VMA_REGION 46 | 47 | config DTB_VMA_REGION 48 | string "VMA region for .dtb section" 49 | default "flash" 50 | 51 | config DTB_LMA_REGION 52 | string "LMA region for .dtb section" 53 | default DTB_VMA_REGION 54 | 55 | config DATA_VMA_REGION 56 | string "VMA region for .data section" 57 | default "ram" 58 | 59 | config DATA_LMA_REGION 60 | string "LMA region for .data section" 61 | default "flash" 62 | 63 | config BSS_VMA_REGION 64 | string "VMA region for .bss section" 65 | default "ram" 66 | 67 | config BSS_LMA_REGION 68 | string "LMA region for .bss section" 69 | default "flash" 70 | 71 | endmenu 72 | 73 | config INITIAL_SP 74 | hex "Initial SP value" 75 | -------------------------------------------------------------------------------- /arch/armv7m/Makefile: -------------------------------------------------------------------------------- 1 | SRCS += arch.c 2 | SRCS += fault.c 3 | SRCS += handlers.S 4 | SRCS += math.c 5 | SRCS += power.c 6 | 7 | DIRS += chip/ 8 | DIRS += dev/ 9 | DIRS += kernel/ 10 | 11 | include $(BASE)/tools/submake.mk 12 | -------------------------------------------------------------------------------- /arch/armv7m/arch.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | /* Set up universal Cortex M perihperals/system settings */ 30 | void init_arch(void) { 31 | /* Setup chip clocks */ 32 | init_clock(); 33 | 34 | /* Send event on pending interrupt */ 35 | *SCB_SCR |= SCB_SCR_SEVONPEND; 36 | 37 | /* Enable Bus and Usage Faults */ 38 | *SCB_SHCSR |= SCB_SHCSR_BUSFAULTENA | SCB_SHCSR_USEFAULTENA; 39 | 40 | #ifdef CONFIG_HAVE_FPU 41 | /* Enable the FPU */ 42 | *SCB_CPACR |= SCB_CPACR_CP10_FULL | SCB_CPACR_CP11_FULL; 43 | 44 | /* Enable floating point extension, and thus state preservation */ 45 | asm volatile ("mrs r0, control \t\n" 46 | "orr r0, %[fpca] \t\n" 47 | "msr control, r0 \t\n" 48 | :: [fpca] "I" (CONTROL_FPCA) 49 | : "r0"); 50 | #endif 51 | } 52 | 53 | void arch_sched_start_system_tick(void) { 54 | /* The SysTick timer handles system ticks */ 55 | init_systick(); 56 | } 57 | -------------------------------------------------------------------------------- /arch/armv7m/chip/Kconfig: -------------------------------------------------------------------------------- 1 | # Chip selection configuration 2 | 3 | choice 4 | prompt "Chip to target" 5 | default CHIP_STM32F40X 6 | 7 | config CHIP_STM32F40X 8 | bool "stm32f40x" 9 | ---help--- 10 | ST Microelectronics STM32F40x line of Cortex M4Fs. 11 | 12 | config CHIP_LM4F120H5 13 | bool "lm4f120h5" 14 | ---help--- 15 | Texas Instruments LM4F120H5 Cortex M4F. 16 | 17 | config CHIP_MSP432P401X 18 | bool "msp432p401x" 19 | ---help--- 20 | Texas Instruments MSP432P401x line of Cortex M4Fs. 21 | 22 | endchoice 23 | 24 | config CHIP 25 | string 26 | default "stm32f40x" if CHIP_STM32F40X 27 | default "lm4f120h5" if CHIP_LM4F120H5 28 | default "msp432p401x" if CHIP_MSP432P401X 29 | 30 | config HAVE_FPU 31 | bool 32 | prompt "FPU Support" 33 | default y 34 | ---help--- 35 | Enable support for ARMv7-M floating point extensions. 36 | 37 | Without this option enabled, executing floating point instructions 38 | will result in a usage fault. 39 | 40 | libgcc should be linked in to provide software floating point 41 | arithmetic routines. 42 | 43 | config SHORT_DOUBLE 44 | bool 45 | prompt "Use short doubles" 46 | default y if HAVE_FPU 47 | ---help--- 48 | Build with '-fshort-double'. 49 | 50 | This will make everything of the double type equivalent in size to 51 | that of the float type. That means that doubles will only be single 52 | precision floating point values. This is particularly useful for 53 | chips that contain only a single precision floating point unit, to 54 | ensure that the FPU is actually used for floating point arithmetic. 55 | 56 | Chips with an FPU that have not enabled this option will require libgcc 57 | to provide software routines for double precision floating point 58 | arithmetic. 59 | 60 | config SYS_CLOCK 61 | int 62 | prompt "System clock speed" 63 | default 168000000 if CHIP_STM32F40X 64 | default 84000000 if CHIP_LM4F120H5 65 | default 48000000 if CHIP_MSP432P401X 66 | ---help--- 67 | Note: This must be set to the value configured by the chip clock function 68 | 69 | if CHIP_STM32F40X 70 | source arch/armv7m/chip/stm32f40x/Kconfig 71 | endif 72 | 73 | if CHIP_LM4F120H5 74 | source arch/armv7m/chip/lm4f120h5/Kconfig 75 | endif 76 | 77 | if CHIP_MSP432P401X 78 | source arch/armv7m/chip/msp432p401x/Kconfig 79 | endif 80 | -------------------------------------------------------------------------------- /arch/armv7m/chip/Makefile: -------------------------------------------------------------------------------- 1 | DIRS := $(CONFIG_CHIP)/ 2 | 3 | include $(BASE)/tools/submake.mk 4 | -------------------------------------------------------------------------------- /arch/armv7m/chip/cortex-m4f.mk: -------------------------------------------------------------------------------- 1 | # Cortex-M4F has a single precision floating point unit 2 | 3 | CFLAGS += -mcpu=cortex-m4 4 | 5 | ifeq ($(CONFIG_HAVE_FPU),y) 6 | CFLAGS += -mfloat-abi=hard # Use FPU and hard float point calling conventions 7 | CFLAGS += -mfpu=fpv4-sp-d16 # Core contains an FPv4-SP-D16 FPU 8 | else 9 | CFLAGS += -lgcc # libgcc to provide floating point routines 10 | endif 11 | 12 | ifeq ($(CONFIG_SHORT_DOUBLE),y) 13 | CFLAGS += -fsingle-precision-constant # Contants are floats, not doubles 14 | CFLAGS += -fshort-double # Treat doubles as 32-bit floats 15 | else 16 | CFLAGS += -lgcc # libgcc to provide double precision floating point routines 17 | endif 18 | -------------------------------------------------------------------------------- /arch/armv7m/chip/lm4f120h5/Kconfig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prattmic/F4OS/43e067e2108356c9a84f9b8362384143ba7f3f3f/arch/armv7m/chip/lm4f120h5/Kconfig -------------------------------------------------------------------------------- /arch/armv7m/chip/lm4f120h5/Makefile: -------------------------------------------------------------------------------- 1 | SRCS += vector.S 2 | SRCS += clock.c 3 | SRCS += gpio.c 4 | 5 | DIRS += boards/ 6 | DIRS += dev/ 7 | 8 | binary: $(PREFIX)/$(PROJ_NAME).bin 9 | 10 | # Define burn target for flashing chip 11 | burn: 12 | ./flash.sh $(PREFIX)/$(PROJ_NAME).bin 13 | 14 | include $(BASE)/tools/submake.mk 15 | -------------------------------------------------------------------------------- /arch/armv7m/chip/lm4f120h5/boards/Makefile: -------------------------------------------------------------------------------- 1 | SRCS += launchpad.c 2 | 3 | include $(BASE)/tools/submake.mk 4 | -------------------------------------------------------------------------------- /arch/armv7m/chip/lm4f120h5/boards/launchpad.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | 26 | /* GPIO LEDs available */ 27 | const struct led leds_avail[] = {{LM4F_GPIO_PF1, 0}, {LM4F_GPIO_PF2, 0}, 28 | {LM4F_GPIO_PF3, 0}}; 29 | 30 | const int num_leds = sizeof(leds_avail)/sizeof(leds_avail[0]); 31 | -------------------------------------------------------------------------------- /arch/armv7m/chip/lm4f120h5/clock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include "sysctl.h" 27 | 28 | void init_clock(void) { 29 | ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); 30 | } 31 | -------------------------------------------------------------------------------- /arch/armv7m/chip/lm4f120h5/config.mk: -------------------------------------------------------------------------------- 1 | # Core is a Cortex-M4F 2 | include $(BASE)/arch/$(CONFIG_ARCH)/chip/cortex-m4f.mk 3 | -------------------------------------------------------------------------------- /arch/armv7m/chip/lm4f120h5/dev/Makefile: -------------------------------------------------------------------------------- 1 | DIRS += hw/ 2 | 3 | include $(BASE)/tools/submake.mk 4 | -------------------------------------------------------------------------------- /arch/armv7m/chip/lm4f120h5/dev/hw/Makefile: -------------------------------------------------------------------------------- 1 | SRCS_$(CONFIG_HAVE_USART) += usart.c 2 | 3 | include $(BASE)/tools/submake.mk 4 | -------------------------------------------------------------------------------- /arch/armv7m/chip/lm4f120h5/flash.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ ! -n "$1" ] 4 | then 5 | echo "Usage: $0 object.bin" 6 | exit $E_BADARGS 7 | fi 8 | 9 | commands="speed 12000 10 | exec device = lm4f120h5qr 11 | loadbin $1,0x00000000 12 | r 13 | g 14 | q" 15 | 16 | echo "$commands" | JLinkExe 17 | -------------------------------------------------------------------------------- /arch/armv7m/chip/msp432p401x/Kconfig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prattmic/F4OS/43e067e2108356c9a84f9b8362384143ba7f3f3f/arch/armv7m/chip/msp432p401x/Kconfig -------------------------------------------------------------------------------- /arch/armv7m/chip/msp432p401x/Makefile: -------------------------------------------------------------------------------- 1 | SRCS += vector.S 2 | SRCS += clock.c 3 | 4 | binary: $(PREFIX)/$(PROJ_NAME).bin 5 | 6 | # TODO: support multiple interfaces 7 | burn: 8 | openocd -f interface/jlink.cfg \ 9 | -c "transport select jtag" \ 10 | -f target/msp432p401r.cfg \ 11 | -c "msp432p4 init 0" \ 12 | -c "msp432p4 mass_erase 0" \ 13 | -c "msp432p4 init 0" \ 14 | -c "flash write_image $(PREFIX)/$(PROJ_NAME).bin" \ 15 | -c "reset run" \ 16 | -c "exit" || true # OpenOCD returns 1? 17 | 18 | include $(BASE)/tools/submake.mk 19 | -------------------------------------------------------------------------------- /arch/armv7m/chip/msp432p401x/clock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | /* TODO: move to dedicated file */ 28 | #define WDTCTL ((uint16_t *)0x4000480C) 29 | #define WDTCTL_PW (0x5A << 8) 30 | #define WDTCTL_HOLD (1 << 7) 31 | 32 | void init_clock(void) { 33 | /* Disable watchdog timer */ 34 | raw_mem_write(WDTCTL, WDTCTL_PW | WDTCTL_HOLD); 35 | 36 | /* TODO */ 37 | } 38 | -------------------------------------------------------------------------------- /arch/armv7m/chip/msp432p401x/config.mk: -------------------------------------------------------------------------------- 1 | # Core is a Cortex-M4F 2 | include $(BASE)/arch/$(CONFIG_ARCH)/chip/cortex-m4f.mk 3 | -------------------------------------------------------------------------------- /arch/armv7m/chip/msp432p401x/include/rom.h: -------------------------------------------------------------------------------- 1 | /* TODO: prototypes for ROM-library functions */ 2 | -------------------------------------------------------------------------------- /arch/armv7m/chip/stm32f40x/Kconfig: -------------------------------------------------------------------------------- 1 | config STM32_OSC_FREQ 2 | int 3 | default 8 4 | prompt "STM32 external crystal frequency" 5 | ---help--- 6 | The oscillator frequency is important for configuring the system 7 | clock to 168MHz. If set incorrectly, the chip may not boot properly. 8 | 9 | choice 10 | prompt "Target board" 11 | default STM32_BOARD_STM32F4DISCOVERY 12 | 13 | config STM32_BOARD_STM32F4DISCOVERY 14 | bool 15 | prompt "STM32F407 Discovery Board" 16 | 17 | config STM32_BOARD_32F401CDISCOVERY 18 | bool 19 | prompt "STM32F401 Discovery Board" 20 | 21 | config STM32_BOARD_PX4 22 | bool 23 | prompt "PX4 Autopilot" 24 | endchoice 25 | 26 | config STM32_BOARD 27 | string 28 | default "stm32f4discovery" if STM32_BOARD_STM32F4DISCOVERY 29 | default "32f401cdiscovery" if STM32_BOARD_32F401CDISCOVERY 30 | default "px4" if STM32_BOARD_PX4 31 | 32 | config PERFCOUNTER 33 | bool 34 | default y 35 | -------------------------------------------------------------------------------- /arch/armv7m/chip/stm32f40x/Makefile: -------------------------------------------------------------------------------- 1 | SRCS += vector.S 2 | SRCS += clock.c 3 | SRCS += dma.c 4 | SRCS += gpio.c 5 | SRCS += rcc.c 6 | 7 | SRCS_$(CONFIG_ADC_CLASS) += adc.c 8 | SRCS_$(CONFIG_PWM_CLASS) += pwm.c 9 | SRCS_$(CONFIG_UART_CLASS) += uart.c 10 | 11 | DIRS += boards/ 12 | DIRS += dev/ 13 | 14 | binary: $(PREFIX)/$(PROJ_NAME).bin 15 | 16 | # Define burn target for flashing chip 17 | burn: 18 | ./flash.sh $(CONFIG_STM32_BOARD) $(PREFIX)/$(PROJ_NAME).bin 19 | 20 | include $(BASE)/tools/submake.mk 21 | -------------------------------------------------------------------------------- /arch/armv7m/chip/stm32f40x/boards/Makefile: -------------------------------------------------------------------------------- 1 | SRCS_$(CONFIG_STM32_BOARD_STM32F4DISCOVERY) += discovery.c 2 | SRCS_$(CONFIG_STM32_BOARD_32F401CDISCOVERY) += discovery.c 3 | SRCS_$(CONFIG_STM32_BOARD_PX4) += px4.c 4 | 5 | include $(BASE)/tools/submake.mk 6 | -------------------------------------------------------------------------------- /arch/armv7m/chip/stm32f40x/boards/discovery.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | 26 | /* GPIO LEDs available - Red, Green, Orange, Blue */ 27 | const struct led leds_avail[] = {{STM32F4_GPIO_PD14, 0}, {STM32F4_GPIO_PD12, 0}, 28 | {STM32F4_GPIO_PD13, 0}, {STM32F4_GPIO_PD15, 0}}; 29 | 30 | const int num_leds = sizeof(leds_avail)/sizeof(leds_avail[0]); 31 | -------------------------------------------------------------------------------- /arch/armv7m/chip/stm32f40x/boards/px4.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | 26 | /* GPIO LEDs available - Red, Blue */ 27 | const struct led leds_avail[] = {{STM32F4_GPIO_PB14, 0}, {STM32F4_GPIO_PB15, 0}}; 28 | 29 | const int num_leds = sizeof(leds_avail)/sizeof(leds_avail[0]); 30 | -------------------------------------------------------------------------------- /arch/armv7m/chip/stm32f40x/config.mk: -------------------------------------------------------------------------------- 1 | # Core is a Cortex-M4F 2 | include $(BASE)/arch/$(CONFIG_ARCH)/chip/cortex-m4f.mk 3 | -------------------------------------------------------------------------------- /arch/armv7m/chip/stm32f40x/dev/Makefile: -------------------------------------------------------------------------------- 1 | DIRS += hw/ 2 | 3 | include $(BASE)/tools/submake.mk 4 | -------------------------------------------------------------------------------- /arch/armv7m/chip/stm32f40x/dev/hw/Makefile: -------------------------------------------------------------------------------- 1 | SRCS_$(CONFIG_HAVE_I2C) += i2c.c 2 | SRCS_$(CONFIG_HAVE_SPI) += spi.c 3 | SRCS_$(CONFIG_PERFCOUNTER) += perfcounter.c 4 | 5 | DIRS_$(CONFIG_HAVE_USBDEV) += usb/ 6 | 7 | include $(BASE)/tools/submake.mk 8 | -------------------------------------------------------------------------------- /arch/armv7m/chip/stm32f40x/dev/hw/usb/Makefile: -------------------------------------------------------------------------------- 1 | SRCS += usbdev_cdc.c 2 | SRCS += usbdev_char.c 3 | SRCS += usbdev_core.c 4 | SRCS += usbdev_desc.c 5 | SRCS += usbdev_init.c 6 | SRCS += usbdev_int.c 7 | 8 | include $(BASE)/tools/submake.mk 9 | -------------------------------------------------------------------------------- /arch/armv7m/chip/stm32f40x/dev/hw/usb/usbdev_class.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #ifndef DEV_HW_USB_USBDEV_CLASS_H_INCLUDED 24 | #define DEV_HW_USB_USBDEV_CLASS_H_INCLUDED 25 | 26 | void usbdev_setup(struct ring_buffer *ring, uint32_t len); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /arch/armv7m/chip/stm32f40x/flash.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ ! -n "$2" ] 4 | then 5 | echo "Usage: $0 board object.bin" 6 | exit $E_BADARGS 7 | fi 8 | 9 | if [ "$1" == "stm32f4discovery" ] || [ "$1" == "32f401cdiscovery" ] 10 | then 11 | st-flash write $2 0x8000000 12 | exit 0 13 | elif [ "$1" == "px4" ] 14 | then 15 | commands="speed 12000 16 | exec device = stm32f405vg 17 | erase 18 | loadbin $2,0x08000000 19 | r 20 | g 21 | q" 22 | 23 | echo "$commands" | JLinkExe 24 | else 25 | echo "Unknown board $BOARD" 26 | exit $E_BADARGS 27 | fi 28 | -------------------------------------------------------------------------------- /arch/armv7m/chip/stm32f40x/include/clock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #ifndef ARCH_CHIP_CLOCK_H_INCLUDED 24 | #define ARCH_CHIP_CLOCK_H_INCLUDED 25 | 26 | #define SYS_CLOCK CONFIG_SYS_CLOCK 27 | #define APB1_CLOCK (SYS_CLOCK/4) 28 | #define APB2_CLOCK (SYS_CLOCK/2) 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /arch/armv7m/config.mk: -------------------------------------------------------------------------------- 1 | # Include chip-specific config 2 | include $(BASE)/arch/$(CONFIG_ARCH)/chip/$(CONFIG_CHIP)/config.mk 3 | 4 | CROSS_COMPILE ?= arm-none-eabi- 5 | 6 | CFLAGS += -mthumb # ARMv7-M supports Thumb and Thumb2 only 7 | -------------------------------------------------------------------------------- /arch/armv7m/dev/Makefile: -------------------------------------------------------------------------------- 1 | DIRS += hw/ 2 | 3 | include $(BASE)/tools/submake.mk 4 | -------------------------------------------------------------------------------- /arch/armv7m/dev/hw/Makefile: -------------------------------------------------------------------------------- 1 | SRCS += systick.c 2 | 3 | include $(BASE)/tools/submake.mk 4 | -------------------------------------------------------------------------------- /arch/armv7m/dev/hw/systick.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | void init_systick(void) { 28 | *SYSTICK_RELOAD = CONFIG_SYS_CLOCK / CONFIG_SYSTICK_FREQ; 29 | *SYSTICK_VAL = 0; 30 | *SYSTICK_CTL = 0x00000007; 31 | 32 | /* Set PendSV and SVC to lowest priority. 33 | * This means that both will be deferred 34 | * until all other exceptions have executed. 35 | * Additionally, PendSV will not interrupt 36 | * an SVC. */ 37 | *NVIC_IPR(11) = 0xFF; 38 | *NVIC_IPR(14) = 0xFF; 39 | } 40 | 41 | -------------------------------------------------------------------------------- /arch/armv7m/include/chip.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #ifndef ARCH_CHIP_H_INCLUDED 24 | #define ARCH_CHIP_H_INCLUDED 25 | 26 | void init_clock() __attribute__((section(".kernel"))); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /arch/armv7m/kernel/Makefile: -------------------------------------------------------------------------------- 1 | SRCS += sched_asm.S 2 | SRCS += sched.c 3 | SRCS += svc.c 4 | 5 | include $(BASE)/tools/submake.mk 6 | -------------------------------------------------------------------------------- /arch/armv7m/kernel/sched.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #ifndef ARCH_ARMV7M_KERNEL_SCHED_H_INCLUDED 24 | #define ARCH_ARMV7M_KERNEL_SCHED_H_INCLUDED 25 | 26 | /* ASM functions */ 27 | extern void enable_psp(); 28 | extern void disable_psp(); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /arch/armv7m/kernel/svc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013, 2014 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | void svc_handler(uint32_t*) __attribute__((section(".kernel"))); 30 | 31 | void svc_handler(uint32_t *registers) { 32 | uint32_t svc_number; 33 | 34 | /* Stack contains: 35 | * r0, r1, r2, r3, r12, r14, the return address and xPSR 36 | * First argument and return value (r0) is registers[0] */ 37 | svc_number = ((char *)registers[6])[-2]; 38 | 39 | switch (svc_number) { 40 | case SVC_YIELD: 41 | case SVC_END_TASK: 42 | case SVC_REGISTER_TASK: 43 | case SVC_TASK_SWITCH: 44 | registers[0] = sched_service_call(svc_number, registers[0], 45 | registers[1]); 46 | break; 47 | case SVC_ACQUIRE: 48 | case SVC_RELEASE: 49 | registers[0] = mutex_service_call(svc_number, registers[0]); 50 | break; 51 | default: 52 | panic_print("Unknown SVC: %d", svc_number); 53 | break; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /arch/armv7m/math.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | 25 | #ifdef CONFIG_HAVE_FPU 26 | float fabsf(float num) { 27 | __asm__("vabs.f32 %[num], %[num] \r\n" 28 | :[num] "+w" (num)::"cc"); 29 | 30 | return num; 31 | } 32 | 33 | float sqrtf(float num) { 34 | __asm__("vsqrt.f32 %[num], %[num] \r\n" 35 | :[num] "+w" (num)::"cc"); 36 | 37 | return num; 38 | } 39 | #endif 40 | -------------------------------------------------------------------------------- /arch/armv7m/power.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | 25 | int arch_wait_for_interrupt(void) { 26 | asm("wfe\n"); 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /configs/32f401cdiscovery.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | /include/ "stm32f4/01xc.dtsi" 3 | 4 | / { 5 | compatible = "stmicro,32f401cdiscovery", "stmicro,stm32f401vc", 6 | "stmicro,stm32f401xc", "stmicro,stm32f401", "stmicro,stm32f4"; 7 | }; 8 | -------------------------------------------------------------------------------- /configs/32f401cdiscovery_defconfig: -------------------------------------------------------------------------------- 1 | # 2 | # Automatically generated file; DO NOT EDIT. 3 | # F4OS Configuration 4 | # 5 | 6 | # 7 | # Arch 8 | # 9 | CONFIG_ARCH_ARMV7M=y 10 | # CONFIG_ARCH_ARMV7A is not set 11 | CONFIG_ARCH="armv7m" 12 | 13 | # 14 | # Chip 15 | # 16 | CONFIG_CHIP_STM32F40X=y 17 | # CONFIG_CHIP_LM4F120H5 is not set 18 | CONFIG_CHIP="stm32f40x" 19 | CONFIG_HAVE_FPU=y 20 | CONFIG_SHORT_DOUBLE=y 21 | CONFIG_SYS_CLOCK=84000000 22 | CONFIG_STM32_OSC_FREQ=8 23 | # CONFIG_STM32_BOARD_STM32F4DISCOVERY is not set 24 | CONFIG_STM32_BOARD_32F401CDISCOVERY=y 25 | # CONFIG_STM32_BOARD_PX4 is not set 26 | CONFIG_STM32_BOARD="32f401cdiscovery" 27 | CONFIG_PERFCOUNTER=y 28 | 29 | # 30 | # Memory layout 31 | # 32 | CONFIG_VECTOR_VMA_REGION="flash" 33 | CONFIG_VECTOR_LMA_REGION="flash" 34 | CONFIG_KERNEL_VMA_REGION="flash" 35 | CONFIG_KERNEL_LMA_REGION="flash" 36 | CONFIG_TEXT_VMA_REGION="flash" 37 | CONFIG_TEXT_LMA_REGION="flash" 38 | CONFIG_RODATA_VMA_REGION="flash" 39 | CONFIG_RODATA_LMA_REGION="flash" 40 | CONFIG_LINKER_ARRAY_VMA_REGION="flash" 41 | CONFIG_LINKER_ARRAY_LMA_REGION="flash" 42 | CONFIG_DTB_VMA_REGION="flash" 43 | CONFIG_DTB_LMA_REGION="flash" 44 | CONFIG_DATA_VMA_REGION="ram" 45 | CONFIG_DATA_LMA_REGION="flash" 46 | CONFIG_BSS_VMA_REGION="ram" 47 | CONFIG_BSS_LMA_REGION="flash" 48 | CONFIG_INITIAL_SP=0x20004000 49 | 50 | # 51 | # Drivers 52 | # 53 | # CONFIG_HAVE_USART is not set 54 | CONFIG_HAVE_I2C=y 55 | CONFIG_HAVE_SPI=y 56 | CONFIG_HAVE_LED=y 57 | CONFIG_HAVE_USBDEV=y 58 | CONFIG_STDOUT_DEV="stm32f4-static-usb" 59 | CONFIG_STDERR_DEV="/uart@40011000" 60 | CONFIG_SYSTICK_FREQ=4000 61 | CONFIG_SHARED_MEM_SIZE=512 62 | CONFIG_ADC_CLASS=y 63 | CONFIG_PWM_CLASS=y 64 | CONFIG_UART_CLASS=y 65 | # CONFIG_MPU6000 is not set 66 | # CONFIG_ACCELEROMETERS is not set 67 | # CONFIG_BAROMETERS is not set 68 | # CONFIG_GYROSCOPES is not set 69 | # CONFIG_MAGNETOMETERS is not set 70 | # CONFIG_ROTARY_ENCODERS is not set 71 | 72 | # 73 | # Memory management 74 | # 75 | CONFIG_MM_ALLOCATOR_BUDDY=y 76 | # CONFIG_MM_ALLOCATOR_BITFIELD is not set 77 | CONFIG_SUSERHEAP=0x20008000 78 | CONFIG_SKERNELHEAP=0x20004000 79 | CONFIG_EUSERHEAP=0x20010000 80 | CONFIG_EKERNELHEAP=0x20008000 81 | CONFIG_MM_USER_MAX_ORDER=15 82 | CONFIG_MM_USER_MIN_ORDER=4 83 | CONFIG_MM_KERNEL_MAX_ORDER=14 84 | CONFIG_MM_KERNEL_MIN_ORDER=4 85 | # CONFIG_MM_PROFILING is not set 86 | 87 | # 88 | # Kernel 89 | # 90 | CONFIG_TASK_STACK_SIZE=255 91 | CONFIG_HELD_MUTEXES_MAX=6 92 | CONFIG_DEVICE_TREE="configs/32f401cdiscovery.dts" 93 | -------------------------------------------------------------------------------- /configs/Makefile.in: -------------------------------------------------------------------------------- 1 | # Create a rule for applying a defconfig 2 | # $(1) = Path to defconfig 3 | define define_defconfig_rule 4 | $(notdir $(1)): $(CONF) clean 5 | $(VERBOSE)$(CONF) $(BASE)/Kconfig --defconfig=$(1) 6 | $(VERBOSE)+$(MAKE) $(KCONFIG_HEADER) 7 | endef 8 | 9 | DEFCONFIG_PATHS := $(wildcard $(BASE)/configs/*_defconfig) 10 | DEFCONFIGS := $(notdir $(DEFCONFIG_PATHS)) 11 | 12 | # Define a rule for each config in configs/ 13 | $(foreach DEFCONFIG, $(DEFCONFIG_PATHS), $(eval $(call define_defconfig_rule,$(DEFCONFIG)))) 14 | -------------------------------------------------------------------------------- /configs/am335x_bone.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | /include/ "am33xx.dtsi" 3 | 4 | / { 5 | compatible = "ti,am335x-bone", "ti,am33xx"; 6 | }; 7 | -------------------------------------------------------------------------------- /configs/beaglebone_black_defconfig: -------------------------------------------------------------------------------- 1 | # 2 | # Automatically generated file; DO NOT EDIT. 3 | # F4OS Configuration 4 | # 5 | 6 | # 7 | # Arch 8 | # 9 | # CONFIG_ARCH_ARMV7M is not set 10 | CONFIG_ARCH_ARMV7A=y 11 | CONFIG_ARCH="armv7a" 12 | CONFIG_CHIP="am335x" 13 | CONFIG_VECTOR_VMA_REGION="sram" 14 | CONFIG_VECTOR_LMA_REGION="sram" 15 | CONFIG_KERNEL_VMA_REGION="sram" 16 | CONFIG_KERNEL_LMA_REGION="sram" 17 | CONFIG_TEXT_VMA_REGION="sram" 18 | CONFIG_TEXT_LMA_REGION="sram" 19 | CONFIG_RODATA_VMA_REGION="sram" 20 | CONFIG_RODATA_LMA_REGION="sram" 21 | CONFIG_LINKER_ARRAY_VMA_REGION="sram" 22 | CONFIG_LINKER_ARRAY_LMA_REGION="sram" 23 | CONFIG_DTB_VMA_REGION="sram" 24 | CONFIG_DTB_LMA_REGION="sram" 25 | CONFIG_DATA_VMA_REGION="sram" 26 | CONFIG_DATA_LMA_REGION="sram" 27 | CONFIG_BSS_VMA_REGION="sram" 28 | CONFIG_BSS_LMA_REGION="sram" 29 | CONFIG_INIT_SVC_STACK_POINTER=0x40302ffc 30 | CONFIG_INIT_IRQ_STACK_POINTER=0x40303ffc 31 | CONFIG_INIT_FIQ_STACK_POINTER=0x40303bfc 32 | CONFIG_INIT_ABT_STACK_POINTER=0x403037fc 33 | CONFIG_INIT_UND_STACK_POINTER=0x403033fc 34 | # CONFIG_COPY_DATA is not set 35 | 36 | # 37 | # Chip 38 | # 39 | CONFIG_CHIP_AM335X=y 40 | 41 | # 42 | # Clocks 43 | # 44 | CONFIG_AM335X_REFERENCE_CLOCK=24000000 45 | CONFIG_AM335X_DEFAULT_SYSTEM_CLOCK=200 46 | 47 | # 48 | # Memory layout 49 | # 50 | 51 | # 52 | # Drivers 53 | # 54 | CONFIG_HAVE_USART=y 55 | # CONFIG_HAVE_I2C is not set 56 | # CONFIG_HAVE_SPI is not set 57 | # CONFIG_HAVE_LED is not set 58 | # CONFIG_HAVE_USBDEV is not set 59 | CONFIG_STDOUT_DEV="am335x-static-usart" 60 | CONFIG_STDERR_DEV="am335x-static-usart" 61 | CONFIG_SYSTICK_FREQ=4000 62 | CONFIG_SHARED_MEM_SIZE=512 63 | # CONFIG_ADC_CLASS is not set 64 | # CONFIG_PWM_CLASS is not set 65 | CONFIG_UART_CLASS=y 66 | # CONFIG_ACCELEROMETERS is not set 67 | # CONFIG_BAROMETERS is not set 68 | # CONFIG_GYROSCOPES is not set 69 | # CONFIG_MAGNETOMETERS is not set 70 | # CONFIG_ROTARY_ENCODERS is not set 71 | 72 | # 73 | # Memory management 74 | # 75 | CONFIG_MM_ALLOCATOR_BUDDY=y 76 | # CONFIG_MM_ALLOCATOR_BITFIELD is not set 77 | CONFIG_SUSERHEAP=0x40308000 78 | CONFIG_SKERNELHEAP=0x40304000 79 | CONFIG_EUSERHEAP=0x40310000 80 | CONFIG_EKERNELHEAP=0x40308000 81 | CONFIG_MM_USER_MAX_ORDER=14 82 | CONFIG_MM_USER_MIN_ORDER=4 83 | CONFIG_MM_KERNEL_MAX_ORDER=13 84 | CONFIG_MM_KERNEL_MIN_ORDER=4 85 | 86 | # 87 | # Kernel 88 | # 89 | CONFIG_TASK_STACK_SIZE=255 90 | CONFIG_HELD_MUTEXES_MAX=6 91 | CONFIG_DEVICE_TREE="configs/am335x_bone.dts" 92 | -------------------------------------------------------------------------------- /configs/msp432_launchpad.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | compatible = "ti,msp432p401r_launchpad", "ti,msp432p401r", 5 | "ti,msp432p401", "ti,msp432p", "ti,msp432"; 6 | 7 | memory { 8 | compatible = "address-layout"; 9 | #address-cells = <1>; 10 | #size-cells = <1>; 11 | 12 | /* 256 KiB flash */ 13 | flash { 14 | attr = "rx"; 15 | reg = <0x00000000 0x40000>; 16 | }; 17 | 18 | /* 64 KiB SRAM */ 19 | ram { 20 | attr = "rwx"; 21 | reg = <0x20000000 0x10000>; 22 | }; 23 | }; 24 | }; 25 | -------------------------------------------------------------------------------- /configs/msp432_launchpad_defconfig: -------------------------------------------------------------------------------- 1 | # 2 | # Automatically generated file; DO NOT EDIT. 3 | # F4OS Configuration 4 | # 5 | 6 | # 7 | # Arch 8 | # 9 | CONFIG_ARCH_ARMV7M=y 10 | # CONFIG_ARCH_ARMV7A is not set 11 | CONFIG_ARCH="armv7m" 12 | 13 | # 14 | # Chip 15 | # 16 | # CONFIG_CHIP_STM32F40X is not set 17 | # CONFIG_CHIP_LM4F120H5 is not set 18 | CONFIG_CHIP_MSP432P401X=y 19 | CONFIG_CHIP="msp432p401x" 20 | CONFIG_HAVE_FPU=y 21 | CONFIG_SHORT_DOUBLE=y 22 | CONFIG_SYS_CLOCK=48000000 23 | 24 | # 25 | # Memory layout 26 | # 27 | CONFIG_VECTOR_VMA_REGION="flash" 28 | CONFIG_VECTOR_LMA_REGION="flash" 29 | CONFIG_KERNEL_VMA_REGION="flash" 30 | CONFIG_KERNEL_LMA_REGION="flash" 31 | CONFIG_TEXT_VMA_REGION="flash" 32 | CONFIG_TEXT_LMA_REGION="flash" 33 | CONFIG_RODATA_VMA_REGION="flash" 34 | CONFIG_RODATA_LMA_REGION="flash" 35 | CONFIG_LINKER_ARRAY_VMA_REGION="flash" 36 | CONFIG_LINKER_ARRAY_LMA_REGION="flash" 37 | CONFIG_DTB_VMA_REGION="flash" 38 | CONFIG_DTB_LMA_REGION="flash" 39 | CONFIG_DATA_VMA_REGION="ram" 40 | CONFIG_DATA_LMA_REGION="flash" 41 | CONFIG_BSS_VMA_REGION="ram" 42 | CONFIG_BSS_LMA_REGION="flash" 43 | CONFIG_INITIAL_SP=0x20004000 44 | 45 | # 46 | # Drivers 47 | # 48 | # CONFIG_HAVE_USART is not set 49 | # CONFIG_HAVE_I2C is not set 50 | # CONFIG_HAVE_SPI is not set 51 | # CONFIG_HAVE_LED is not set 52 | # CONFIG_HAVE_USBDEV is not set 53 | CONFIG_STDOUT_DEV="lm4f-static-usart" 54 | CONFIG_STDERR_DEV="lm4f-static-usart" 55 | CONFIG_SYSTICK_FREQ=4000 56 | CONFIG_SHARED_MEM_SIZE=128 57 | # CONFIG_ADC_CLASS is not set 58 | # CONFIG_PWM_CLASS is not set 59 | # CONFIG_UART_CLASS is not set 60 | # CONFIG_ACCELEROMETERS is not set 61 | # CONFIG_BAROMETERS is not set 62 | # CONFIG_GYROSCOPES is not set 63 | # CONFIG_MAGNETOMETERS is not set 64 | # CONFIG_ROTARY_ENCODERS is not set 65 | 66 | # 67 | # Memory management 68 | # 69 | CONFIG_MM_ALLOCATOR_BUDDY=y 70 | # CONFIG_MM_ALLOCATOR_BITFIELD is not set 71 | CONFIG_SUSERHEAP=0x20008000 72 | CONFIG_SKERNELHEAP=0x20004000 73 | CONFIG_EUSERHEAP=0x20010000 74 | CONFIG_EKERNELHEAP=0x20008000 75 | CONFIG_MM_USER_MAX_ORDER=15 76 | CONFIG_MM_USER_MIN_ORDER=4 77 | CONFIG_MM_KERNEL_MAX_ORDER=14 78 | CONFIG_MM_KERNEL_MIN_ORDER=4 79 | 80 | # 81 | # Kernel 82 | # 83 | CONFIG_TASK_STACK_SIZE=255 84 | CONFIG_HELD_MUTEXES_MAX=6 85 | CONFIG_DEVICE_TREE="configs/msp432_launchpad.dts" 86 | -------------------------------------------------------------------------------- /configs/stellaris_launchpad.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | compatible = "ti,stellaris_launchpad", "ti,tiva_c_launchpad", 5 | "ti,lm4f120h5qr", "ti,tm4c1233h6pm", "ti,lm4f120h5", "ti,tm4c1233h6", 6 | "ti,lm4", "ti,tm4c"; 7 | 8 | memory { 9 | compatible = "address-layout"; 10 | #address-cells = <1>; 11 | #size-cells = <1>; 12 | 13 | /* 256 KiB flash */ 14 | flash { 15 | attr = "rx"; 16 | reg = <0x00000000 0x40000>; 17 | }; 18 | 19 | /* 32 KiB SRAM */ 20 | ram { 21 | attr = "rwx"; 22 | reg = <0x20000000 0x8000>; 23 | }; 24 | }; 25 | }; 26 | -------------------------------------------------------------------------------- /configs/stellaris_launchpad_defconfig: -------------------------------------------------------------------------------- 1 | # 2 | # Automatically generated file; DO NOT EDIT. 3 | # F4OS Configuration 4 | # 5 | 6 | # 7 | # Arch 8 | # 9 | CONFIG_ARCH_ARMV7M=y 10 | # CONFIG_ARCH_ARMV7A is not set 11 | CONFIG_ARCH="armv7m" 12 | 13 | # 14 | # Chip 15 | # 16 | # CONFIG_CHIP_STM32F40X is not set 17 | CONFIG_CHIP_LM4F120H5=y 18 | CONFIG_CHIP="lm4f120h5" 19 | CONFIG_HAVE_FPU=y 20 | CONFIG_SHORT_DOUBLE=y 21 | CONFIG_SYS_CLOCK=84000000 22 | 23 | # 24 | # Memory layout 25 | # 26 | CONFIG_VECTOR_VMA_REGION="flash" 27 | CONFIG_VECTOR_LMA_REGION="flash" 28 | CONFIG_KERNEL_VMA_REGION="flash" 29 | CONFIG_KERNEL_LMA_REGION="flash" 30 | CONFIG_TEXT_VMA_REGION="flash" 31 | CONFIG_TEXT_LMA_REGION="flash" 32 | CONFIG_RODATA_VMA_REGION="flash" 33 | CONFIG_RODATA_LMA_REGION="flash" 34 | CONFIG_LINKER_ARRAY_VMA_REGION="flash" 35 | CONFIG_LINKER_ARRAY_LMA_REGION="flash" 36 | CONFIG_DTB_VMA_REGION="flash" 37 | CONFIG_DTB_LMA_REGION="flash" 38 | CONFIG_DATA_VMA_REGION="ram" 39 | CONFIG_DATA_LMA_REGION="flash" 40 | CONFIG_BSS_VMA_REGION="ram" 41 | CONFIG_BSS_LMA_REGION="flash" 42 | CONFIG_INITIAL_SP=0x20002000 43 | 44 | # 45 | # Drivers 46 | # 47 | CONFIG_HAVE_USART=y 48 | # CONFIG_HAVE_I2C is not set 49 | # CONFIG_HAVE_SPI is not set 50 | CONFIG_HAVE_LED=y 51 | # CONFIG_HAVE_USBDEV is not set 52 | CONFIG_STDOUT_DEV="lm4f-static-usart" 53 | CONFIG_STDERR_DEV="lm4f-static-usart" 54 | CONFIG_SYSTICK_FREQ=4000 55 | CONFIG_SHARED_MEM_SIZE=128 56 | # CONFIG_ADC_CLASS is not set 57 | # CONFIG_PWM_CLASS is not set 58 | CONFIG_UART_CLASS=y 59 | # CONFIG_ACCELEROMETERS is not set 60 | # CONFIG_BAROMETERS is not set 61 | # CONFIG_GYROSCOPES is not set 62 | # CONFIG_MAGNETOMETERS is not set 63 | # CONFIG_ROTARY_ENCODERS is not set 64 | 65 | # 66 | # Memory management 67 | # 68 | CONFIG_MM_ALLOCATOR_BUDDY=y 69 | # CONFIG_MM_ALLOCATOR_BITFIELD is not set 70 | CONFIG_SUSERHEAP=0x20004000 71 | CONFIG_SKERNELHEAP=0x20002000 72 | CONFIG_EUSERHEAP=0x20008000 73 | CONFIG_EKERNELHEAP=0x20004000 74 | CONFIG_MM_USER_MAX_ORDER=14 75 | CONFIG_MM_USER_MIN_ORDER=4 76 | CONFIG_MM_KERNEL_MAX_ORDER=13 77 | CONFIG_MM_KERNEL_MIN_ORDER=4 78 | 79 | # 80 | # Kernel 81 | # 82 | CONFIG_TASK_STACK_SIZE=255 83 | CONFIG_HELD_MUTEXES_MAX=6 84 | CONFIG_DEVICE_TREE="configs/stellaris_launchpad.dts" 85 | -------------------------------------------------------------------------------- /configs/stm32f4/01.dtsi: -------------------------------------------------------------------------------- 1 | /include/ "common.dtsi" 2 | 3 | / { 4 | compatible = "stmicro,stm32f401", "stmicro,stm32f4"; 5 | 6 | spi4: spi@40003C00 { 7 | #address-cells = <1>; 8 | #size-cells = <0>; 9 | compatible = "stmicro,stm32f407-spi"; 10 | reg = <0x40013400 0x20>; 11 | spi,sck-gpio = <&gpio 68 0>; /* PE4 */ 12 | spi,miso-gpio = <&gpio 69 0>; /* PE5 */ 13 | spi,mosi-gpio = <&gpio 70 0>; /* PE6 */ 14 | stmicro,periph-id = <57>; /* STM32F4_PERIPH_SPI4 */ 15 | }; 16 | }; 17 | -------------------------------------------------------------------------------- /configs/stm32f4/01xc.dtsi: -------------------------------------------------------------------------------- 1 | /include/ "01.dtsi" 2 | 3 | /* STM32F401 with 64KiB SRAM and 256KiB flash */ 4 | 5 | / { 6 | compatible = "stmicro,stm32f401xc", "stmicro,stm32f401", "stmicro,stm32f4"; 7 | 8 | memory { 9 | compatible = "address-layout"; 10 | #address-cells = <1>; 11 | #size-cells = <1>; 12 | 13 | /* 256 KiB flash */ 14 | flash { 15 | attr = "rx"; 16 | reg = <0x08000000 0x40000>; 17 | }; 18 | 19 | /* 64 KiB SRAM */ 20 | ram { 21 | attr = "rwx"; 22 | reg = <0x20000000 0x10000>; 23 | }; 24 | }; 25 | }; 26 | -------------------------------------------------------------------------------- /configs/stm32f4/05xg.dtsi: -------------------------------------------------------------------------------- 1 | /include/ "05.dtsi" 2 | 3 | /* STM32F405 with 192KiB SRAM, 1MiB flash */ 4 | 5 | / { 6 | compatible = "stmicro,stm32f405xg", "stmicro,stm32f405", "stmicro,stm32f4"; 7 | 8 | memory { 9 | compatible = "address-layout"; 10 | #address-cells = <1>; 11 | #size-cells = <1>; 12 | 13 | /* 1MiB flash */ 14 | flash { 15 | attr = "rx"; 16 | reg = <0x08000000 0x100000>; 17 | }; 18 | 19 | /* 64 KiB CCMRAM */ 20 | ccmram { 21 | attr = "rwx"; 22 | reg = <0x10000000 0x10000>; 23 | }; 24 | 25 | /* 112KiB SRAM */ 26 | ram { 27 | attr = "rwx"; 28 | reg = <0x20000000 0x1c000>; 29 | }; 30 | 31 | /* 16KiB ETHRAM */ 32 | ethram { 33 | attr = "rwx"; 34 | reg = <0x2001c000 0x4000>; 35 | }; 36 | }; 37 | }; 38 | -------------------------------------------------------------------------------- /configs/stm32f4/07.dtsi: -------------------------------------------------------------------------------- 1 | /include/ "05.dtsi" 2 | 3 | /* STM32F407 extends STM32F405 with additional peripherals */ 4 | 5 | / { 6 | compatible = "stmicro,stm32f407", "stmicro,stm32f405", "stmicro,stm32f4"; 7 | }; 8 | -------------------------------------------------------------------------------- /configs/stm32f4/07xg.dtsi: -------------------------------------------------------------------------------- 1 | /include/ "07.dtsi" 2 | 3 | /* STM32F407 with 192KiB SRAM, 1MiB flash */ 4 | 5 | / { 6 | compatible = "stmicro,stm32f407xg", "stmicro,stm32f407", 7 | "stmicro,stm32f405", "stmicro,stm32f4"; 8 | 9 | memory { 10 | compatible = "address-layout"; 11 | #address-cells = <1>; 12 | #size-cells = <1>; 13 | 14 | /* 1MiB flash */ 15 | flash { 16 | attr = "rx"; 17 | reg = <0x08000000 0x100000>; 18 | }; 19 | 20 | /* 64 KiB CCMRAM */ 21 | ccmram { 22 | attr = "rwx"; 23 | reg = <0x10000000 0x10000>; 24 | }; 25 | 26 | /* 112KiB SRAM */ 27 | ram { 28 | attr = "rwx"; 29 | reg = <0x20000000 0x1c000>; 30 | }; 31 | 32 | /* 16KiB ETHRAM */ 33 | ethram { 34 | attr = "rwx"; 35 | reg = <0x2001c000 0x4000>; 36 | }; 37 | }; 38 | }; 39 | -------------------------------------------------------------------------------- /configs/stm32f4_discovery_revb.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | /include/ "stm32f4/07xg.dtsi" 3 | 4 | / { 5 | compatible = "stmicro,stm32f4discovery-revb", "stmicro,stm32f4discovery", 6 | "stmicro,stm32f407vg", "stmicro,stm32f407xg", "stmicro,stm32f407", 7 | "stmicro,stm32f405", "stmicro,stm32f4"; 8 | 9 | }; 10 | 11 | &spi1 { 12 | lis302dl@0 { 13 | compatible = "stmicro,lis302dl"; 14 | reg = <0>; 15 | cs-gpio = <&gpio 67 0>; /* PE3 */ 16 | }; 17 | }; 18 | -------------------------------------------------------------------------------- /configs/stm32f4_discovery_revc.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | /include/ "stm32f4/07xg.dtsi" 3 | 4 | / { 5 | compatible = "stmicro,stm32f4discovery-revc", "stmicro,stm32f4discovery", 6 | "stmicro,stm32f407vg", "stmicro,stm32f407xg", "stmicro,stm32f407", 7 | "stmicro,stm32f405", "stmicro,stm32f4"; 8 | 9 | }; 10 | 11 | &spi1 { 12 | lis3dsh@0 { 13 | compatible = "stmicro,lis3dsh"; 14 | reg = <0>; 15 | cs-gpio = <&gpio 67 0>; /* PE3 */ 16 | }; 17 | }; 18 | -------------------------------------------------------------------------------- /configs/stm32f4_px4.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | /include/ "stm32f4/05xg.dtsi" 3 | 4 | / { 5 | compatible = "pixhawk,px4fmu", "stmicro,stm32f405rg", 6 | "stmicro,stm32f405xg", "stmicro,stm32f405", "stmicro,stm32f4"; 7 | }; 8 | 9 | &spi1 { 10 | mpu6000@0 { 11 | compatible = "invensense,mpu6000-spi"; 12 | reg = <0>; 13 | cs-gpio = <&gpio 16 0>; /* PB0 */ 14 | 15 | accel { 16 | compatible = "invensense,mpu6000-accel"; 17 | }; 18 | 19 | gyro { 20 | compatible = "invensense,mpu6000-gyro"; 21 | }; 22 | }; 23 | }; 24 | 25 | &i2c2 { 26 | hmc5883l@1E { 27 | compatible = "honeywell,hmc5883l", "honeywell,hmc5883"; 28 | reg = <0x1E>; 29 | }; 30 | 31 | ms5611@76 { 32 | compatible = "meas-spec,ms5611-01ba03"; 33 | reg = <0x76>; 34 | }; 35 | }; 36 | -------------------------------------------------------------------------------- /dev/Makefile: -------------------------------------------------------------------------------- 1 | SRCS += clocks.c 2 | SRCS += char.c 3 | SRCS += resource.c 4 | SRCS += shared_mem.c 5 | SRCS += buf_stream.c 6 | SRCS += device.c 7 | SRCS += fdtparse.c 8 | 9 | DIRS += hw/ 10 | DIRS_$(CONFIG_ACCELEROMETERS) += accel/ 11 | DIRS_$(CONFIG_BAROMETERS) += baro/ 12 | DIRS_$(CONFIG_GYROSCOPES) += gyro/ 13 | DIRS_$(CONFIG_MAGNETOMETERS) += mag/ 14 | DIRS_$(CONFIG_ROTARY_ENCODERS) += rotary_encoder/ 15 | 16 | DIRS_$(CONFIG_MPU6000) += mpu6000/ 17 | 18 | include $(BASE)/tools/submake.mk 19 | -------------------------------------------------------------------------------- /dev/accel/Kconfig: -------------------------------------------------------------------------------- 1 | menu "Accelerometers" 2 | 3 | config MPU6000_ACCEL 4 | bool "InvenSense MPU6000 Accelerometer" 5 | depends on MPU6000 6 | ---help--- 7 | MPU6000 accelerometer driver. Provides access to the accelerometer 8 | features of the MPU6000, with a standard accelerometer driver. 9 | 10 | config STM_LIS302DL 11 | bool "STMicro LIS302DL Accelerometer" 12 | depends on HAVE_SPI 13 | ---help--- 14 | 3-axis accelerometer from STMicro. 15 | 16 | endmenu 17 | -------------------------------------------------------------------------------- /dev/accel/Makefile: -------------------------------------------------------------------------------- 1 | SRCS += accel.c 2 | SRCS_$(CONFIG_STM_LIS302DL) += lis302dl.c 3 | 4 | include $(BASE)/tools/submake.mk 5 | -------------------------------------------------------------------------------- /dev/baro/Kconfig: -------------------------------------------------------------------------------- 1 | menu "Barometers" 2 | 3 | config MS5611 4 | bool "Measurement Specialists MS5611 Barometer" 5 | depends on HAVE_I2C 6 | ---help--- 7 | Standard barometer driver for MS5611. 8 | 9 | endmenu 10 | -------------------------------------------------------------------------------- /dev/baro/Makefile: -------------------------------------------------------------------------------- 1 | SRCS += baro.c 2 | 3 | SRCS_$(CONFIG_MS5611) += ms5611.c 4 | 5 | include $(BASE)/tools/submake.mk 6 | -------------------------------------------------------------------------------- /dev/baro/baro.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | void baro_dtor(struct obj *o); 30 | 31 | struct obj_type baro_type_s = { 32 | .offset = offset_of(struct baro, obj), 33 | .dtor = baro_dtor, 34 | }; 35 | 36 | /* 37 | * Barometers are never destroyed. When their refcount reaches zero, 38 | * this destructor is called, and the barometer is deinitialized (possibly 39 | * going into a low power state), but it remains registered and available for 40 | * use for the duration of the OS. 41 | */ 42 | void baro_dtor(struct obj *o) { 43 | struct baro *baro; 44 | struct baro_ops *ops; 45 | 46 | assert_type(o, &baro_type_s); 47 | baro = to_baro(o); 48 | ops = (struct baro_ops *) o->ops; 49 | ops->deinit(baro); 50 | } 51 | 52 | struct class baro_class = INIT_CLASS(baro_class, "baro", &baro_type_s); 53 | 54 | /* Set up barometer system */ 55 | int baro_setup(void) { 56 | /* Set up baro_class */ 57 | obj_init(&baro_class.obj, system_class.type, "baro"); 58 | 59 | /* Register baro_class with /system/dev */ 60 | register_with_system(&dev_system, &baro_class); 61 | return 0; 62 | } 63 | CORE_INITIALIZER(baro_setup) 64 | -------------------------------------------------------------------------------- /dev/gyro/Kconfig: -------------------------------------------------------------------------------- 1 | menu "Gyroscopes" 2 | 3 | config MPU6000_GYRO 4 | bool "InvenSense MPU6000 Gyroscope" 5 | depends on MPU6000 6 | ---help--- 7 | MPU6000 gyroscope driver. Provides access to the gyroscope 8 | features of the MPU6000, with a standard gyroscope driver. 9 | 10 | config ITG3200_GYRO 11 | bool "InvenSense ITG-3200 Gyroscope" 12 | depends on HAVE_I2C 13 | ---help--- 14 | InvenSense ITG-3200 Gyroscope driver. 15 | 16 | endmenu 17 | -------------------------------------------------------------------------------- /dev/gyro/Makefile: -------------------------------------------------------------------------------- 1 | SRCS += gyro.c 2 | 3 | SRCS_$(CONFIG_ITG3200_GYRO) += itg3200.c 4 | 5 | include $(BASE)/tools/submake.mk 6 | -------------------------------------------------------------------------------- /dev/gyro/gyro.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | void gyro_dtor(struct obj *o); 30 | 31 | struct obj_type gyro_type_s = { 32 | .offset = offset_of(struct gyro, obj), 33 | .dtor = gyro_dtor, 34 | }; 35 | 36 | /* 37 | * Gyroscopes are never destroyed. When their refcount reaches zero, 38 | * this destructor is called, and the gyroscope is deinitialized (possibly 39 | * going into a low power state), but they remain registered and available for 40 | * use for the duration of the OS. 41 | */ 42 | void gyro_dtor(struct obj *o) { 43 | struct gyro *gyro; 44 | struct gyro_ops *ops; 45 | 46 | assert_type(o, &gyro_type_s); 47 | gyro = to_gyro(o); 48 | ops = (struct gyro_ops *)o->ops; 49 | ops->deinit(gyro); 50 | } 51 | 52 | struct class gyro_class = INIT_CLASS(gyro_class, "gyro", &gyro_type_s); 53 | 54 | int gyro_setup(void) { 55 | obj_init(&gyro_class.obj, system_class.type, "gyro"); 56 | 57 | register_with_system(&dev_system, &gyro_class); 58 | return 0; 59 | } 60 | CORE_INITIALIZER(gyro_setup) 61 | -------------------------------------------------------------------------------- /dev/hw/Makefile: -------------------------------------------------------------------------------- 1 | SRCS += gpio.c 2 | 3 | SRCS_$(CONFIG_ADC_CLASS) += adc.c 4 | SRCS_$(CONFIG_HAVE_I2C) += i2c.c 5 | SRCS_$(CONFIG_HAVE_LED) += led.c 6 | SRCS_$(CONFIG_PWM_CLASS) += pwm.c 7 | SRCS_$(CONFIG_HAVE_SPI) += spi.c 8 | SRCS_$(CONFIG_UART_CLASS) += uart.c 9 | 10 | include $(BASE)/tools/submake.mk 11 | -------------------------------------------------------------------------------- /dev/hw/i2c.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013, 2014 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | static void i2c_dtor(struct obj *o); 28 | 29 | struct obj_type i2c_type_s = { 30 | .offset = offset_of(struct i2c, obj), 31 | .dtor = &i2c_dtor, 32 | }; 33 | 34 | struct class i2c_class = INIT_CLASS(i2c_class, "i2c", &i2c_type_s); 35 | 36 | static void i2c_dtor(struct obj *o) { 37 | struct i2c *i2c; 38 | struct i2c_ops *ops; 39 | 40 | assert_type(o, &i2c_type_s); 41 | i2c = to_i2c(o); 42 | ops = (struct i2c_ops *) o->ops; 43 | ops->deinit(i2c); 44 | 45 | /* Deinitialize, but don't destroy the I2C device */ 46 | } 47 | -------------------------------------------------------------------------------- /dev/hw/pwm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013, 2014 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | void pwm_dtor(struct obj *o); 32 | 33 | struct obj_type pwm_type_s = { 34 | .offset = offset_of(struct pwm, obj), 35 | .dtor = pwm_dtor, 36 | }; 37 | 38 | struct class pwm_class = INIT_CLASS(pwm_class, "pwm", &pwm_type_s); 39 | 40 | void pwm_dtor(struct obj *o) { 41 | struct pwm *pwm; 42 | struct pwm_ops *ops; 43 | 44 | assert_type(o, &pwm_type_s); 45 | pwm = to_pwm(o); 46 | ops = (struct pwm_ops *)o->ops; 47 | ops->dtor(pwm); 48 | 49 | /* Decref GPIO obj */ 50 | obj_put(pwm->gpio); 51 | 52 | /* We are completely done with this object, get rid of it */ 53 | class_unexport_member(o); 54 | class_deinstantiate(o); 55 | } 56 | 57 | int pwm_setup(void) { 58 | obj_init(&pwm_class.obj, system_class.type, "pwm"); 59 | return 0; 60 | } 61 | CORE_INITIALIZER(pwm_setup) 62 | 63 | /* 64 | * In the event that there is no chip PWM driver, provide stub pwm_get 65 | * that always returns failure. 66 | */ 67 | struct obj __weak *pwm_get(struct obj *gpio, uint32_t duty) { 68 | return NULL; 69 | } 70 | -------------------------------------------------------------------------------- /dev/hw/spi.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013, 2014 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | static void spi_dtor(struct obj *o); 28 | 29 | struct obj_type spi_type_s = { 30 | .offset = offset_of(struct spi, obj), 31 | .dtor = &spi_dtor, 32 | }; 33 | 34 | struct class spi_class = INIT_CLASS(spi_class, "spi", &spi_type_s); 35 | 36 | static void spi_dtor(struct obj *o) { 37 | struct spi *spi; 38 | struct spi_ops *ops; 39 | 40 | assert_type(o, &spi_type_s); 41 | spi = to_spi(o); 42 | ops = (struct spi_ops *)o->ops; 43 | ops->deinit(spi); 44 | 45 | /* Deinitialize, but don't destroy the SPI device */ 46 | } 47 | -------------------------------------------------------------------------------- /dev/mag/Kconfig: -------------------------------------------------------------------------------- 1 | menu "Magnetometers" 2 | 3 | config HMC5883 4 | bool "Honeywell HMC5883 Magnetometer" 5 | depends on HAVE_I2C 6 | ---help--- 7 | Standard magnetometer driver for HMC5883. 8 | 9 | endmenu 10 | -------------------------------------------------------------------------------- /dev/mag/Makefile: -------------------------------------------------------------------------------- 1 | SRCS += mag.c 2 | 3 | SRCS_$(CONFIG_HMC5883) += hmc5883.c 4 | 5 | include $(BASE)/tools/submake.mk 6 | -------------------------------------------------------------------------------- /dev/mpu6000/Kconfig: -------------------------------------------------------------------------------- 1 | config MPU6000 2 | bool "InvenSense MPU6000" 3 | depends on HAVE_SPI 4 | ---help--- 5 | Base class for MPU6000 support. Provides device-level support for the 6 | MPU6000, with support for reading/writing registers, allowing 7 | accelerometer and gyro drivers to be built on top. 8 | -------------------------------------------------------------------------------- /dev/mpu6000/Makefile: -------------------------------------------------------------------------------- 1 | SRCS += class.c 2 | SRCS += spi.c 3 | SRCS_$(CONFIG_MPU6000_ACCEL) += accel.c 4 | SRCS_$(CONFIG_MPU6000_GYRO) += gyro.c 5 | 6 | include $(BASE)/tools/submake.mk 7 | -------------------------------------------------------------------------------- /dev/mpu6000/class.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | void mpu6000_dtor(struct obj *o); 30 | 31 | struct obj_type mpu6000_type_s = { 32 | .offset = offset_of(struct mpu6000, obj), 33 | .dtor = mpu6000_dtor, 34 | }; 35 | 36 | /* MPU6000 objects are not destroyed, simply placed into a low power state */ 37 | void mpu6000_dtor(struct obj *o) { 38 | struct mpu6000 *m; 39 | struct mpu6000_ops *ops; 40 | 41 | assert_type(o, &mpu6000_type_s); 42 | m = to_mpu6000(o); 43 | ops = (struct mpu6000_ops *)o->ops; 44 | ops->deinit(m); 45 | } 46 | 47 | struct class mpu6000_class = INIT_CLASS(mpu6000_class, "mpu6000", 48 | &mpu6000_type_s); 49 | 50 | int mpu6000_class_setup(void) { 51 | obj_init(&mpu6000_class.obj, system_class.type, "mpu6000"); 52 | 53 | register_with_system(&dev_system, &mpu6000_class); 54 | return 0; 55 | } 56 | CORE_INITIALIZER(mpu6000_class_setup) 57 | -------------------------------------------------------------------------------- /dev/rotary_encoder/Kconfig: -------------------------------------------------------------------------------- 1 | menu "Rotary encoders" 2 | 3 | config AS5048B 4 | bool "AMS AS5048B Rotary Encoder" 5 | depends on HAVE_I2C 6 | ---help--- 7 | Standard rotary encoder driver for AS5048B. 8 | Supports one-time programming of zero position 9 | with calibrate method. 10 | 11 | endmenu 12 | -------------------------------------------------------------------------------- /dev/rotary_encoder/Makefile: -------------------------------------------------------------------------------- 1 | SRCS += rotary_encoder.c 2 | 3 | SRCS_$(CONFIG_AS5048B) += as5048b.c 4 | 5 | include $(BASE)/tools/submake.mk 6 | -------------------------------------------------------------------------------- /docs/arch_porting.md: -------------------------------------------------------------------------------- 1 | Porting to a new architecture 2 | ============================= 3 | 4 | Porting to a new architecture is more involved than porting to a new chip. 5 | Luckily, F4OS has been designed to be as architecture-agnostic as possible, 6 | outside of the `arch/` folder. 7 | 8 | Some of the things that would be necessary to begin porting to a new 9 | architecture: 10 | 11 | * Initial system and C runtime startup, eventually calling `os_start()` 12 | * `init_arch()` to do architecture and chip initialization, including 13 | initializing the system and peripheral clocks 14 | * Exception handling 15 | * Scheduler support, including: 16 | * A preemptive interrupt for system ticks 17 | * This should call `sched_system_tick()` at CONFIG_SYSTICK_FREQ. 18 | * A software interrupt, for service calls 19 | * Context switching routines 20 | * A mechanism for differentiating kernel and user stack pointers 21 | * A list of Arch-provided functions can be found in 22 | `include/kernel/sched_internals.h`. 23 | 24 | -------------------------------------------------------------------------------- /docs/armv7a.md: -------------------------------------------------------------------------------- 1 | ARMv7-A Support 2 | =============== 3 | 4 | ARMv7-A is the application profile of the ARMv7 architecture. 5 | It supports the ARM, Thumb, and Thumb2 instruction sets. 6 | 7 | Currently support for ARMv7-A is very basic. The MMU is never enabled, 8 | nor are the instruction or data caches. 9 | 10 | ## Toolchain 11 | 12 | An arm-none-eabi- GNU toolchain is necessary to build for ARMv7-A. 13 | The following versions of the toolchain are known working: 14 | 15 | * [GCC ARM Embedded](https://launchpad.net/gcc-arm-embedded) 16 | * Debian's arm-none-eabi packages 17 | * [gcc-arm-none-eabi](https://packages.debian.org/jessie/gcc-arm-none-eabi) 18 | * [binutils-arm-none-eabi](https://packages.debian.org/jessie/binutils-arm-none-eabi) 19 | 20 | ## Chip porting 21 | 22 | Porting to a new ARMv7-A chip, is fairly simple. 23 | 24 | Only a few things should be required to get running: 25 | 26 | * A linker script to place sections in the right portion of memory 27 | * An example can be found in `arch/armv7a/chip/am335x/link.ld` 28 | * An `init_chip()` function, which initializes the system and peripheral 29 | clocks. The function prototype can be found in `arch/armv7a/include/chip.h`. 30 | * `irq_handler()` and `fiq_handler()` functions, which lookup and handle IRQ 31 | and FIQ interrupts as they occur. Their function prototypes can be found in 32 | `arch/armv7a/include/chip.h`. 33 | * A `chip_sched_start_system_tick()` function, which initializes a timer to 34 | preempt the system at CONFIG_SYSTICK_FREQ, performing a system tick by 35 | calling `sched_system_tick()`. The function prototypes can be found in 36 | `arch/armv7a/include/chip.h` and `include/kernel/sched_internals.h`. 37 | 38 | At that point, it should be possible to run F4OS on the chip, with all extra 39 | features disabled (no outputs, no GPIOs, etc). From there, chip peripheral 40 | drivers can be written to provide additional functionality. 41 | -------------------------------------------------------------------------------- /docs/armv7m.md: -------------------------------------------------------------------------------- 1 | ARMv7-M Support 2 | =============== 3 | 4 | ARMv7-M is the microcontroller variant of the ARMv7 architecture. 5 | It supports the Thumb and Thumb2 instruction sets. 6 | 7 | All of the ARMv7-M chips currently supported are ARM Cortex-M4F chips, however 8 | ARM Cortex-M4 and ARM Cortex-M3 should be supported simply by disabling FPU 9 | support (`CONFIG_HAVE_FPU`). 10 | 11 | Non-Cortex-M chips have not been considered, but only minor changes should be 12 | necessary to support them. The core architecture code is chip agnostic. 13 | 14 | ## Toolchain 15 | 16 | An arm-none-eabi- GNU toolchain is necessary to build for ARMv7-M. For 17 | FPU support, the GCC build must include hard-float support for Cortex-M4F. 18 | The following versions of the toolchain are known working, including for 19 | FPU support: 20 | 21 | * [GCC ARM Embedded](https://launchpad.net/gcc-arm-embedded) 22 | * Debian's arm-none-eabi packages 23 | * [gcc-arm-none-eabi](https://packages.debian.org/jessie/gcc-arm-none-eabi) 24 | * [binutils-arm-none-eabi](https://packages.debian.org/jessie/binutils-arm-none-eabi) 25 | 26 | ## Chip porting 27 | 28 | Porting to a new ARMv7-M chip, especially a Cortex-M4 or Cortex-M3 chip, is 29 | fairly simple. 30 | 31 | Only a few things should be required to get running: 32 | 33 | * A linker script to place sections in the right portion of memory 34 | * An example can be found in `arch/armv7m/chip/lm4f120h5/link.ld` 35 | * A vector table initialized with the reset and exception vectors 36 | * An `init_clock()` function, which initializes the system and peripheral 37 | clocks. The function prototype can be found in `arch/armv7m/include/chip.h`. 38 | 39 | At that point, it should be possible to run F4OS on the chip, with all extra 40 | features disabled (no outputs, no GPIOs, etc). From there, chip peripheral 41 | drivers can be written to provide additional functionality. 42 | 43 | The architecture code uses the Cortex-M SysTick timer for preemptive 44 | scheduling. For chips without this timer, additional work is needed 45 | to disable use of the SysTick timer, and to use another timer for preemptive 46 | scheduling. 47 | -------------------------------------------------------------------------------- /docs/fdt/bindings/README: -------------------------------------------------------------------------------- 1 | This directory contains device tree bindings for F4OS. 2 | 3 | Bindings are split into subdirectories based on category, and describe 4 | the required and optional properties for the different bindings. 5 | 6 | General documentation for devicetree can be found at: 7 | http://www.devicetree.org 8 | -------------------------------------------------------------------------------- /docs/fdt/bindings/address-layout.txt: -------------------------------------------------------------------------------- 1 | Generic address space layout bindings 2 | 3 | These bindings describe the layout of a device's physical address map. 4 | This is used primarily to describe regions of memory for program storage 5 | and memory (e.g., ROM, RAM, flash). 6 | 7 | The core's address space layout should be described in /memory, which 8 | contains a subnode for each region of memory. 9 | 10 | Required properties: 11 | - compatible: must be "address-layout" 12 | - #address-cells: must be <1> 13 | - #size-cells: must be <1> 14 | 15 | Region subnode properties: 16 | - reg: start address and size of region 17 | - attr: string describing region attributes, in the same format as 18 | LD's MEMORY attr string[1]. 19 | 20 | [1]: https://sourceware.org/binutils/docs/ld/MEMORY.html#MEMORY 21 | -------------------------------------------------------------------------------- /docs/fdt/bindings/clocks/clocks.txt: -------------------------------------------------------------------------------- 1 | Clocks bindings 2 | 3 | Clock bindings describe the clocks that a peripheral is connected to. 4 | 5 | Clock providers required properties: 6 | - #clock-cells: Number of clock specifier cells 7 | 8 | Clock users specify the clocks they use in the "clocks" property. 9 | 10 | Required properties: 11 | - clocks: List of multiple clock provider entry. Each entry begins 12 | with the provider phandle, followed by #clock-cells specifiers 13 | 14 | Optional properties: 15 | - clock-names: String list of clock names, in the same order as the 16 | clocks property 17 | -------------------------------------------------------------------------------- /docs/fdt/bindings/clocks/ti-am335x-prcm.txt: -------------------------------------------------------------------------------- 1 | TI AM335x PRCM clocks bindings 2 | 3 | Clock providers #clock-cells should be 1. The clock specifier 4 | specifies the register offset of the clock control register from 5 | the provider base address. 6 | 7 | Clock users optional properties: 8 | - ti,clock-select: Same format as general clocks binding. 9 | Specifies clock provider register offset used to select 10 | peripheral clock source when written. 11 | -------------------------------------------------------------------------------- /docs/fdt/bindings/dma/dma-stm32f4.txt: -------------------------------------------------------------------------------- 1 | STMicro STM32F4 DMA bindings 2 | 3 | DMA controllers should specify #dma-cells = <2>. The first cell is 4 | the DMA stream number. The second cell is the stream channel number. 5 | Duplicate dma-names may be provided, if they offer the same functionality. 6 | 7 | Required properties: 8 | - compatible: Must be "stmicro,stm32f407-dma" 9 | - reg: register base address and register map size 10 | - #dma-cells: Must be 2 11 | - stmicro,periph-id: STM32F4 Peripheral ID associated with the peripheral 12 | -------------------------------------------------------------------------------- /docs/fdt/bindings/dma/dma.txt: -------------------------------------------------------------------------------- 1 | DMA controller and client bindings 2 | 3 | DMA controllers required properties: 4 | - #dma-cells: Number of dma property cells 5 | 6 | DMA clients required properties: 7 | - dmas: List of DMA channel cells. Each cell begins with 8 | the controller phandle, followed by #dma-cells specifiers 9 | - dma-names: String list of DMA names, one for each DMA channel. 10 | -------------------------------------------------------------------------------- /docs/fdt/bindings/gpio/gpio-prop.txt: -------------------------------------------------------------------------------- 1 | GPIO property bindings 2 | 3 | When referencing a GPIO, the GPIO property consists of three cells: 4 | - phandle to GPIO device controlling the GPIO 5 | - GPIO number on the device 6 | - GPIO flags, defined below and by the GPIO device 7 | 8 | Global valid GPIO flags are found in include/dev/hw/gpio.h: 9 | - GPIO_FDT_ACTIVE_LOW (1 << 0): GPIO is active low 10 | -------------------------------------------------------------------------------- /docs/fdt/bindings/gpio/gpio-stm32f4.txt: -------------------------------------------------------------------------------- 1 | GPIO for STM32F4 chips 2 | 3 | Required properties: 4 | - compatible: Must be "stmicro,stm32f407-gpio" 5 | 6 | When referencing GPIOs in a GPIO property, the valid GPIO numbers can be found 7 | in arch/armv7m/chip/stm32f40x/include/gpio.h in enum stm32f4_gpios. 8 | 9 | Only the standard FDT GPIO flags are supported. These are documented in 10 | gpio-prop.txt. 11 | -------------------------------------------------------------------------------- /docs/fdt/bindings/i2c/i2c-bus.txt: -------------------------------------------------------------------------------- 1 | I2C Bus Bindings 2 | 3 | Binding for devices on an I2C bus 4 | 5 | Required properties: 6 | - reg: I2C device address on the bus 7 | -------------------------------------------------------------------------------- /docs/fdt/bindings/i2c/i2c-stm32f4.txt: -------------------------------------------------------------------------------- 1 | I2C for STM32F4 chips 2 | 3 | Required properties: 4 | - compatible: Must be "stmicro,stm32f407-i2c" 5 | - reg: register base address and register map size 6 | - i2c,scl-gpio: GPIO property for the SCL GPIO 7 | - i2c,sda-gpio: GPIO property for the SDA GPIO 8 | - stmicro,periph-id: STM32F4 Peripheral ID of the bus peripheral 9 | - #address-cells = <1>; 10 | - #size-cells = <0>; 11 | 12 | Optional properties: 13 | - Child nodes describing devices on the bus, 14 | conforming to the I2C bus bindings 15 | 16 | Example: 17 | 18 | i2c1: i2c@40005400 { 19 | #address-cells = <1>; 20 | #size-cells = <0>; 21 | compatible = "stmicro,stm32f407-i2c"; 22 | reg = <0x40005400 0x24>; 23 | i2c,scl-gpio = <&gpio 24 0>; /* PB8 */ 24 | i2c,sda-gpio = <&gpio 25 0>; /* PB9 */ 25 | stmicro,periph-id = <26>; /* STM32F4_PERIPH_I2C1 */ 26 | 27 | hmc5883l@1E { 28 | compatible = "honeywell,hmc5883l", "honeywell,hmc5883"; 29 | reg = <0x1E>; 30 | }; 31 | }; 32 | -------------------------------------------------------------------------------- /docs/fdt/bindings/mpu6000.txt: -------------------------------------------------------------------------------- 1 | Invensense MPU6000 bindings 2 | 3 | Required properties: 4 | - compatible: must be either "invensense,mpu6000-spi" or 5 | "invensense,mpu6000-i2c" (currently unsupported) 6 | 7 | The MPU6000 may either be on an I2C or SPI bus, and should conform to 8 | the appropriate bus bindings. 9 | 10 | Options properties: 11 | - "accel" node, with compatible = "invensense,mpu6000-accel" to indicate 12 | accelerometer support. 13 | - "gyro" node, with compatible = "invensense,mpu6000-gyro" to indicate 14 | gyroscope support. 15 | -------------------------------------------------------------------------------- /docs/fdt/bindings/spi/spi-bus.txt: -------------------------------------------------------------------------------- 1 | SPI Bus Bindings 2 | 3 | Binding for devices on a SPI bus 4 | 5 | Required properties: 6 | - cs-gpio: GPIO property describing the CS GPIO 7 | -------------------------------------------------------------------------------- /docs/fdt/bindings/spi/spi-stm32f4.txt: -------------------------------------------------------------------------------- 1 | SPI for STM32F4 chips 2 | 3 | Required properties: 4 | - compatible: Must be "stmicro,stm32f407-spi" 5 | - reg: register base address and register map size 6 | - spi,sck-gpio: GPIO property for the SCK GPIO 7 | - spi,miso-gpio: GPIO property for the MISO GPIO 8 | - spi,mosi-gpio: GPIO property for the MOSI GPIO 9 | - stmicro,periph-id: STM32F4 Peripheral ID associated with the bus 10 | - #address-cells = <1>; 11 | - #size-cells = <0>; 12 | 13 | Optional properties: 14 | - Child nodes describing devices on the bus, 15 | conforming to the SPI bus bindings 16 | 17 | Example: 18 | 19 | spi1: spi@40013000 { 20 | #address-cells = <1>; 21 | #size-cells = <0>; 22 | compatible = "stmicro,stm32f407-spi"; 23 | reg = <0x40013000 0x20>; 24 | spi,sck-gpio = <&gpio 5 0>; /* PA5 */ 25 | spi,miso-gpio = <&gpio 6 0>; /* PA6 */ 26 | spi,mosi-gpio = <&gpio 7 0>; /* PA7 */ 27 | stmicro,periph-id = <23>; /* STM32F4_PERIPH_SPI1 */ 28 | 29 | lis302dl@0 { 30 | compatible = "stmicro,lis302dl"; 31 | reg = <0>; 32 | cs-gpio = <&gpio 67 0>; /* PE3 */ 33 | }; 34 | }; 35 | -------------------------------------------------------------------------------- /docs/fdt/bindings/uart/uart-stm32f4.txt: -------------------------------------------------------------------------------- 1 | UART for STM32F4 chips 2 | 3 | Required properties: 4 | - compatible: Must be "stmicro,stm32f407-uart" 5 | - reg: register base address and register map size 6 | - uart,tx-gpio: GPIO property for the RX GPIO 7 | - uart,rx-gpio: GPIO property for the TX GPIO 8 | - stmicro,periph-id: STM32F4 Peripheral ID associated with the bus 9 | - dmas: DMA channels 10 | - dma-names: "rx" and "tx", may include duplicates 11 | 12 | Example: 13 | 14 | uart1: uart@40011000 { 15 | compatible = "stmicro,stm32f407-uart"; 16 | reg = <0x40011000 0x1C>; 17 | uart,tx-gpio = <&gpio 22 0>; /* PB6 */ 18 | uart,rx-gpio = <&gpio 23 0>; /* PB7 */ 19 | stmicro,periph-id = <29>; /* STM32F4_PERIPH_USART1 */ 20 | dmas = <&dma2 2 4>, <&dma2 5 4>, <&dma2 7 4>; 21 | dma-names = "rx", "rx", "tx"; 22 | }; 23 | -------------------------------------------------------------------------------- /docs/tivac.md: -------------------------------------------------------------------------------- 1 | TI Tiva C Series Chips 2 | ====================== 3 | 4 | The Tiva C series is a series of ARM Cortex-M4F microcontrollers from TI, with 5 | a maximum frequency of 80MHz-120MHz. 6 | 7 | [Manufacturer product page](http://www.ti.com/lsds/ti/microcontroller/tiva_arm_cortex/c_series/overview.page) 8 | 9 | The Tiva C series has basic support in F4OS. Specifically development has 10 | focused on the LM4F120H5QR, aka TM4C1233H6PM. No regard has been given for 11 | other variants in development, but members of the TM4C123x and TM4C129x 12 | series should be mostly supported. 13 | 14 | ## Peripherals 15 | 16 | ### UART 17 | UART0 supported as a standard resource. It is hardcoded to operate on PA0 and 18 | PA1, at a baud rate of 115200 and 8N1 configuration. 19 | 20 | ### GPIO 21 | Any of the chip GPIOs can be used with the standard GPIO obj system. 22 | 23 | ## Flashing 24 | 25 | Tiva C chips have on-chip flash, starting at address 0x00000000. The output 26 | file `f4os.bin` should be written to that address. The officially supported 27 | board supports flashing with `make burn`, as described below. 28 | 29 | ## Boards 30 | 31 | F4OS officially supports, and includes defconfigs for, one Tiva C-based board 32 | 33 | ### TI Stellaris Launchpad 34 | 35 | The Stellaris Launchpad was TI's primary development board for LM4F series 36 | chips, before renaming the series to Tiva C. The board has onboard a 37 | LM4F120H5QR, aka TM4C1233H6PM. Additionally, it has an on-board JTAG 38 | debugger, which can be used to flash the chip. 39 | 40 | http://www.ti.com/tool/EK-LM4F120XL 41 | 42 | This board has since been superseded by the TI Tiva C Series Launchpad, which 43 | is not officially supported. 44 | 45 | The LEDs are supported by F4OS. They are enumerated as LEDs 0-2. 46 | 47 | The provided defconfig can be used to configure F4OS for the Stellaris 48 | Launchpad. 49 | 50 | $ make stellaris_launchpad_defconfig 51 | 52 | #### Flashing 53 | 54 | `make burn` will use the J-Link Commander software to flash the chip. 55 | This will only work if a Segger J-Link JTAG debugger is connected to 56 | the board JTAG header. 57 | 58 | Alternatively, the on-board JTAG debugger can be used to flash the chip, with 59 | a tool such as lm4flash, part of [lm4tools](https://github.com/utzig/lm4tools). 60 | 61 | #### Output 62 | 63 | The Stellaris Launchpad defconfig configures UART0 as both stdout and stderr, 64 | at a baud rate of 115200. 65 | -------------------------------------------------------------------------------- /f4os.mk: -------------------------------------------------------------------------------- 1 | DIRS += arch/ 2 | DIRS += dev/ 3 | DIRS += kernel/ 4 | DIRS += lib/ 5 | DIRS += mm/ 6 | DIRS += usr/ 7 | 8 | include $(BASE)/tools/submake.mk 9 | -------------------------------------------------------------------------------- /include/compiler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | /* Special compiler constructs, such as function and type attributes */ 24 | 25 | #ifndef COMPILER_H_INCLUDED 26 | #define COMPILER_H_INCLUDED 27 | 28 | #define offset_of(type, member) __builtin_offsetof(type, member) 29 | 30 | #define container_of(ptr, type, member) ({ \ 31 | const typeof( ((type *)0)->member ) *__mptr = (ptr); \ 32 | (type *)( (char *)__mptr - __builtin_offsetof(type,member) );}) 33 | 34 | #define __always_inline inline __attribute__((always_inline)) 35 | #define __weak __attribute__((weak)) 36 | #define __packed __attribute__((packed)) 37 | 38 | #define STRINGIFY(s) STRINGIFY2(s) 39 | #define STRINGIFY2(s) #s 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /include/dev/arch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #ifndef DEV_ARCH_H_INCLUDED 24 | #define DEV_ARCH_H_INCLUDED 25 | 26 | void init_arch(void) __attribute__((section(".kernel"))); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /include/dev/buf_stream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013, 2014 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #ifndef DEV_BUF_STREAM_H_INCLUDED 24 | #define DEV_BUF_STREAM_H_INCLUDED 25 | 26 | #include 27 | 28 | /* 29 | * Create a stream character device around of given buffer of a given length. 30 | * Reading from this resource will read until the NULL terminator is reached, 31 | * or len characters have been read. Writing to this resource will 32 | * sequentially write the characters to the buffer, until len-1 characters have 33 | * been written, leaving a a NULL terminator. 34 | */ 35 | struct char_device *buf_stream_create(char *buf, uint32_t len); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /include/dev/hw/perfcounter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #ifndef DEV_HW_PERFCOUNTER_H_INCLUDED 24 | #define DEV_HW_PERFCOUNTER_H_INCLUDED 25 | 26 | void init_perfcounter(void) __attribute__((section(".kernel"))); 27 | uint64_t perfcounter_getcount(void); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /include/dev/hw/systick.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #ifndef DEV_HW_SYSTICK_INCLUDED 24 | #define DEV_HW_SYSTICK_INCLUDED 25 | 26 | void init_systick(void) __attribute__((section(".kernel"))); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /include/dev/hw/usart.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013, 2014 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #ifndef DEV_HW_USART_H_INCLUDED 24 | #define DEV_HW_USART_H_INCLUDED 25 | 26 | #include 27 | 28 | int usart_putc(char c, void *env) __attribute__((section(".kernel"))); 29 | int usart_puts(char *s, void *env) __attribute__((section(".kernel"))); 30 | char usart_getc(void *env, int *error) __attribute__((section(".kernel"))); 31 | int usart_close(resource *resource) __attribute__((section(".kernel"))); 32 | 33 | extern uint8_t usart_ready; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /include/dev/hw/usbdev.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #ifndef DEV_USBDEV_H_INCLUDED 24 | #define DEV_USBDEV_H_INCLUDED 25 | 26 | void usbdev_handler(void) __attribute__((section(".kernel"))); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /include/dev/sensors.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #ifndef DEV_SENSORS_H_INCLUDED 24 | #define DEV_SENSORS_H_INCLUDED 25 | 26 | /* Basic data structures for sensors */ 27 | 28 | struct magnetometer { 29 | float x; 30 | float y; 31 | float z; 32 | }; 33 | 34 | struct accelerometer { 35 | float x; 36 | float y; 37 | float z; 38 | }; 39 | 40 | struct gyro { 41 | float x; 42 | float y; 43 | float z; 44 | }; 45 | 46 | struct barometer { 47 | float pressure; 48 | float temp; 49 | }; 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /include/dev/shared_mem.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013, 2014 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #ifndef DEV_SHARED_MEM_H_INCLUDED 24 | #define DEV_SHARED_MEM_H_INCLUDED 25 | 26 | #include 27 | 28 | /** 29 | * Create a shared memory region 30 | * 31 | * Create a buffer of configurable size intended to be shared between 32 | * tasks. Reads and writes go to the same buffer, which can be used for 33 | * rudimentary message passing. 34 | */ 35 | struct char_device *shared_mem_create(void); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /include/float.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #ifndef FLOAT_H_INCLUDED 24 | #define FLOAT_H_INCLUDED 25 | 26 | #define FLT_MAX_EXP 128 /* Not confirmed */ 27 | #define FLT_MIN_EXP -125 /* Not confirmed */ 28 | 29 | /* http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0491c/Babbfeda.html */ 30 | #define FLT_MAX 3.40282347e+38F 31 | #define FLT_MIN 1.175494351e-38F 32 | 33 | #define FLT_RADIX 2 34 | #define FLT_ROUNDS 1 35 | #define FLT_DIGITS 6 36 | 37 | #define FLT_EPSILON 1.19209290e-7F 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /include/kernel/power.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #ifndef KERNEL_POWER_H_INCLUDED 24 | #define KERNEL_POWER_H_INCLUDED 25 | 26 | /** 27 | * Place the core in the lowest power state that still responds to interrupts. 28 | * 29 | * @returns 0 on wakeup from low power state, 30 | * else if low power state not supported. 31 | */ 32 | int arch_wait_for_interrupt(void); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /include/limits.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #ifndef LIMITS_H_INCLUDED 24 | #define LIMITS_H_INCLUDED 25 | 26 | #define MB_LEN_MAX 1 27 | 28 | #define CHAR_BIT __CHAR_BIT__ 29 | 30 | /* Minimum and maximum values a 'signed char' can hold. */ 31 | #define SCHAR_MAX __SCHAR_MAX__ 32 | #define SCHAR_MIN (-SCHAR_MAX-1) 33 | 34 | /* Maximum value an 'unsigned char' can hold. (Minimum is 0). */ 35 | #define UCHAR_MAX 255 36 | 37 | /* Minimum and maximum values a 'char' can hold. */ 38 | #define CHAR_MIN 0 39 | #define CHAR_MAX 255 40 | 41 | /* Minimum and maximum values a 'signed short int' can hold. */ 42 | #define SHRT_MAX __SHRT_MAX__ 43 | #define SHRT_MIN (-SHRT_MAX-1) 44 | 45 | /* Maximum value an 'unsigned short int' can hold. (Minimum is 0). */ 46 | #define USHRT_MAX __UINT16_MAX__ 47 | 48 | /* Minimum and maximum values a 'signed int' can hold. */ 49 | #define INT_MAX __INT_MAX__ 50 | #define INT_MIN (-INT_MAX-1) 51 | 52 | /* Maximum value an 'unsigned int' can hold. (Minimum is 0). */ 53 | #define UINT_MAX (INT_MAX * 2U + 1) 54 | 55 | /* Minimum and maximum values a 'signed long int' can hold. 56 | (Same as `int'). */ 57 | #define LONG_MAX __LONG_MAX__ 58 | #define LONG_MIN (-LONG_MAX-1) 59 | 60 | /* Maximum value an `unsigned long int' can hold. (Minimum is 0). */ 61 | #define ULONG_MAX (LONG_MAX * 2UL + 1) 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /include/mm/mm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #ifndef MM_MM_H_INCLUDED 24 | #define MM_MM_H_INCLUDED 25 | 26 | #include 27 | #include 28 | 29 | void init_heap(void) __attribute__((section(".kernel"))); 30 | void *kmalloc(size_t size) __attribute__((malloc,section(".kernel"))); 31 | void kfree(void *address) __attribute__((section(".kernel"))); 32 | 33 | uint32_t mm_space(void) __attribute__((section(".kernel"))); 34 | uint32_t mm_kspace(void) __attribute__((section(".kernel"))); 35 | 36 | #ifdef CONFIG_MM_PROFILING 37 | extern uint64_t begin_malloc_timestamp, end_malloc_timestamp; 38 | #endif 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /include/stdarg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #ifndef STDARG_H_INCLUDED 24 | #define STDARG_H_INCLUDED 25 | 26 | typedef __builtin_va_list va_list; 27 | 28 | #define va_start(v,l) __builtin_va_start(v,l) 29 | #define va_arg(v,l) __builtin_va_arg(v,l) 30 | #define va_end(v) __builtin_va_end(v) 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /include/stddef.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013, 2015 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #ifndef STDDEF_H_INCLUDED 24 | #define STDDEF_H_INCLUDED 25 | 26 | typedef __PTRDIFF_TYPE__ ptrdiff_t; 27 | typedef __SIZE_TYPE__ size_t; 28 | 29 | #define NULL (void *) 0x00000000 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /include/stdlib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013, 2014 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #ifndef STDLIB_H_INCLUDED 24 | #define STDLIB_H_INCLUDED 25 | 26 | #include 27 | #include 28 | 29 | void *malloc(size_t size) __attribute__((malloc,section(".kernel"))); 30 | void free(void *address) __attribute__((section(".kernel"))); 31 | void abort(void) __attribute__((section(".kernel"))); 32 | char *strndup(const char *str, int n); 33 | char *strdup(const char *str); 34 | int atoi(char buf[]); 35 | char *itoa(int number, char *buf, uint32_t len, uint32_t base); 36 | char *uitoa(uint32_t number, char *buf, uint32_t len, uint32_t base); 37 | void ftoa(float num, float tolerance, char buf[], uint32_t n); 38 | 39 | static inline int abs(int n) { 40 | return n > 0 ? n : -n; 41 | } 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /include/string.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013, 2014 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #ifndef STRING_H_INCLUDED 24 | #define STRING_H_INCLUDED 25 | 26 | #include 27 | #include 28 | 29 | void *memchr(const void *ptr, int value, size_t num); 30 | int memcmp(const void *ptr1, const void *ptr2, size_t num); 31 | void memset32(void *p, int32_t value, uint32_t size); 32 | void memset(void *p, uint8_t value, uint32_t size); 33 | void memcpy(void *dst, const void *src, int n); 34 | void memmove(void *dst, const void *src, size_t n); 35 | char *strchr(const char *s, int c); 36 | size_t strlen(const char *s); 37 | size_t strnlen(const char *s, int n); 38 | void strreverse(char *s); 39 | int strcmp(const char *s, const char *p); 40 | int strncmp(const char *s, const char *p, uint32_t n); 41 | char *strncpy(char *destination, const char *source, int num); 42 | int chrnlst(char c, const char *l); 43 | 44 | static inline int printable(char c) { 45 | return c >= 0x20 && c <= 0x7E; 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /include/time.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #ifndef TIME_H_INCLUDED 24 | #define TIME_H_INCLUDED 25 | 26 | #include 27 | 28 | extern volatile uint32_t system_ticks; 29 | 30 | /* Microsecond sleep. Max precision is system tick period (1/CONFIG_SYSTICK_FREQ). */ 31 | int usleep(uint32_t usecs); 32 | 33 | /* 34 | * Time since start time in us. 35 | * 36 | * start_time of 0 will indicate us since system boot. 37 | * Max precision is system tick period (1/CONFIG_SYSTICK_FREQ). 38 | */ 39 | uint64_t system_time(uint64_t start_time); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /kernel/Kconfig: -------------------------------------------------------------------------------- 1 | config TASK_STACK_SIZE 2 | int 3 | prompt "Task stack size" 4 | default 255 5 | ---help--- 6 | The stack size allocated to each task, in words. 7 | When building unoptimized, most tasks will need 8 | more stack space, so this will probably the limiting 9 | factor. It is recommended to set this to a value 10 | 2^n - 1 in order to limit wasted space in the memory 11 | allocator, which must allocate 2^n sized regions, and 12 | will set aside one word for a header. 13 | 14 | config HELD_MUTEXES_MAX 15 | int 16 | prompt "Maximum number of held mutexes per task" 17 | default 6 18 | ---help--- 19 | The maximum number of mutexes any given task will 20 | be able to hold at one time. Each held mutex must 21 | be stored alongside the task to aid in deadlock checking. 22 | -------------------------------------------------------------------------------- /kernel/Makefile: -------------------------------------------------------------------------------- 1 | SRCS += fault.c 2 | SRCS += init.c 3 | SRCS += mutex.c 4 | SRCS += reentrant_mutex.c 5 | SRCS += class.c 6 | SRCS += collection.c 7 | SRCS += system.c 8 | 9 | DIRS += sched/ 10 | 11 | include $(BASE)/tools/submake.mk 12 | -------------------------------------------------------------------------------- /kernel/reentrant_mutex.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | void reentrant_acquire(struct reentrant_mutex *mutex) { 29 | PANIC_ON(!mutex); 30 | 31 | if (mutex->held_by == curr_task) { 32 | mutex->count++; 33 | } 34 | else { 35 | acquire(&mutex->lock); 36 | mutex->held_by = curr_task; 37 | mutex->count = 1; 38 | } 39 | } 40 | 41 | void reentrant_release(struct reentrant_mutex *mutex) { 42 | PANIC_ON(!mutex); 43 | PANIC_ON(mutex->held_by != curr_task); 44 | 45 | if (!--mutex->count) { 46 | mutex->held_by = NULL; 47 | release(&mutex->lock); 48 | } 49 | 50 | WARN_ON(mutex->count < 0); 51 | } 52 | 53 | -------------------------------------------------------------------------------- /kernel/sched/Makefile: -------------------------------------------------------------------------------- 1 | SRCS += kernel_task.c 2 | SRCS += sched_generic.c 3 | SRCS += sched_api.c 4 | SRCS += sched_end.c 5 | SRCS += sched_interrupts.c 6 | SRCS += sched_new.c 7 | SRCS += sched_start.c 8 | SRCS += sched_switch.c 9 | 10 | include $(BASE)/tools/submake.mk 11 | -------------------------------------------------------------------------------- /kernel/sched/kernel_task.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013, 2014 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include "sched_internals.h" 30 | 31 | struct list free_task_list = INIT_LIST(free_task_list); 32 | 33 | void kernel_task(void) { 34 | /* Does cleanup that can't be done from outside a task (ie. in an interrupt) */ 35 | 36 | while (!list_empty(&free_task_list)) { 37 | struct list *element = list_pop(&free_task_list); 38 | struct task_ctrl *task = list_entry(element, struct task_ctrl, free_task_list); 39 | 40 | /* Free abandoned mutexes */ 41 | for (int i = 0; i < HELD_MUTEXES_MAX; i++) { 42 | struct task_mutex_data *mut_data = &get_task_t(task)->mutex_data; 43 | 44 | if (mut_data->held_mutexes[i]) { 45 | release(mut_data->held_mutexes[i]); 46 | } 47 | } 48 | 49 | free_task(task); 50 | } 51 | } 52 | 53 | void sleep_task(void) { 54 | /* Run when there is nothing else to run */ 55 | while (1) { 56 | arch_wait_for_interrupt(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /kernel/sched/sched_generic.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013, 2014 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | /* Functions common to all scheduler implementations */ 28 | 29 | /* 30 | * Setup new task IO 31 | * 32 | * This means copying stdin/stdout/stderr from the current task. 33 | */ 34 | static void task_io_setup(task_t *task) { 35 | if (stdin) { 36 | obj_get(&stdin->obj); 37 | } 38 | task->_stdin = stdin; 39 | 40 | if (stdout) { 41 | obj_get(&stdout->obj); 42 | } 43 | task->_stdout = stdout; 44 | 45 | if (stderr) { 46 | obj_get(&stderr->obj); 47 | } 48 | task->_stderr = stderr; 49 | } 50 | 51 | /* Do non-scheduler setup for new task */ 52 | void generic_task_setup(task_t *task) { 53 | task_io_setup(task); 54 | task_mutex_setup(task); 55 | } 56 | -------------------------------------------------------------------------------- /kernel/sched/sched_start.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013, 2014 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include "sched_internals.h" 27 | 28 | volatile uint8_t task_switching = 0; 29 | 30 | /* 31 | * "Task" before task switching begins 32 | * 33 | * Used for accessing things like stdin/stdout before 34 | * task switching begins. 35 | */ 36 | static struct task_ctrl pre_switch_task; 37 | task_t * volatile curr_task = &pre_switch_task.exported; 38 | 39 | void start_sched(void) { 40 | /* 41 | * Set up initial tasks. 42 | * Kernel task performs cleanup every millisecond. 43 | */ 44 | new_task(&kernel_task, 10, 1000); 45 | new_task(&sleep_task, 0, 0); 46 | 47 | /* Setup boot tasks specified by end user. */ 48 | main(); 49 | 50 | /* Perform last minute arch setup */ 51 | arch_sched_start_bootstrap(); 52 | 53 | /* Switch to first task */ 54 | task_switch(NULL); 55 | } 56 | 57 | /* By default, do nothing */ 58 | void __weak arch_sched_start_bootstrap(void) {} 59 | -------------------------------------------------------------------------------- /kernel/system.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | struct collection systems = INIT_COLLECTION(systems); 28 | 29 | struct obj_type system_type_s = { 30 | .dtor = NULL, 31 | .offset = offset_of(system_t, obj), 32 | }; 33 | 34 | struct class system_class = INIT_CLASS(system_class, "system", &system_type_s); 35 | 36 | struct system dev_system = INIT_SYSTEM(dev_system, dev); 37 | 38 | int create_dev_system(void) { 39 | obj_init(&dev_system.obj, &system_type_s, "dev"); 40 | collection_add(&systems, &dev_system.obj); 41 | return 0; 42 | } 43 | CORE_INITIALIZER(create_dev_system) 44 | 45 | struct obj *get_by_name_from_system(struct system *sys, char *cls_name, char *inst_name) { 46 | struct obj *cls_obj = collection_get_by_name(&sys->classes, cls_name); 47 | 48 | if(!cls_obj) 49 | return NULL; 50 | 51 | struct class *cls = to_class(cls_obj); 52 | return get_by_name_from_class(inst_name, cls); 53 | } 54 | 55 | struct obj *get_system_by_name(char *name) { 56 | return collection_get_by_name(&systems, name); 57 | } 58 | 59 | void register_with_system(struct system *sys, struct class *cls) { 60 | collection_add(&sys->classes, &cls->obj); 61 | } 62 | -------------------------------------------------------------------------------- /lib/Makefile: -------------------------------------------------------------------------------- 1 | SRCS += stdio.c 2 | SRCS += stdlib.c 3 | SRCS += string.c 4 | SRCS += time.c 5 | 6 | DIRS += libfdt/ 7 | DIRS += math/ 8 | 9 | include $(BASE)/tools/submake.mk 10 | -------------------------------------------------------------------------------- /lib/libfdt/Makefile: -------------------------------------------------------------------------------- 1 | SRCS += fdt.c 2 | SRCS += fdt_ro.c 3 | SRCS += fdt_wip.c 4 | SRCS += fdt_sw.c 5 | SRCS += fdt_rw.c 6 | SRCS += fdt_strerror.c 7 | SRCS += fdt_empty_tree.c 8 | 9 | include $(BASE)/tools/submake.mk 10 | -------------------------------------------------------------------------------- /lib/math/Makefile: -------------------------------------------------------------------------------- 1 | SRCS += math_pow.c 2 | SRCS += math_other.c 3 | 4 | DIRS += newlib/ 5 | 6 | include $(BASE)/tools/submake.mk 7 | -------------------------------------------------------------------------------- /lib/math/math_other.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | float lowpass(float acc, float new, float gain) { 28 | acc = acc * (1-gain); 29 | 30 | return acc + new * gain; 31 | } 32 | 33 | float __weak fabsf(float num) { 34 | return num > 0 ? num : -num; 35 | } 36 | -------------------------------------------------------------------------------- /lib/math/math_pow.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | 26 | uint32_t pow(uint32_t base, uint32_t exp) { 27 | int result = base; 28 | 29 | if (exp == 0) { 30 | return 1; 31 | } 32 | 33 | exp--; 34 | while (exp) { 35 | result = result * base; 36 | exp--; 37 | } 38 | 39 | return result; 40 | } 41 | -------------------------------------------------------------------------------- /lib/math/newlib/Makefile: -------------------------------------------------------------------------------- 1 | SRCS += math_newlib.c 2 | SRCS += math_sine.c 3 | SRCS += math_tangent.c 4 | SRCS += math_atangent.c 5 | 6 | include $(BASE)/tools/submake.mk 7 | -------------------------------------------------------------------------------- /lib/math/newlib/math_tangent.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was derived from the Newlib open source project, 3 | * and is subject to its copyright notices and licenses, which 4 | * can be found in lib/math/newlib/LICENSE. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | static const float TWO_OVER_PI = 0.6366197723f; 12 | static const float p[] = { -0.958017723e-1f }; 13 | static const float q[] = { -0.429135777f, 14 | 0.971685835e-2f }; 15 | 16 | float tanf(float x) { 17 | float y, f, g, xnum, xden, res; 18 | int N; 19 | 20 | /* Check for special values. */ 21 | switch (numtestf (x)) { 22 | case NAN: 23 | return (x); 24 | case INF: 25 | return (FLOAT_NAN); 26 | } 27 | 28 | y = fabsf (x); 29 | 30 | /* Check for values that are out of our range. */ 31 | if (y > 105414357.0f) 32 | { 33 | return (y); 34 | } 35 | 36 | if (x < 0.0f) 37 | N = (int) (x * TWO_OVER_PI - 0.5f); 38 | else 39 | N = (int) (x * TWO_OVER_PI + 0.5f); 40 | 41 | f = x - N * FLOAT_PI_OVER_TWO; 42 | 43 | /* Check for values that are too small. */ 44 | if (-ROOTEPS < f && f < ROOTEPS) 45 | { 46 | xnum = f; 47 | xden = 1.0f; 48 | } 49 | 50 | /* Calculate the polynomial. */ 51 | else 52 | { 53 | g = f * f; 54 | 55 | xnum = f * (p[0] * g) + f; 56 | xden = (q[1] * g + q[0]) * g + 1.0f; 57 | } 58 | 59 | /* Check for odd or even values. */ 60 | if (N & 1) 61 | { 62 | xnum = -xnum; 63 | res = xden / xnum; 64 | } 65 | else 66 | { 67 | res = xnum / xden; 68 | } 69 | 70 | return (res); 71 | } 72 | -------------------------------------------------------------------------------- /lib/time.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | volatile uint32_t system_ticks = 0; 28 | 29 | int usleep(uint32_t usecs) { 30 | uint64_t start = system_time(0); 31 | 32 | while (system_time(start) < usecs) { 33 | yield_if_possible(); 34 | } 35 | 36 | return 0; 37 | } 38 | 39 | uint64_t system_time(uint64_t start_time) { 40 | uint32_t local_sys_ticks = system_ticks; 41 | 42 | /* Tick period in usecs */ 43 | uint64_t period = 1e6/CONFIG_SYSTICK_FREQ; 44 | 45 | /* usec since boot */ 46 | uint64_t current_time = local_sys_ticks * period; 47 | 48 | return current_time - start_time; 49 | } 50 | -------------------------------------------------------------------------------- /mm/Kconfig: -------------------------------------------------------------------------------- 1 | choice 2 | prompt "Allocator type" 3 | default MM_ALLOCATOR_BUDDY 4 | 5 | config MM_ALLOCATOR_BUDDY 6 | bool "Buddy allocator" 7 | ---help--- 8 | Buddy allocator. Only power of two allocations are made, 9 | leading to esay merging of blocks. Internal fragmentation 10 | is high, but external fragmentation is low. 11 | 12 | config MM_ALLOCATOR_BITFIELD 13 | bool "Bitfield allocator" 14 | ---help--- 15 | Bitfield allocator. Allocation granularity down configurable. 16 | Harder to "merge" after smaller allocations, leading to small 17 | internal fragmentation but high external fragmentation. 18 | 19 | endchoice 20 | 21 | config SUSERHEAP 22 | hex "Start address of user heap" 23 | 24 | config SKERNELHEAP 25 | hex "Start address of kernel heap" 26 | 27 | config EUSERHEAP 28 | hex "End address of user heap" 29 | 30 | config EKERNELHEAP 31 | hex "End address of kernel heap" 32 | 33 | config MM_GRAIN_SHIFT 34 | int 35 | default 4 36 | depends on MM_ALLOCATOR_BITFIELD 37 | prompt "Bitfield allocator grain shift" 38 | ---help--- 39 | Power of 2 for the bitfield allocator granularity. 40 | 2**this is what it rounds up to when allocating space. 41 | 42 | config MM_USER_MAX_ORDER 43 | int 44 | depends on MM_ALLOCATOR_BUDDY 45 | prompt "User buddy heap max order" 46 | ---help--- 47 | Maximum buddy block order for user buddy heap. 48 | Heap will be 2^order bytes. 49 | 50 | config MM_USER_MIN_ORDER 51 | int 52 | depends on MM_ALLOCATOR_BUDDY 53 | prompt "User buddy heap min order" 54 | default 4 55 | ---help--- 56 | Minimum buddy block order to allocate for user buddy. 57 | 58 | config MM_KERNEL_MAX_ORDER 59 | int 60 | depends on MM_ALLOCATOR_BUDDY 61 | prompt "Kernel buddy heap max order" 62 | ---help--- 63 | Maximum buddy block order for kernel buddy heap. 64 | Heap will be 2^order bytes. 65 | 66 | config MM_KERNEL_MIN_ORDER 67 | int 68 | depends on MM_ALLOCATOR_BUDDY 69 | prompt "Kernel buddy heap min order" 70 | default 4 71 | ---help--- 72 | Minimum buddy block order to allocate for kernel buddy. 73 | 74 | config MM_PROFILING 75 | bool 76 | depends on PERFCOUNTER 77 | prompt "Memory manager profiling" 78 | default n 79 | ---help--- 80 | Enables instrumenting mm functions and using mem_perf 81 | -------------------------------------------------------------------------------- /mm/Makefile: -------------------------------------------------------------------------------- 1 | SRCS_$(CONFIG_MM_ALLOCATOR_BUDDY) += buddy_mm_free.c 2 | SRCS_$(CONFIG_MM_ALLOCATOR_BUDDY) += buddy_mm_init.c 3 | SRCS_$(CONFIG_MM_ALLOCATOR_BUDDY) += buddy_mm_malloc.c 4 | SRCS_$(CONFIG_MM_ALLOCATOR_BUDDY) += buddy_mm_space.c 5 | SRCS_$(CONFIG_MM_ALLOCATOR_BITFIELD) += bitfield_mm_free.c 6 | SRCS_$(CONFIG_MM_ALLOCATOR_BITFIELD) += bitfield_mm_init.c 7 | SRCS_$(CONFIG_MM_ALLOCATOR_BITFIELD) += bitfield_mm_malloc.c 8 | SRCS_$(CONFIG_MM_ALLOCATOR_BITFIELD) += bitfield_mm_space.c 9 | 10 | include $(BASE)/tools/submake.mk 11 | -------------------------------------------------------------------------------- /mm/bitfield_mm_init.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013, 2014 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include "bitfield_mm_internals.h" 28 | 29 | struct mutex userheap_mutex = INIT_MUTEX; 30 | struct mutex kernelheap_mutex = INIT_MUTEX; 31 | 32 | mm_block_t userheap[MM_USER_NUM_BLOCKS]; 33 | mm_block_t kernelheap[MM_KERNEL_NUM_BLOCKS]; 34 | 35 | static void init_this_heap(mm_block_t *heap, uint32_t size) { 36 | for(int i = 0; i < size; i++) { 37 | heap[i].free_grains = MM_GRAINS_PER_BLOCK; 38 | heap[i].free_mask = 0; 39 | } 40 | } 41 | 42 | void init_heap(void) { 43 | init_this_heap(kernelheap, MM_KERNEL_NUM_BLOCKS); 44 | init_this_heap(userheap, MM_USER_NUM_BLOCKS); 45 | } 46 | -------------------------------------------------------------------------------- /mm/bitfield_mm_space.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013, 2014 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include "bitfield_mm_internals.h" 28 | 29 | static uint32_t count_space(mm_block_t *heap, uint32_t hlen, struct mutex *mutex) { 30 | uint32_t space = 0; 31 | 32 | acquire(mutex); 33 | for(int i = 0; i < hlen; i++) { 34 | space += MM_GRAIN_SIZE*heap[i].free_grains; 35 | } 36 | release(mutex); 37 | return space; 38 | } 39 | 40 | uint32_t mm_space(void) { 41 | return count_space(userheap, MM_USER_NUM_BLOCKS, &userheap_mutex); 42 | } 43 | 44 | uint32_t mm_kspace(void) { 45 | return count_space(kernelheap, MM_KERNEL_NUM_BLOCKS, &kernelheap_mutex); 46 | } 47 | -------------------------------------------------------------------------------- /mm/buddy_mm_internals.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013, 2014 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #ifndef MM_BUDDY_MM_INTERNALS_INCLUDED 24 | #define MM_BUDDY_MM_INTERNALS_INCLUDED 25 | 26 | #include 27 | 28 | #define MM_MAGIC 0xBEEF 29 | 30 | struct heapnode_header { 31 | uint16_t magic; 32 | uint8_t order; 33 | uint8_t padding; /* Tasks won't take kindly to */ 34 | /* getting unaligned addresses */ 35 | } __attribute__((packed)); 36 | 37 | struct heapnode { 38 | struct heapnode_header header; 39 | struct heapnode *next; 40 | } __attribute__((packed)); 41 | 42 | struct buddy { 43 | uint8_t max_order; 44 | uint8_t min_order; 45 | struct mutex mutex; 46 | struct heapnode **list; 47 | }; 48 | 49 | #define MM_HEADER_SIZE sizeof(struct heapnode_header) 50 | #define MM_MAX_USER_SIZE (CONFIG_EUSERHEAP - CONFIG_SUSERHEAP) 51 | #define MM_MAX_KERNEL_SIZE (CONFIG_EKERNELHEAP - CONFIG_SKERNELHEAP) 52 | 53 | extern struct buddy user_buddy; 54 | extern struct heapnode *user_buddy_list[]; 55 | 56 | extern struct buddy kernel_buddy; 57 | extern struct heapnode *kernel_buddy_list[]; 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /mm/buddy_mm_space.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013, 2014 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | 26 | #include 27 | #include "buddy_mm_internals.h" 28 | 29 | static uint32_t free_memory(struct buddy *buddy); 30 | 31 | uint32_t mm_space(void) { 32 | uint32_t space; 33 | acquire(&user_buddy.mutex); 34 | space = free_memory(&user_buddy); 35 | release(&user_buddy.mutex); 36 | 37 | return space; 38 | } 39 | 40 | uint32_t mm_kspace(void) { 41 | uint32_t space; 42 | acquire(&kernel_buddy.mutex); 43 | space = free_memory(&kernel_buddy); 44 | release(&kernel_buddy.mutex); 45 | 46 | return space; 47 | } 48 | 49 | static uint32_t free_memory(struct buddy *buddy) { 50 | uint32_t free = 0; 51 | 52 | for (int i = buddy->min_order; i <= buddy->max_order; i++) { 53 | struct heapnode *node = buddy->list[i]; 54 | while (node) { 55 | free += pow(2, i); 56 | node = node->next; 57 | } 58 | } 59 | 60 | return free; 61 | } 62 | -------------------------------------------------------------------------------- /mm/mpu.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #define BASE_REGION 0 24 | #define USER_MEM_REGION 1 25 | #define VECTFLASH_REGION 2 26 | #define RAM_REGION 4 27 | #define PRIV_PERIPH_REGION 5 28 | #define KERNEL_CODE_REGION 6 29 | #define KERNEL_MEM_REGION 7 30 | 31 | void mpu_setup(void) __attribute__((section(".kernel"))); 32 | void mpu_stack_set(uint32_t *stack_base) __attribute__((section(".kernel"))); 33 | uint16_t mpu_size(uint32_t size) __attribute__((section(".kernel"))); 34 | -------------------------------------------------------------------------------- /tools/build.mk: -------------------------------------------------------------------------------- 1 | # Primary rules for building source files 2 | 3 | include $(BASE)/tools/common.mk 4 | 5 | # For nonrecursive builds, obj_prefix will be empty, 6 | # so the normal prefix will be used 7 | obj_prefix ?= $(PREFIX)/ 8 | 9 | $(obj_prefix)%.o : %.S $(KCONFIG_HEADER) 10 | $(call print_command,"CC","$(RELATIVE_CURDIR)/$<") 11 | $(VERBOSE)$(CC) -MD -c $(CFLAGS) $< -o $@ 12 | 13 | $(obj_prefix)%.o : %.c $(KCONFIG_HEADER) 14 | $(call print_command,"CC","$(RELATIVE_CURDIR)/$<") 15 | $(VERBOSE)$(CC) -MD -c $(CFLAGS) $< -o $@ 16 | 17 | %.hex: %.elf 18 | $(call print_command,"OBJCOPY",$(call relative_path,$@)) 19 | $(VERBOSE)$(OBJCOPY) -O ihex $< $@ 20 | 21 | %.bin: %.elf 22 | $(call print_command,"OBJCOPY",$(call relative_path,$@)) 23 | $(VERBOSE)$(OBJCOPY) -O binary $< $@ 24 | 25 | -include $(addprefix $(obj_prefix), $(SRCS:.S=.d)) 26 | -include $(addprefix $(obj_prefix), $(SRCS:.c=.d)) 27 | 28 | .FORCE: 29 | -------------------------------------------------------------------------------- /tools/build_kconfig.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | VERSION=3.11.0.0 4 | URL=http://ymorin.is-a-geek.org/download/kconfig-frontends/kconfig-frontends-$VERSION.tar.bz2 5 | 6 | set -e 7 | 8 | if [ $# -ne 1 ] 9 | then 10 | echo "Usage $0 kconfig-install-dir" 11 | exit $E_BADARGS 12 | fi 13 | 14 | INSTALL=$1 15 | 16 | echo "It looks like the Kconfig tools are not installed on your system." 17 | echo "kconfig-frontends can be downloaded and installed automatically." 18 | echo "kconfig-frontends depends on (at least) autoconf, automake, bison," 19 | echo "curl, flex, gperf, libtoolize, libncurses5-dev, m4, and pkg-config." 20 | echo "It will be installed to $INSTALL." 21 | 22 | read -p "Download and install? (y/n) " response 23 | 24 | if [ $response != "y" ] 25 | then 26 | echo "Canceling build" 27 | exit 1 28 | fi 29 | 30 | if [ -e $INSTALL ] 31 | then 32 | echo "$INSTALL already exists. It must be deleted to continue." 33 | read -p "Delete it and continue? (y/n) " response 34 | if [ $response != "y" ] 35 | then 36 | echo "Canceling build" 37 | exit 1 38 | fi 39 | 40 | echo "Removing $INSTALL" 41 | rm -r $INSTALL 42 | fi 43 | 44 | # Continue with download and install 45 | 46 | ARCHIVE=$INSTALL/kconfig-frontends.tar.bz2 47 | 48 | echo "Creating installation directory" 49 | mkdir -p $INSTALL 50 | cd $INSTALL 51 | 52 | echo "Downloading kconfig-frontends to $ARCHIVE" 53 | curl $URL > $ARCHIVE 54 | 55 | echo "Extracting kconfig-frontends archive" 56 | tar xjf $ARCHIVE --strip-components=1 # Strip leading directory from archive 57 | 58 | echo "Configuring kconfig-frontends" 59 | ./bootstrap 60 | ./configure --disable-shared --enable-static --disable-gconf --disable-qconf --disable-utils 61 | 62 | echo "Building kconfig-frontends" 63 | make 64 | 65 | echo "Removing archive" 66 | rm $ARCHIVE 67 | -------------------------------------------------------------------------------- /tools/build_memory.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Generate LD MEMORY command based on FDT memory node. 4 | # See https://sourceware.org/binutils/docs/ld/MEMORY.html for command 5 | # documentation. 6 | 7 | set -e 8 | 9 | # $1 = dtb name 10 | # $2 = region name 11 | output_region() { 12 | local dtb="$1" 13 | local region="$2" 14 | local attr reg addr len 15 | 16 | attr=$(fdtget ${dtb} /memory/${region} attr) 17 | reg=($(fdtget ${dtb} /memory/${region} reg)) 18 | addr=${reg[0]} 19 | len=${reg[1]} 20 | 21 | printf "\t%s (%s) : ORIGIN = %#x, LENGTH = %#x\n" "${region}" "${attr}" "${addr}" "${len}" 22 | } 23 | 24 | if (( $# != 1 )); then 25 | echo "Usage: $0
" 26 | exit $E_BADARGS 27 | fi 28 | 29 | dtb="$1" 30 | 31 | memory_regions=$(fdtget -l ${dtb} /memory) 32 | 33 | echo "/*" 34 | echo " * Automatically generated" 35 | echo " * DO NOT EDIT" 36 | echo " */" 37 | echo 38 | 39 | echo "MEMORY {" 40 | for region in ${memory_regions}; do 41 | output_region ${dtb} ${region} 42 | done 43 | echo "}" 44 | -------------------------------------------------------------------------------- /tools/common.mk: -------------------------------------------------------------------------------- 1 | # Determine relative path of file from project base 2 | # readlink to ensure folder is canonical 3 | # $(1) = File to get relative path of 4 | define relative_path 5 | $(subst $(BASE)/,,$(shell $(READLINK) -m "$(1)")) 6 | endef 7 | 8 | RELATIVE_CURDIR = $(call relative_path,$(CURDIR)) 9 | 10 | # Pretty print the executing command 11 | # $(1) = Command name 12 | # $(2) = Affected file 13 | define print_command 14 | $(VERBOSE)printf "%-7s %s\n" "$(1)" "$(2)" 15 | endef 16 | -------------------------------------------------------------------------------- /tools/device_tree.S: -------------------------------------------------------------------------------- 1 | /* 2 | * Build device tree source into object file. 3 | * Build with DEVICE_TREE_SOURCE defined, with quotes 4 | */ 5 | .section .dtb, "wa" 6 | .incbin DEVICE_TREE_SOURCE 7 | -------------------------------------------------------------------------------- /tools/gdb/fpu_regs.py: -------------------------------------------------------------------------------- 1 | import gdb 2 | 3 | # See ARMv7-M Architecture Reference Manual 4 | # Section C1.6 for details on the debug registers 5 | 6 | class FPU_Regs(gdb.Command): 7 | """Print ARMv7-M FPU registers.""" 8 | 9 | def __init__(self): 10 | super(FPU_Regs, self).__init__("info fpu-regs", gdb.COMMAND_DATA, gdb.COMPLETE_NONE) 11 | 12 | def invoke(self, arg, from_tty): 13 | if not arg: 14 | #s0-s31 15 | for n in range(32): 16 | self.print_reg(n) 17 | self.print_reg(0, fpscr=True) 18 | else: 19 | for a in arg.split(): 20 | if a == "fpscr": 21 | self.print_reg(0, fpscr=True) 22 | elif a[0] == 's' and int(a[1:]) >= 0 and int(a[1:]) <= 31: 23 | self.print_reg(int(a[1:])) 24 | else: 25 | print "Invalid register '%s'" % a 26 | 27 | def print_reg(self, num, fpscr=False): 28 | gdb.execute("set $data_reg = 0xE000EDF8") 29 | 30 | if fpscr: 31 | # Set debug core register selection register 32 | gdb.execute("set *0xE000EDF4 = 0x%x" % (0x21)) 33 | # Grab result from debug core register data register 34 | reg = gdb.parse_and_eval("*((unsigned int *)$data_reg)") 35 | print "{0:<15}{1:#x}\t{1:d}".format("fpscr", int(reg)) 36 | else: 37 | # Set debug core register selection register 38 | gdb.execute("set *0xE000EDF4 = 0x%x" % (0x40 + num)) 39 | # Grab result from debug core register data register 40 | reg = gdb.parse_and_eval("*((float *)$data_reg)") 41 | print "s{0:<14}{1:f}\t(raw {2})".format(num, float(reg), reg.cast(gdb.lookup_type("void").pointer())) 42 | 43 | 44 | FPU_Regs() 45 | -------------------------------------------------------------------------------- /tools/gdb/null_curr_task.py: -------------------------------------------------------------------------------- 1 | import gdb 2 | 3 | cont = True 4 | 5 | def break_handler(event): 6 | curr_task = gdb.parse_and_eval("curr_task") 7 | 8 | if curr_task == 0: 9 | cont = False 10 | print "curr_task == NULL" 11 | 12 | watch = gdb.Breakpoint("curr_task", type=gdb.BP_WATCHPOINT) 13 | 14 | # Run forever 15 | gdb.execute("set height 0") 16 | 17 | # Initialize breakpoint handler 18 | gdb.events.stop.connect(break_handler) 19 | 20 | while cont: 21 | gdb.execute("continue") 22 | -------------------------------------------------------------------------------- /tools/gdb/print_buddy.py: -------------------------------------------------------------------------------- 1 | import gdb 2 | 3 | class Print_Buddy(gdb.Command): 4 | """Prints out an F4OS buddy in a pretty format""" 5 | 6 | def __init__(self): 7 | super(Print_Buddy, self).__init__("print-buddy", gdb.COMMAND_DATA, gdb.COMPLETE_SYMBOL) 8 | 9 | def invoke(self, arg, from_tty): 10 | buddy = gdb.parse_and_eval(arg) 11 | self.print_buddy(buddy) 12 | 13 | def print_buddy(self, buddy): 14 | for i in range(buddy['min_order'], buddy['max_order']+1): 15 | heapnode = buddy['list'][i] 16 | if heapnode: 17 | print "Order %d:" % i, 18 | self.print_heapnode(heapnode) 19 | else: 20 | print "Order %d: NULL" % i 21 | 22 | def print_heapnode(self, heapnode): 23 | print heapnode, "(%d)" % heapnode['header']['order'], "->", 24 | while heapnode['next']: 25 | heapnode = heapnode['next'] 26 | print heapnode, "(%d)" % heapnode['header']['order'], "->", 27 | print "NULL" 28 | 29 | Print_Buddy() 30 | -------------------------------------------------------------------------------- /tools/gdb/print_list.py: -------------------------------------------------------------------------------- 1 | import gdb 2 | 3 | class Print_List(gdb.Command): 4 | """Prints out an F4OS linked list in a pretty format""" 5 | 6 | def __init__(self): 7 | super(Print_List, self).__init__("print-list", gdb.COMMAND_DATA, gdb.COMPLETE_SYMBOL) 8 | 9 | def invoke(self, arg, from_tty): 10 | head = gdb.parse_and_eval(arg) 11 | self.print_list(head) 12 | 13 | def print_list(self, head): 14 | malformed = False 15 | seen = [] 16 | 17 | print "%x ->" % head.address, 18 | 19 | node = head['next'] 20 | seen.append(node) 21 | 22 | while node != head.address: 23 | print "%x ->" % node, 24 | node = node['next'] 25 | 26 | if node in seen: 27 | malformed = True 28 | break 29 | 30 | seen.append(node) 31 | 32 | print "%x" % node 33 | 34 | if malformed: 35 | print "(Loop detected. Malformed list?)" 36 | 37 | Print_List() 38 | -------------------------------------------------------------------------------- /tools/submake.mk: -------------------------------------------------------------------------------- 1 | # Error if obj wasn't passed in, 2 | # and there isn't a custom goal declared 3 | ifndef MAKECMDGOALS 4 | ifndef obj 5 | $(error submake obj not specified) 6 | endif 7 | endif 8 | 9 | include $(BASE)/tools/common.mk 10 | 11 | .DEFAULT_GOAL := $(obj) 12 | 13 | obj_prefix := $(basename $(obj))_ 14 | 15 | # Only build "yes" conditional sources 16 | SRCS += $(SRCS_y) 17 | 18 | OBJS := $(patsubst %.c, %.o, $(filter %.c, $(SRCS))) # Add C files 19 | OBJS += $(patsubst %.S, %.o, $(filter %.S, $(SRCS))) # Add ASM files 20 | OBJS := $(addprefix $(obj_prefix), $(OBJS)) # Add output prefix 21 | 22 | # Only build "yes" conditional directories 23 | DIRS += $(DIRS_y) 24 | 25 | # Convert DIR into matching .o file 26 | # First removes slashes, then adds 27 | # prefix, which includes the current obj 28 | # name, then adds .o 29 | dir_obj = $(addsuffix .o,\ 30 | $(addprefix $(obj_prefix),\ 31 | $(subst /,,$(1)))) 32 | 33 | # Create a compilation rule for directory 34 | # $(1) = Directory 35 | # $(2) = Directory obj to create 36 | define define_compile_rules 37 | $(2): .FORCE 38 | $(call print_command,"MAKE",$(call relative_path,$(1))/) 39 | $(VERBOSE)+$(MAKE) -C $(1) obj=$(2) 40 | endef 41 | 42 | # Create rule for each directory 43 | $(foreach DIR, $(DIRS), $(eval $(call define_compile_rules,$(DIR),$(call dir_obj, $(DIR))))) 44 | 45 | # All of the directory object files 46 | DIR_OBJS := $(foreach DIR, $(DIRS), $(call dir_obj, $(DIR))) 47 | 48 | ifeq ($(strip $(OBJS)$(DIR_OBJS)),) 49 | # Nothing to build! Generate an empty object 50 | $(obj): 51 | $(call print_command,"LD",$(call relative_path,$@)) 52 | $(VERBOSE)echo "" | $(CC) -c -xc $(CFLAGS) -o $@ - 53 | else 54 | # Actual directory obj rule 55 | # Links all source and subdirectory objects 56 | $(obj): $(OBJS) $(DIR_OBJS) 57 | $(call print_command,"LD",$(call relative_path,$@)) 58 | $(VERBOSE)$(LD) -r $^ -o $@ 59 | endif 60 | 61 | include $(BASE)/tools/build.mk 62 | -------------------------------------------------------------------------------- /usr/Makefile: -------------------------------------------------------------------------------- 1 | DIRS += $(USR)/ 2 | 3 | include $(BASE)/tools/submake.mk 4 | -------------------------------------------------------------------------------- /usr/shell/Makefile: -------------------------------------------------------------------------------- 1 | SRCS += main.c 2 | SRCS += shell.c 3 | SRCS += ipctest.c 4 | SRCS += top.c 5 | SRCS += uname.c 6 | SRCS += rd_test.c 7 | SRCS += getchar.c 8 | SRCS += shared_deq_test.c 9 | SRCS += list_test.c 10 | SRCS += system_ctl.c 11 | SRCS += device_lookup.c 12 | SRCS += uart.c 13 | SRCS += char_dev.c 14 | 15 | SRCS_$(CONFIG_ACCELEROMETERS) += accel.c 16 | SRCS_$(CONFIG_BAROMETERS) += baro.c 17 | SRCS_$(CONFIG_GYROSCOPES) += gyro.c 18 | SRCS_$(CONFIG_MAGNETOMETERS) += mag.c 19 | SRCS_$(CONFIG_ROTARY_ENCODERS) += rotary_encoder.c 20 | SRCS_$(CONFIG_HAVE_LED) += blink.c 21 | SRCS_$(CONFIG_MM_PROFILING) += mem_perf.c 22 | SRCS_$(CONFIG_PWM_CLASS) += pwm.c 23 | SRCS_$(CONFIG_ADC_CLASS) += adc.c 24 | 25 | # Date and rev for uname 26 | DATE := "$(shell date -u)" 27 | SHA := $(shell git log HEAD -n 1 --format='%h') 28 | DIRTY := $(strip $(shell git status --porcelain | wc -c)) 29 | CFLAGS += -D BUILD_TIME='$(DATE)' -D BUILD_SHA='"$(SHA)"' -D BUILD_DIRTY=$(DIRTY) 30 | 31 | include $(BASE)/tools/submake.mk 32 | -------------------------------------------------------------------------------- /usr/shell/app.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #ifndef USR_SHELL_APP_H_INCLUDED 24 | #define USR_SHELL_APP_H_INCLUDED 25 | 26 | #include 27 | 28 | typedef struct command { 29 | char *name; 30 | void (*fptr)(int, char **); 31 | int len; 32 | } command_t; 33 | 34 | #define DEFINE_APP(fn) \ 35 | struct command _shell_app_##fn LINKER_ARRAY_ENTRY(shell_apps) = {\ 36 | .name = #fn, \ 37 | .fptr = fn, \ 38 | .len = sizeof(#fn)-1 \ 39 | }; 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /usr/shell/char_dev.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #ifndef USR_SHELL_CHAR_DEV_H_INCLUDED 24 | #define USR_SHELL_CHAR_DEV_H_INCLUDED 25 | 26 | #include 27 | 28 | /* 29 | * Infinite char_device passthrough 30 | * 31 | * All bytes read from stdin are written to device. 32 | * All bytes read from device are written to stdout. 33 | * 34 | * Returns only on error. 35 | */ 36 | void char_passthrough(struct char_device *dev); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /usr/shell/device_lookup.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | const char *device_auto_lookup(struct class *class) { 29 | const char *driver = NULL; 30 | int total; 31 | 32 | /* Hopefully, there is only one driver */ 33 | total = device_list_class(class, &driver, 1); 34 | if (total < 1) { 35 | printf("Error: No devices found.\r\n"); 36 | return NULL; 37 | } 38 | else if (total > 1) { 39 | const char *names[total]; 40 | /* Now, get all of the drivers */ 41 | total = device_list_class(class, names, total); 42 | 43 | printf("Multiple devices found:\r\n"); 44 | for (int i = 0; i < total; i++) { 45 | printf("* %s\r\n", names[i]); 46 | } 47 | 48 | return NULL; 49 | } 50 | 51 | return driver; 52 | } 53 | -------------------------------------------------------------------------------- /usr/shell/device_lookup.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #ifndef USR_SHELL_DEVICE_LOOKUP_H_INCLUDED 24 | #define USR_SHELL_DEVICE_LOOKUP_H_INCLUDED 25 | 26 | /* 27 | * Lookup default class device, or print options 28 | * 29 | * If there is only one device available in the class, return 30 | * the name of that device. If there are no devices available, 31 | * print an error. If multiple are available, print all options. 32 | * 33 | * @param class Class to lookup devices in 34 | * @returns name of only device in class, or NULL when error or options 35 | * printed 36 | */ 37 | const char *device_auto_lookup(struct class *class); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /usr/shell/getchar.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include "app.h" 27 | 28 | /* Get a number of characters */ 29 | void getchar(int argc, char **argv) { 30 | int num_chars = 1; 31 | if (argc > 1) { 32 | num_chars = atoi(argv[1]); 33 | } 34 | printf("Getting %d char%s\r\n", num_chars, num_chars > 1 ? "s" : ""); 35 | for (int i = 0; i < num_chars; i++) { 36 | int c = getc(); 37 | printf("\t%d: 0x%x %d\r\n", i, c, c); 38 | } 39 | } 40 | DEFINE_APP(getchar) 41 | -------------------------------------------------------------------------------- /usr/shell/ipctest.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013, 2014 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include "app.h" 29 | 30 | static struct char_device *shared_mem; 31 | 32 | void memreader(void); 33 | 34 | void ipctest(int argc, char **argv) { 35 | if (argc != 1) { 36 | printf("Usage: %s\n", argv[0]); 37 | return; 38 | } 39 | 40 | shared_mem = shared_mem_create(); 41 | if (!shared_mem) { 42 | printf("Error: unable to open shared mem.\r\n"); 43 | return; 44 | } 45 | 46 | /* Make a second reservation for the other task */ 47 | obj_get(&shared_mem->obj); 48 | 49 | printf("WRITING MEM.\r\n"); 50 | 51 | fputs(shared_mem, "THIS IS A TEST OF SHARED MEMORY REGIONS N STUFF."); 52 | 53 | printf("READING MEM.\r\n"); 54 | new_task(&memreader, 5, 0); 55 | 56 | obj_put(&shared_mem->obj); 57 | } 58 | DEFINE_APP(ipctest) 59 | 60 | void memreader(void) { 61 | char buf[16]; 62 | 63 | read(shared_mem, buf, 10); 64 | buf[10] = 0x00; 65 | 66 | puts(buf); 67 | 68 | obj_put(&shared_mem->obj); 69 | } 70 | -------------------------------------------------------------------------------- /usr/shell/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | /* The main function in this file is called by the scheduler 24 | * before beginning task switching. The end user should use 25 | * this function to create tasks that should run at boot, or 26 | * to perform any other actions that need to take place at the 27 | * end of boot. 28 | * 29 | * main() is defined in kernel/sched.h */ 30 | 31 | #include 32 | 33 | #include "shell.h" 34 | 35 | void main(void) { 36 | new_task(&shell, 1, 0); 37 | } 38 | -------------------------------------------------------------------------------- /usr/shell/mem_perf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include "app.h" 29 | 30 | #define ITERATIONS 10 31 | 32 | void mem_perf(int argc, char **argv) { 33 | uint32_t times[ITERATIONS]; 34 | uint32_t total; 35 | 36 | printf("ALLOCATOR BENCHMARKS\r\n"); 37 | 38 | for(int n = CONFIG_MM_USER_MIN_ORDER; n < CONFIG_MM_USER_MAX_ORDER; n++) { 39 | total = 0; 40 | uint32_t blocksize = pow(2, n); 41 | printf("Basic alloc %d bytes\r\n", blocksize); 42 | for(int i = 0; i < ITERATIONS; i++) { 43 | void *stuff = malloc(blocksize); 44 | if (!stuff) { 45 | printf("Warning: no memory available\r\n"); 46 | } 47 | else { 48 | free(stuff); 49 | } 50 | 51 | times[i] = (uint32_t)(end_malloc_timestamp - begin_malloc_timestamp); 52 | total += times[i]; 53 | #ifdef VERBOSE 54 | printf("--Time Delta %d = %u\r\n", i, times[i]); 55 | #endif 56 | } 57 | printf("--Average time %fus\r\n", (total/((float)ITERATIONS))/(CONFIG_SYS_CLOCK/1e6)); 58 | } 59 | } 60 | DEFINE_APP(mem_perf) 61 | -------------------------------------------------------------------------------- /usr/shell/rd_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | 25 | #include "app.h" 26 | 27 | void rd_test(int argc, char **argv) { 28 | char c; 29 | 30 | fprintf(stderr, "Press q to quit.\r\n"); 31 | 32 | while (1) { 33 | c = fgetc(stderr); 34 | 35 | if (c == 'q') { 36 | return; 37 | } 38 | 39 | fputc(stderr, c); 40 | } 41 | } 42 | DEFINE_APP(rd_test) 43 | -------------------------------------------------------------------------------- /usr/shell/shell.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #ifndef USR_SHELL_SHELL_H_INCLUDED 24 | #define USR_SHELL_SHELL_H_INCLUDED 25 | 26 | void shell(void); 27 | void help(int argc, char **argv); 28 | void history(int argc, char **argv); 29 | 30 | #define SHELL_BUF_MAX 256 31 | #define SHELL_ARG_BUF_MAX 256 32 | #define SHELL_PROMPT "$ " 33 | #define SHELL_PROMPT_LEN (2) // strlen(SHELL_PROMPT) 34 | #define SHELL_HISTORY (10) // Command history length 35 | 36 | #define CLEARLINE "\e[K" 37 | #define RIGHT "\e[C" 38 | #define LEFT "\e[D" 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /usr/shell/top.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013, 2014 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include "app.h" 28 | 29 | /* Display memory usage */ 30 | void top(int argc, char **argv) { 31 | printf("User free memory: %d bytes\r\n", mm_space()); 32 | printf("Kernel free memory: %d bytes\r\n", mm_kspace()); 33 | } 34 | DEFINE_APP(top) 35 | -------------------------------------------------------------------------------- /usr/shell/uname.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include "shell.h" 26 | #include "app.h" 27 | 28 | #if BUILD_DIRTY 29 | #define DIRTY_MESSAGE "~dirty" 30 | #else 31 | #define DIRTY_MESSAGE "" 32 | #endif 33 | 34 | void uname(int argc, char **argv) { 35 | if (argc > 1) { 36 | if (!strncmp(argv[1], "-a", SHELL_ARG_BUF_MAX)) { 37 | printf("F4OS build %s%s %s/%s %s\r\n", BUILD_SHA, DIRTY_MESSAGE, 38 | CONFIG_ARCH, CONFIG_CHIP, BUILD_TIME); 39 | } 40 | else if (!strncmp(argv[1], "-m", SHELL_ARG_BUF_MAX)) { 41 | printf("%s/%s\r\n", CONFIG_ARCH, CONFIG_CHIP); 42 | } 43 | else if (!strncmp(argv[1], "-r", SHELL_ARG_BUF_MAX)) { 44 | printf("build %s%s\r\n", BUILD_SHA, DIRTY_MESSAGE); 45 | } 46 | else { 47 | printf("%s: unrecognized option '%s'\r\n", argv[0], argv[1]); 48 | } 49 | } 50 | else { 51 | puts("F4OS\r\n"); 52 | } 53 | } 54 | DEFINE_APP(uname) 55 | -------------------------------------------------------------------------------- /usr/tests/Makefile: -------------------------------------------------------------------------------- 1 | SRCS += main.c 2 | SRCS += task_creation.c 3 | SRCS += string.c 4 | SRCS += stdlib.c 5 | SRCS += mm.c 6 | SRCS += cooperate.c 7 | SRCS += shared_mem.c 8 | SRCS += buf_stream.c 9 | SRCS += regression.c 10 | SRCS += init.c 11 | SRCS += mutex.c 12 | 13 | include $(BASE)/tools/submake.mk 14 | -------------------------------------------------------------------------------- /usr/tests/cooperate.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include "test.h" 26 | 27 | volatile task_t *t1 = NULL; 28 | volatile task_t *t2 = NULL; 29 | 30 | volatile int t1_done = 0; 31 | volatile int t2_done = 0; 32 | 33 | static void task1(void) { 34 | while (!t2); 35 | 36 | do { 37 | task_switch((task_t *)t2); 38 | } while (!t2_done); 39 | 40 | t1_done = 1; 41 | } 42 | 43 | static void task2(void) { 44 | t2_done = 1; 45 | } 46 | 47 | static int cooperative_task_test(char *message, int len) { 48 | /* Make the tasks priority 0, so that they will 49 | * never be preemptively scheduled */ 50 | t1 = new_task(&task1, 0, 0); 51 | t2 = new_task(&task2, 0, 0); 52 | 53 | int count = 1 << 20; 54 | 55 | /* Continuously switch to task until it finishes */ 56 | do { 57 | task_switch((task_t *)t1); 58 | } while (!t1_done && count--); 59 | 60 | if (count <= 0) { 61 | return FAILED; 62 | } 63 | 64 | return PASSED; 65 | } 66 | DEFINE_TEST("Cooperative task switching", cooperative_task_test); 67 | -------------------------------------------------------------------------------- /usr/tests/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include "test.h" 28 | 29 | LINKER_ARRAY_DECLARE(tests) 30 | 31 | #define MESSAGE_LEN 128 32 | 33 | void run_tests(void) { 34 | struct test *test; 35 | int failures = 0; 36 | 37 | /* Wait for stdin/stdout - getc returns a negative error when it is not connected. */ 38 | while (getc() < 0); 39 | 40 | LINKER_ARRAY_FOR_EACH(tests, test) { 41 | char message[MESSAGE_LEN] = {'\0'}; 42 | 43 | printf("Test '%s'...", test->name); 44 | 45 | /* Call test, but don't allow the last byte in 46 | * message to be set */ 47 | int ret = test->func(message, sizeof(message)-1); 48 | 49 | if (ret) { 50 | failures++; 51 | 52 | printf("FAILED"); 53 | 54 | if (message[0]) { 55 | printf(" - '%s'\r\n", message); 56 | } 57 | else { 58 | printf("\r\n"); 59 | } 60 | } 61 | else { 62 | printf("PASSED\r\n"); 63 | } 64 | } 65 | 66 | printf("%d total failures\r\n", failures); 67 | } 68 | 69 | void main(void) { 70 | new_task(&run_tests, 1, 0); 71 | } 72 | -------------------------------------------------------------------------------- /usr/tests/regression.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include "test.h" 26 | 27 | /* strreverse would always skip the first byte when searching for the 28 | * end of the str, causing it to overflow when given a string containing 29 | * only a NULL byte */ 30 | int strreverse_buffer_overflow(char *message, int len) { 31 | char buf[] = {'\0', 'a', 'b', '\0'}; 32 | 33 | strreverse(buf); 34 | 35 | if (buf[0] != '\0') { 36 | scnprintf(message, len, "buffer NULL overwritten"); 37 | return FAILED; 38 | } 39 | 40 | if (buf[1] != 'a' || buf[2] != 'b') { 41 | scnprintf(message, len, "buffer contents overwritten"); 42 | return FAILED; 43 | } 44 | 45 | return PASSED; 46 | } 47 | DEFINE_TEST("strreverse buffer overflow", strreverse_buffer_overflow); 48 | -------------------------------------------------------------------------------- /usr/tests/task_creation.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include "test.h" 26 | 27 | volatile int task_created = 0; 28 | 29 | static void basic_task(void) { 30 | task_created = 1; 31 | } 32 | 33 | int task_creation(char *message, int len) { 34 | new_task(&basic_task, 5, 0); 35 | 36 | /* Wait a while for task to be created */ 37 | int count = 100000; 38 | while (count-- && !task_created); 39 | 40 | if (task_created) { 41 | return PASSED; 42 | } 43 | 44 | strncpy(message, "Task creation timed out", len); 45 | return FAILED; 46 | } 47 | DEFINE_TEST("Task creation", task_creation); 48 | -------------------------------------------------------------------------------- /usr/tests/test.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 F4OS Authors 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #ifndef USR_TEST_TEST_H_INCLUDED 24 | #define USR_TEST_TEST_H_INCLUDED 25 | 26 | #include 27 | 28 | /* Tests return 0 on pass, else on error. 29 | * The first arguement is a buffer to copy 30 | * an error message into, whose length is the 31 | * second arguement */ 32 | struct test { 33 | char *name; 34 | int (*func)(char *, int); 35 | }; 36 | 37 | /* Create a test with name nm using function f */ 38 | #define DEFINE_TEST(nm, f) \ 39 | struct test _test_##f LINKER_ARRAY_ENTRY(tests) = {\ 40 | .name = nm, \ 41 | .func = f \ 42 | }; 43 | 44 | /* Standard test return codes */ 45 | enum { 46 | PASSED = 0, 47 | FAILED, 48 | }; 49 | 50 | #define ARRAY_LENGTH(array) (sizeof(array)/sizeof(array[0])) 51 | 52 | #endif 53 | --------------------------------------------------------------------------------