├── BUCK ├── doc └── .gitignore ├── src ├── auth │ ├── auth_boot_event.c │ ├── CMakeLists.txt │ └── BUCK ├── device │ ├── drive_mcu_flash.c │ ├── urandom.c │ ├── zero.c │ ├── null.c │ ├── full.c │ ├── i2s_spi_ffifo.c │ ├── drive_sdssp.c │ ├── drive_sdspi_dma.c │ ├── drive_mmc_dma.c │ ├── CMakeLists.txt │ ├── drive_sdio_dma.c │ ├── tty_usbbulk.c │ ├── BUCK │ └── reset_tmr.c ├── sys │ ├── pthread │ │ ├── pthread_rwlockattr.c │ │ ├── pthread_rwlock.c │ │ ├── pthread_mutex_local.h │ │ ├── pthread_self.c │ │ ├── pthread_cleanup.c │ │ ├── pthread_mutex_init.c │ │ └── pthread_mutexattr_init.c │ ├── sffs │ │ ├── test_dir.c │ │ ├── Makefile.am │ │ ├── configure.ac │ │ ├── sffs_dir.h │ │ ├── sffs_tp.h │ │ ├── tests.h │ │ └── sffs_diag.h │ ├── signal │ │ ├── sigset.c │ │ └── _kill.c │ ├── scheduler │ │ ├── scheduler_flags.h │ │ ├── scheduler_fault.h │ │ ├── scheduler_root.c │ │ └── scheduler.h │ ├── symbols.c │ ├── unistd │ │ ├── unistd_fs.h │ │ ├── _execve.c │ │ ├── _getppid.c │ │ ├── _getpid.c │ │ ├── _unlink.c │ │ ├── crypt.c │ │ ├── _isatty.c │ │ ├── rmdir.c │ │ ├── chmod.c │ │ ├── chown.c │ │ ├── _fstat.c │ │ ├── lstat.c │ │ ├── _stat.c │ │ ├── mkdir.c │ │ ├── _rename.c │ │ ├── _symlink.c │ │ ├── _link.c │ │ ├── _close.c │ │ ├── fsync.c │ │ ├── _fork.c │ │ ├── access.c │ │ └── ioctl.c │ ├── malloc │ │ ├── mlock.c │ │ ├── realloc.c │ │ ├── _calloc.c │ │ ├── malloc_stats.c │ │ ├── malloc_local.h │ │ ├── mallinfo.c │ │ └── calloc.c │ ├── symbols.h │ ├── process │ │ ├── process_start.h │ │ └── _system.c │ ├── termios │ │ ├── termios.c │ │ └── termios_local.h │ ├── sysfs │ │ └── devfs_local.h │ ├── time │ │ └── _itimer.c │ ├── check_config.h │ ├── assert_func.c │ ├── sos_led.c │ ├── sos_led_root.c │ ├── pwd │ │ └── pwd.c │ ├── sos_interrupt_handlers.c │ └── grp │ │ └── grp.c ├── BUCK ├── mcu │ ├── CMakeLists.txt │ ├── eint.c │ ├── eeprom.c │ ├── dac.c │ ├── dac_dma.c │ ├── BUCK │ ├── core.c │ ├── emc.c │ ├── enet.c │ ├── mci.c │ ├── adc.c │ ├── i2c.c │ ├── spi.c │ ├── ssp.c │ ├── usb.c │ ├── rtc.c │ ├── spi_dma.c │ ├── i2s.c │ ├── i2s_spi.c │ ├── qei.c │ ├── uart.c │ ├── i2s_spi_dma.c │ ├── mem.c │ ├── pio.c │ ├── pwm.c │ ├── tmr.c │ ├── flash.c │ ├── mcu_sync_io.c │ └── sys.c ├── crt │ ├── CMakeLists.txt │ ├── operator.cpp │ ├── BUCK │ ├── crt_common.h │ └── crt.c ├── boot │ ├── CMakeLists.txt │ ├── BUCK │ ├── boot_config.h │ └── boot_interrupt_handlers.c ├── link │ ├── CMakeLists.txt │ ├── BUCK │ ├── link_stdio.c │ ├── link_debug.c │ └── link_time.c ├── cortexm │ ├── CMakeLists.txt │ ├── fault_local.h │ ├── util.c │ ├── cortexm_local.h │ ├── BUCK │ ├── task_process.c │ └── auth.c ├── CMakeLists.txt ├── usbd │ ├── CMakeLists.txt │ ├── usbd_standard.h │ └── BUCK ├── link_transport │ ├── CMakeLists.txt │ ├── BUCK │ └── link_transport_slave.c ├── library.bzl └── sos_config_template.h ├── include ├── device │ ├── drive_mcu_flash.h │ ├── README.md │ ├── drive_ram.h │ ├── null.h │ ├── full.h │ ├── CMakeLists.txt │ ├── urandom.h │ ├── random.h │ ├── reset_tmr.h │ ├── led_pio.h │ ├── zero.h │ ├── devfifo.h │ ├── led_pwm.h │ ├── tty.h │ ├── drive_mmc.h │ ├── auth_flash.h │ ├── drive_sdio.h │ ├── sys.h │ ├── auth.h │ ├── netif_eth.h │ └── drive_device.h ├── posix │ ├── sys │ │ ├── socket.h.gch │ │ ├── ioctl.h │ │ ├── select.h │ │ └── dirent.h │ ├── README.md │ ├── CMakeLists.txt │ ├── netinet │ │ └── in.h │ ├── semaphore.h │ └── arpa │ │ └── inet.h ├── cortexm │ ├── util.h │ ├── CMakeLists.txt │ └── README.md ├── usbd │ ├── CMakeLists.txt │ └── README.md ├── mcu │ ├── cfi.h │ ├── CMakeLists.txt │ ├── can.h │ ├── periph.h │ ├── wdt.h │ ├── crypt.h │ ├── hash.h │ ├── mci.h │ ├── eeprom.h │ ├── rng.h │ ├── eint.h │ ├── adc.h │ ├── ltdc.h │ ├── qspi.h │ ├── rtc.h │ ├── crc.h │ ├── eth.h │ ├── qei.h │ ├── ohci.h │ ├── mmc.h │ ├── pio.h │ ├── emc.h │ ├── sdio.h │ ├── flash.h │ └── usb.h ├── sos │ ├── api │ │ ├── crypt_api.h │ │ ├── sos_api.h │ │ └── README.md │ ├── power.h │ ├── fs.h │ ├── led.h │ ├── dev │ │ ├── usbfifo.h │ │ ├── uartfifo.h │ │ ├── eeprom.h │ │ ├── i2s_ffifo.h │ │ ├── device_fifo.h │ │ └── tty.h │ ├── boot │ │ └── bootloader.h │ ├── arch │ │ └── delay_cm.h │ ├── ioctl.h │ └── trace.h ├── README.md └── CMakeLists.txt ├── spaces_deps.toml ├── .gitignore ├── StratifyOS_crt.cmake ├── CMakeLists.txt ├── StratifyOS.cmake ├── cmake └── generate_sources.cmake ├── create-gcc-hard.cmake ├── link.cmake ├── ldscript └── common.ld ├── .github └── workflows │ └── build.yml ├── README.md └── guides └── Porting.md /BUCK: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /doc/.gitignore: -------------------------------------------------------------------------------- 1 | /xml 2 | -------------------------------------------------------------------------------- /src/auth/auth_boot_event.c: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/device/drive_mcu_flash.c: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /include/device/drive_mcu_flash.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /include/posix/sys/socket.h.gch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StratifyLabs/StratifyOS/HEAD/include/posix/sys/socket.h.gch -------------------------------------------------------------------------------- /src/sys/pthread/pthread_rwlockattr.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | -------------------------------------------------------------------------------- /spaces_deps.toml: -------------------------------------------------------------------------------- 1 | [deps.SDK] 2 | git = "https://github.com/StratifyLabs/SDK" 3 | rev = "1f17fb0c6b4fc56f3c430a7390daa16a12c8a892" 4 | branch = "main" -------------------------------------------------------------------------------- /src/sys/sffs/test_dir.c: -------------------------------------------------------------------------------- 1 | /* 2 | * test_dir.c 3 | * 4 | * Created on: Jun 14, 2012 5 | * Author: tgil 6 | */ 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.a 2 | *.d 3 | *.o 4 | *.user 5 | cmake_* 6 | *.gch 7 | *.8-pre1 8 | .vscode/ 9 | doc/StratifyOS/ 10 | build/ 11 | doc/StratifyOS.tag 12 | -------------------------------------------------------------------------------- /src/sys/signal/sigset.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | 5 | 6 | #include 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/BUCK: -------------------------------------------------------------------------------- 1 | 2 | 3 | cxx_library( 4 | name = "config", 5 | exported_headers = ["config.h"], 6 | header_namespace = "", 7 | visibility = ["PUBLIC"] 8 | ) -------------------------------------------------------------------------------- /src/mcu/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | if( ${CMSDK_BUILD_CONFIG} STREQUAL arm ) 4 | set(SOURCES 5 | mcu_sync_io.c 6 | mcu.c 7 | PARENT_SCOPE) 8 | endif() 9 | -------------------------------------------------------------------------------- /include/cortexm/util.h: -------------------------------------------------------------------------------- 1 | #ifndef CORTEXM_UTIL_H 2 | #define CORTEXM_UTIL_H 3 | 4 | void htoa(char *dest, int num); 5 | char htoc(int nibble); 6 | 7 | #endif // CORTEXM_UTIL_H 8 | -------------------------------------------------------------------------------- /StratifyOS_crt.cmake: -------------------------------------------------------------------------------- 1 | if(CMSDK_IS_ARM) 2 | set(STRATIFYOS_CMAKE_CONFIG_LIST release debug) 3 | cmsdk_include_target(StratifyOS_crt "${STRATIFYOS_CMAKE_CONFIG_LIST}") 4 | endif() 5 | -------------------------------------------------------------------------------- /include/cortexm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(SOURCES 3 | cortexm.h 4 | fault.h 5 | mpu.h 6 | task.h 7 | util.h 8 | task_table.h 9 | task_types.h 10 | PARENT_SCOPE) 11 | -------------------------------------------------------------------------------- /src/auth/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | if (${CMSDK_BUILD_CONFIG} STREQUAL arm) 3 | set(SOURCELIST 4 | auth_pure_code.c) 5 | endif () 6 | 7 | set(SOURCES ${SOURCELIST} PARENT_SCOPE) 8 | -------------------------------------------------------------------------------- /include/device/README.md: -------------------------------------------------------------------------------- 1 | # device API 2 | 3 | These are compound system devices that usually rely on microcontroller peripherals to perform a higher level function like an [SD Card SPI driver](drive_sdspi.h). -------------------------------------------------------------------------------- /include/usbd/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(SOURCES 3 | adc.h 4 | cdc.h 5 | control.h 6 | defines.h 7 | dfu.h 8 | hid.h 9 | msc_scsi.h 10 | msc.h 11 | msft.h 12 | types.h 13 | PARENT_SCOPE) 14 | -------------------------------------------------------------------------------- /include/posix/README.md: -------------------------------------------------------------------------------- 1 | # posix 2 | 3 | The header files here represent a subset of the POSIX functions that are available in Stratify OS. The rest of the POSIX functionality is declared in `newlib` header files. -------------------------------------------------------------------------------- /include/mcu/cfi.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #ifndef DEV_CFI_H_ 4 | #define DEV_CFI_H_ 5 | 6 | 7 | 8 | 9 | 10 | #endif /* DEV_CFI_H_ */ 11 | 12 | -------------------------------------------------------------------------------- /include/usbd/README.md: -------------------------------------------------------------------------------- 1 | # usbd 2 | 3 | These headers primarily contain standard USB definitions. These structures are used to customize the USB desriptions for a board. 4 | 5 | They are not used for application development. -------------------------------------------------------------------------------- /include/posix/sys/ioctl.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #ifndef _SYS_IOCTL_H_ 4 | #define _SYS_IOCTL_H_ 5 | 6 | #include "ioctl.h" 7 | 8 | #endif /* _SYS_IOCTL_H_ */ 9 | -------------------------------------------------------------------------------- /src/crt/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | if( ${CMSDK_BUILD_CONFIG} STREQUAL arm ) 4 | set(SOURCES 5 | crt_common.c 6 | crt_common.h 7 | crt_symbols.S 8 | crt.c 9 | operator.cpp 10 | PARENT_SCOPE) 11 | endif() 12 | -------------------------------------------------------------------------------- /src/mcu/eint.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | #include "sos/fs/devfs.h" 5 | #include "mcu/eint.h" 6 | 7 | DEVFS_MCU_DRIVER_IOCTL_FUNCTION_MIN(eint, EINT_VERSION) 8 | -------------------------------------------------------------------------------- /include/sos/api/crypt_api.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #ifndef SOS_API_CRYPT_API_H 4 | #define SOS_API_CRYPT_API_H 5 | 6 | #include 7 | 8 | #endif // SOS_API_CRYPT_API_H 9 | -------------------------------------------------------------------------------- /src/mcu/eeprom.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | #include "sos/fs/devfs.h" 5 | #include "mcu/eeprom.h" 6 | 7 | 8 | DEVFS_MCU_DRIVER_IOCTL_FUNCTION_MIN(eeprom, EEPROM_VERSION) 9 | 10 | -------------------------------------------------------------------------------- /src/sys/pthread/pthread_rwlock.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | //This is a mutex that can be held by any number of readers or one writer -- a writer has to wait until all readers release the mutex 5 | -------------------------------------------------------------------------------- /include/cortexm/README.md: -------------------------------------------------------------------------------- 1 | # Cortex M API 2 | 3 | The functions within the `cortexm` folder are primarily used internally to access Cortex M hardware. Feel free to per-use, but you will only use these for system development as they are not available to applications. 4 | -------------------------------------------------------------------------------- /src/auth/BUCK: -------------------------------------------------------------------------------- 1 | """ 2 | Auth library 3 | """ 4 | 5 | load("//deps/StratifyOS/src/library.bzl", "sos_library") 6 | 7 | sos_library( 8 | name = "auth", 9 | srcs = [ 10 | "auth_boot_event.c", 11 | "auth_pure_code.c", 12 | ], 13 | ) 14 | -------------------------------------------------------------------------------- /include/posix/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(SOURCES 3 | aio.h 4 | mqueue.h 5 | netdb.h 6 | semaphore.h 7 | trace.h 8 | arpa/inet.h 9 | netinet/in.h 10 | sys/dirent.h 11 | sys/ioctl.h 12 | sys/select.h 13 | sys/socket.h 14 | sys/termios.h 15 | PARENT_SCOPE) 16 | -------------------------------------------------------------------------------- /include/sos/api/sos_api.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #ifndef SOS_API_SOS_API_H 4 | #define SOS_API_SOS_API_H 5 | 6 | #include 7 | #include 8 | 9 | #endif // SOS_API_SOS_API_H 10 | -------------------------------------------------------------------------------- /include/sos/power.h: -------------------------------------------------------------------------------- 1 | #ifndef SOS_POWER_H 2 | #define SOS_POWER_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | int hibernate(int seconds); 9 | void powerdown(int seconds); 10 | 11 | #ifdef __cplusplus 12 | } 13 | #endif 14 | 15 | #endif // SOS_POWER_H 16 | -------------------------------------------------------------------------------- /src/mcu/dac.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | #include "sos/fs/devfs.h" 5 | #include "mcu/dac.h" 6 | 7 | 8 | DEVFS_MCU_DRIVER_IOCTL_FUNCTION(dac, DAC_VERSION, I_MCU_TOTAL + I_DAC_TOTAL, mcu_dac_get, mcu_dac_set) 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/sys/scheduler/scheduler_flags.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | #ifndef SCHEDULER_SCHEDULER_FLAGS_H_ 5 | #define SCHEDULER_SCHEDULER_FLAGS_H_ 6 | 7 | #include "scheduler_local.h" 8 | 9 | #endif /* SCHEDULER_SCHEDULER_FLAGS_H_ */ 10 | -------------------------------------------------------------------------------- /include/README.md: -------------------------------------------------------------------------------- 1 | # Header File Overview 2 | 3 | The `sos` and `posix` folders contains application level header files that declare functions that are generally available to Stratify OS applications. 4 | 5 | THe other folders contain headers files that are used for kernel and board support package development. -------------------------------------------------------------------------------- /src/mcu/dac_dma.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | #include "sos/fs/devfs.h" 5 | #include "mcu/dac.h" 6 | 7 | 8 | DEVFS_MCU_DRIVER_IOCTL_FUNCTION(dac_dma, DAC_VERSION, I_MCU_TOTAL + I_DAC_TOTAL, mcu_dac_dma_get, mcu_dac_dma_set) 9 | 10 | 11 | -------------------------------------------------------------------------------- /include/sos/fs.h: -------------------------------------------------------------------------------- 1 | #ifndef SOS_FS_H 2 | #define SOS_FS_H 3 | 4 | #if defined __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | int mkfs(const char *path); 9 | int mount(const char *path); 10 | int unmount(const char *path); 11 | 12 | #if defined __cplusplus 13 | } 14 | #endif 15 | 16 | #endif // SOS_FS_H 17 | -------------------------------------------------------------------------------- /src/boot/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | if( ${CMSDK_BUILD_CONFIG} STREQUAL arm ) 4 | set(SOURCES 5 | boot_config.h 6 | boot_debug.c 7 | boot_link_transport_usb.c 8 | boot_link.c 9 | boot_main.c 10 | boot_interrupt_handlers.c 11 | ../sys/sos_led_root.c 12 | PARENT_SCOPE) 13 | endif() 14 | -------------------------------------------------------------------------------- /src/mcu/BUCK: -------------------------------------------------------------------------------- 1 | """ 2 | MCU library 3 | """ 4 | 5 | load("//deps/StratifyOS/src/library.bzl", "sos_library") 6 | 7 | sos_library( 8 | name = "mcu", 9 | srcs = [ 10 | "mcu_sync_io.c", 11 | "mcu.c", 12 | ], 13 | headers = [ 14 | "variant.h", 15 | "local.h", 16 | ] 17 | ) 18 | -------------------------------------------------------------------------------- /src/mcu/core.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | #include "sos/fs/devfs.h" 5 | #include "mcu/core.h" 6 | 7 | DEVFS_MCU_DRIVER_IOCTL_FUNCTION(core, CORE_VERSION, I_MCU_TOTAL + I_CORE_TOTAL, mcu_core_setpinfunc, mcu_core_setclkout, mcu_core_setclkdivide, mcu_core_getmcuboardconfig) 8 | -------------------------------------------------------------------------------- /include/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | cmsdk_add_subdirectory(SOURCELIST cortexm) 5 | cmsdk_add_subdirectory(SOURCELIST device) 6 | cmsdk_add_subdirectory(SOURCELIST mcu) 7 | cmsdk_add_subdirectory(SOURCELIST posix) 8 | cmsdk_add_subdirectory(SOURCELIST sos) 9 | cmsdk_add_subdirectory(SOURCELIST usbd) 10 | 11 | set(SOURCES ${SOURCELIST} PARENT_SCOPE) 12 | -------------------------------------------------------------------------------- /src/link/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | if( ${CMSDK_BUILD_CONFIG} STREQUAL link ) 4 | set(SOURCES 5 | link_bootloader.c 6 | link_debug.c 7 | link_dir.c 8 | link_file.c 9 | link_phy.c 10 | link_process.c 11 | link_stdio.c 12 | link_sys_attr.c 13 | link_time.c 14 | link.c 15 | link_local.h 16 | PARENT_SCOPE) 17 | endif() 18 | -------------------------------------------------------------------------------- /include/posix/sys/select.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #ifndef SYS_SELECT_H_ 4 | #define SYS_SELECT_H_ 5 | 6 | 7 | #if !defined __link 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | 15 | #endif 16 | 17 | #endif /* SYS_SELECT_H_ */ 18 | -------------------------------------------------------------------------------- /src/cortexm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | if( ${CMSDK_BUILD_CONFIG} STREQUAL arm ) 3 | set(SOURCES 4 | cortexm_local.h 5 | cortexm.c 6 | auth.c 7 | devfs.c 8 | fault.c 9 | util.c 10 | fault_handler.c 11 | fault_local.h 12 | mpu.c 13 | task_mpu.c 14 | task_process.c 15 | task.c 16 | task_local.h 17 | PARENT_SCOPE) 18 | endif() 19 | -------------------------------------------------------------------------------- /src/crt/operator.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | #include 5 | #include 6 | 7 | extern "C" void *operator new(size_t size) { return malloc(size); } 8 | 9 | extern "C" void operator delete(void *p) { free(p); } 10 | 11 | extern "C" void operator delete(void *p, unsigned int size) { free(p); } 12 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | if( ${CMSDK_BUILD_CONFIG} STREQUAL arm ) 3 | list(APPEND SOURCELIST ${SRC_SOURCES_PREFIX}/config.h) 4 | cmsdk_add_subdirectory(SOURCELIST sys) 5 | else() 6 | cmsdk_add_subdirectory(SOURCELIST link_transport) 7 | cmsdk_add_subdirectory(SOURCELIST link) 8 | endif() 9 | 10 | set(SOURCES 11 | ${SOURCELIST} 12 | sos_config_template.h 13 | PARENT_SCOPE) 14 | -------------------------------------------------------------------------------- /include/sos/api/README.md: -------------------------------------------------------------------------------- 1 | # api 2 | 3 | The `api` folder contains built-in Stratify OS api interfaces. Other libraries may install additional api header files to augment the built-in ones. 4 | 5 | These api libraries are how Stratify OS allows multiple applications to share libraries. 6 | 7 | All api libraries should use the `sos_api_t` as the first entry in the API. See [sos api](sos_api.h) for details. -------------------------------------------------------------------------------- /src/sys/pthread/pthread_mutex_local.h: -------------------------------------------------------------------------------- 1 | #ifndef PTHREAD_MUTEX_LOCAL_H 2 | #define PTHREAD_MUTEX_LOCAL_H 3 | 4 | #include 5 | #include 6 | 7 | typedef struct { 8 | int id; 9 | pthread_mutex_t *mutex; 10 | } pthread_mutex_root_unlock_t; 11 | 12 | void pthread_mutex_root_unlock(pthread_mutex_root_unlock_t *args) MCU_ROOT_EXEC_CODE; 13 | 14 | #endif // PTHREAD_MUTEX_LOCAL_H 15 | -------------------------------------------------------------------------------- /src/usbd/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | if( ${CMSDK_BUILD_CONFIG} STREQUAL arm ) 4 | set(SOURCES 5 | usbd_control.c 6 | usbd_standard.c 7 | sos_link_transport_usb_link_descriptors.c 8 | sos_link_transport_usb_link_vcp_descriptors.c 9 | sos_link_transport_usb_vcp_descriptors.c 10 | sos_link_transport_usb_dual_vcp_descriptors.c 11 | sos_link_transport_usb.c 12 | PARENT_SCOPE) 13 | endif() 14 | -------------------------------------------------------------------------------- /src/sys/symbols.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #include "sos/symbols.h" 4 | #include "sos/symbols/table.h" 5 | 6 | void __cxa_pure_virtual() {} 7 | 8 | void __div0() { 9 | while (1) { 10 | } 11 | } 12 | 13 | u32 symbols_total() { 14 | int i; 15 | i = 0; 16 | while (symbols_table[i] != 1) { 17 | i++; 18 | } 19 | return i; 20 | } 21 | -------------------------------------------------------------------------------- /src/sys/unistd/unistd_fs.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | #ifndef UNISTD_FS_H_ 5 | #define UNISTD_FS_H_ 6 | 7 | #include "config.h" 8 | #include //Defines the flags 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "sos/fs/sysfs.h" 15 | 16 | 17 | #endif /* UNISTD_FS_H_ */ 18 | -------------------------------------------------------------------------------- /src/sys/malloc/mlock.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | void __malloc_lock(struct _reent *ptr) { 8 | pthread_mutex_lock(&(ptr->procmem_base->__malloc_lock_object)); 9 | } 10 | 11 | void __malloc_unlock(struct _reent *ptr) { 12 | pthread_mutex_unlock(&(ptr->procmem_base->__malloc_lock_object)); 13 | } 14 | -------------------------------------------------------------------------------- /src/cortexm/fault_local.h: -------------------------------------------------------------------------------- 1 | #ifndef FAULT_LOCAL_H 2 | #define FAULT_LOCAL_H 3 | 4 | #include "cortexm/fault.h" 5 | 6 | typedef struct { 7 | u32 tid; 8 | s32 free_stack_size; 9 | s32 free_heap_size; 10 | u32 pid; 11 | fault_t fault; 12 | } cortexm_fault_t; 13 | 14 | extern volatile cortexm_fault_t m_cortexm_fault MCU_SYS_MEM; 15 | extern mcu_event_handler_t m_cortexm_fault_handler MCU_SYS_MEM; 16 | 17 | #endif // FAULT_LOCAL_H 18 | -------------------------------------------------------------------------------- /src/boot/BUCK: -------------------------------------------------------------------------------- 1 | """ 2 | Boot library 3 | """ 4 | 5 | load("//deps/StratifyOS/src/library.bzl", "sos_library") 6 | 7 | sos_library( 8 | name = "boot", 9 | srcs = [ 10 | "boot_main.c", 11 | "boot_interrupt_handlers.c", 12 | "boot_debug.c", 13 | "boot_link_transport_usb.c", 14 | "boot_link.c", 15 | ], 16 | headers = [ 17 | "boot_link.h", 18 | "boot_config.h", 19 | ] 20 | ) 21 | -------------------------------------------------------------------------------- /src/sys/symbols.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #ifndef SYMBOLS_H_ 4 | #define SYMBOLS_H_ 5 | 6 | #include 7 | #include 8 | 9 | extern u32 const symbols_table[] MCU_WEAK; 10 | 11 | static inline u32 symbols_total() { 12 | int i; 13 | i = 0; 14 | while (symbols_table[i] != 1) { 15 | i++; 16 | } 17 | return i; 18 | } 19 | 20 | #endif /* SYMBOLS_H_ */ 21 | -------------------------------------------------------------------------------- /include/posix/netinet/in.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #ifndef POSIX_NETINET_IN_H_ 4 | #define POSIX_NETINET_IN_H_ 5 | 6 | /* Include the LWIP sockets header 7 | * 8 | * If LWIP isn't installed in the SDK, any apps that use netdb will get an error. 9 | * 10 | */ 11 | #if SOS_BOOTSTRAP_SOCKETS == 0 12 | #include 13 | #endif 14 | 15 | 16 | #endif /* POSIX_NETINET_IN_H_ */ 17 | -------------------------------------------------------------------------------- /src/cortexm/util.c: -------------------------------------------------------------------------------- 1 | 2 | #include "cortexm/util.h" 3 | 4 | char htoc(int nibble) { 5 | if (nibble >= 0 && nibble < 10) { 6 | return (char)nibble + '0'; 7 | } else { 8 | return (char)nibble + 'A' - 10; 9 | } 10 | } 11 | 12 | void htoa(char *dest, int num) { 13 | int i; 14 | for (i = 0; i < 8; i++) { 15 | char nibble; 16 | nibble = num & 0xF; 17 | num >>= 4; 18 | dest[7 - i] = htoc(nibble); 19 | } 20 | dest[8] = 0; 21 | } 22 | -------------------------------------------------------------------------------- /src/boot/boot_config.h: -------------------------------------------------------------------------------- 1 | #ifndef BOOT_CONFIG_H_ 2 | #define BOOT_CONFIG_H_ 3 | 4 | #include "sos/boot/bootloader.h" 5 | 6 | //version 4 will store the first page and write it after verification 7 | #define BCDVERSION 0x400 8 | 9 | //Un-comment to use UART for debugging 10 | #if defined ___debug 11 | #define DEBUG_BOOTLOADER 1 12 | #endif 13 | 14 | void delay_ms(int ms); 15 | void sos_handle_event(int event, void * args); 16 | 17 | #endif /* BOOT_CONFIG_H_ */ 18 | -------------------------------------------------------------------------------- /src/crt/BUCK: -------------------------------------------------------------------------------- 1 | """ 2 | C Runtime Library 3 | """ 4 | 5 | load("//deps/StratifyOS/src/library.bzl", "sos_library") 6 | 7 | sos_library( 8 | name = "crt", 9 | srcs = [ 10 | "crt_common.c", 11 | "crt.c", 12 | "crt_symbols.S", 13 | "operator.cpp", 14 | ], 15 | headers = [ 16 | "crt_common.h", 17 | ], 18 | deps = [ 19 | "root//deps/local/arm-none-eabi/lib/thumb/v7e-m+dp/hard:libstdcpp" 20 | ] 21 | ) 22 | -------------------------------------------------------------------------------- /src/sys/malloc/realloc.c: -------------------------------------------------------------------------------- 1 | #ifdef MALLOC_PROVIDED 2 | int _dummy_calloc = 1; 3 | #else 4 | /* realloc.c -- a wrapper for realloc_r. */ 5 | 6 | #include <_ansi.h> 7 | #include 8 | #include 9 | #include 10 | 11 | #ifndef _REENT_ONLY 12 | 13 | _PTR 14 | _DEFUN (realloc, (ap, nbytes), 15 | _PTR ap _AND 16 | size_t nbytes) 17 | { 18 | return _realloc_r (_GLOBAL_REENT, ap, nbytes); 19 | } 20 | 21 | #endif 22 | #endif /* MALLOC_PROVIDED */ 23 | -------------------------------------------------------------------------------- /src/sys/pthread/pthread_self.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup pthread 4 | * @{ 5 | */ 6 | 7 | /*! \file */ 8 | 9 | #include 10 | 11 | #include "cortexm/task.h" 12 | 13 | /*! \details This function returns the thread ID of the calling process. 14 | * \return The thread ID of the caller. 15 | */ 16 | pthread_t pthread_self() { return (pthread_t)task_get_current(); } 17 | 18 | /*! @} */ 19 | -------------------------------------------------------------------------------- /include/mcu/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(SOURCES 3 | adc.h 4 | can.h 5 | cfi.h 6 | core.h 7 | crc.h 8 | crypt.h 9 | dac.h 10 | dma.h 11 | eeprom.h 12 | eint.h 13 | emc.h 14 | eth.h 15 | flash.h 16 | hash.h 17 | i2c.h 18 | i2s.h 19 | ltdc.h 20 | mci.h 21 | mcu.h 22 | mmc.h 23 | ohci.h 24 | periph.h 25 | pio.h 26 | pwm.h 27 | qei.h 28 | qspi.h 29 | rng.h 30 | rtc.h 31 | sdio.h 32 | spi.h 33 | tmr.h 34 | uart.h 35 | usb.h 36 | wdt.h 37 | PARENT_SCOPE) 38 | -------------------------------------------------------------------------------- /src/sys/malloc/_calloc.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | void * _calloc_r(struct _reent * reent_ptr, size_t s1, size_t s2){ 11 | int size; 12 | void * alloc; 13 | size = s1*s2; 14 | alloc = _malloc_r(reent_ptr, size); 15 | if ( alloc != NULL ){ 16 | memset(alloc, 0, size); 17 | } 18 | return alloc; 19 | } 20 | -------------------------------------------------------------------------------- /src/sys/process/process_start.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | /*! \addtogroup SYSCALLS_PROCESS 5 | * @{ 6 | */ 7 | 8 | /*! \file */ 9 | 10 | #ifndef SYSCALLS_PROCESS_H_ 11 | #define SYSCALLS_PROCESS_H_ 12 | 13 | #include "config.h" 14 | 15 | #include 16 | #include 17 | 18 | int process_start(const char *path, char *const envp[]); 19 | 20 | #endif /* SYSCALLS_PROCESS_H_ */ 21 | 22 | 23 | /*! @} */ 24 | -------------------------------------------------------------------------------- /src/sys/sffs/Makefile.am: -------------------------------------------------------------------------------- 1 | bin_PROGRAMS = cafslitesim 2 | CFLAGS = -I$(srcdir) -I$(top_srcdir)/../include -D__SIM__ 3 | cafslitesim_SOURCES = cafs_lite_block.c \ 4 | cafs_lite_diag.c \ 5 | cafs_lite_dir.c \ 6 | cafs_lite_file.c \ 7 | cafs_lite_filelist.c \ 8 | cafs_lite_list.c \ 9 | cafs_lite_scratch.c \ 10 | cafs_lite_serialno.c \ 11 | cafs_lite_tp.c \ 12 | cafs_lite.c \ 13 | main.c \ 14 | test_dir.c \ 15 | test_file.c \ 16 | tests.c \ 17 | sim_dev.c \ 18 | sysfs.c 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/sys/unistd/_execve.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | /*! \addtogroup unistd 5 | * @{ 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | 12 | int _execve(const char *path, char *const argv[], char *const envp[]){ 13 | //This needs to manipulate the task table so that the current process is replaced by a new image 14 | errno = ENOTSUP; 15 | return -1; 16 | 17 | } 18 | 19 | 20 | /*! @} */ 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /include/device/drive_ram.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #ifndef DEVICE_DRIVE_RAM_H_ 4 | #define DEVICE_DRIVE_RAM_H_ 5 | 6 | #include "sos/dev/drive.h" 7 | #include "sos/fs/devfs.h" 8 | 9 | enum { DRIVE_RAM_CONFIG_FLAG_IS_READ_ONLY = (1 << 0) }; 10 | 11 | typedef struct { 12 | void *memory; 13 | u32 size; 14 | u32 o_flags; 15 | } drive_ram_config_t; 16 | 17 | DEVFS_DRIVER_DECLARTION(drive_ram); 18 | 19 | #endif /* DEVICE_DRIVE_RAM_H_ */ 20 | -------------------------------------------------------------------------------- /src/sys/unistd/_getppid.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup unistd 4 | * @{ 5 | */ 6 | 7 | /*! \file */ 8 | 9 | #include 10 | 11 | #include "cortexm/task.h" 12 | 13 | /*! \details This function returns the process ID of the parent process. 14 | * \return The process ID of the caller's parent process. 15 | */ 16 | pid_t getppid() { return (pid_t)task_get_pid(task_get_parent(task_get_current())); } 17 | 18 | /*! @} */ 19 | -------------------------------------------------------------------------------- /src/sys/sffs/configure.ac: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Process this file with autoconf to produce a configure script. 3 | 4 | AC_INIT([cafslitesim], [1.2.6], [contact@coactionos.com]) 5 | AM_INIT_AUTOMAKE([-Wall foreign]) 6 | 7 | AC_CONFIG_HEADERS([config.h]) 8 | AC_CONFIG_FILES([Makefile]) 9 | 10 | AC_CONFIG_MACRO_DIR([m4]) 11 | AC_FUNC_MALLOC 12 | AC_TYPE_INT16_T 13 | AC_TYPE_INT32_T 14 | AC_TYPE_UINT16_T 15 | AC_TYPE_UINT32_T 16 | AC_TYPE_UINT8_T 17 | AC_OUTPUT 18 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.12) 2 | cmsdk2_minimum_required(2.1.2) 3 | 4 | project(StratifyOS 5 | LANGUAGES CXX C ASM 6 | VERSION 4.3.1) 7 | 8 | set(${PROJECT_NAME}_VERSION ${PROJECT_VERSION} CACHE INTERNAL "StratifyOS project version") 9 | 10 | include( ${CMAKE_CURRENT_SOURCE_DIR}/${CMSDK_BUILD_CONFIG}.cmake ) 11 | 12 | install(FILES 13 | ${CMAKE_CURRENT_SOURCE_DIR}/StratifyOS.cmake 14 | ${CMAKE_CURRENT_SOURCE_DIR}/StratifyOS_crt.cmake 15 | DESTINATION ${CMSDK_LOCAL_PATH}/cmake/targets) 16 | 17 | 18 | -------------------------------------------------------------------------------- /include/sos/led.h: -------------------------------------------------------------------------------- 1 | #ifndef SOS_LED_H 2 | #define SOS_LED_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | void sos_led_startup(); 9 | void sos_led_boot_startup(); 10 | void sos_led_flash(int count); 11 | void sos_led_svcall_enable(void *args); 12 | void sos_led_svcall_disable(void *args); 13 | void sos_led_svcall_error(void *args); 14 | 15 | void sos_led_root_enable(); 16 | void sos_led_root_disable(); 17 | void sos_led_root_error(); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif // SOS_LED_H 24 | -------------------------------------------------------------------------------- /include/device/null.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #ifndef MCU_NULL_H_ 4 | #define MCU_NULL_H_ 5 | 6 | #include "sos/fs/devfs.h" 7 | 8 | int null_open(const devfs_handle_t * handle); 9 | int null_ioctl(const devfs_handle_t * handle, int request, void * ctl); 10 | int null_read(const devfs_handle_t * handle, devfs_async_t * rop); 11 | int null_write(const devfs_handle_t * handle, devfs_async_t * wop); 12 | int null_close(const devfs_handle_t * handle); 13 | 14 | #endif /* MCU_NULL_H_ */ 15 | -------------------------------------------------------------------------------- /src/link/BUCK: -------------------------------------------------------------------------------- 1 | """ 2 | Transport Link library 3 | """ 4 | 5 | load("//deps/StratifyOS/src/library.bzl", "sos_library") 6 | 7 | sos_library( 8 | name = "link", 9 | srcs = [ 10 | "link_bootloader.c", 11 | "link_debug.c", 12 | "link_dir.c", 13 | "link_file.c", 14 | "link_phy.c", 15 | "link_process.c", 16 | "link_stdio.c", 17 | "link_sys_attr.c", 18 | "link_time.c", 19 | "link.c", 20 | ], 21 | headers = [ 22 | "link_local.h", 23 | ], 24 | ) 25 | -------------------------------------------------------------------------------- /include/device/full.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #ifndef MCU_FULL_H_ 4 | #define MCU_FULL_H_ 5 | 6 | #include "sos/fs/devfs.h" 7 | 8 | 9 | int full_open(const devfs_handle_t * handle); 10 | int full_ioctl(const devfs_handle_t * handle, int request, void * ctl); 11 | int full_read(const devfs_handle_t * handle, devfs_async_t * rop); 12 | int full_write(const devfs_handle_t * handle, devfs_async_t * wop); 13 | int full_close(const devfs_handle_t * handle); 14 | 15 | 16 | #endif /* MCU_FULL_H_ */ 17 | -------------------------------------------------------------------------------- /src/sys/unistd/_getpid.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup unistd 4 | * @{ 5 | */ 6 | 7 | /*! \file */ 8 | 9 | #include 10 | 11 | #include "config.h" 12 | #include "cortexm/task.h" 13 | 14 | /*! \details This function returns the process ID of the calling process. 15 | * \return The process ID of the caller. 16 | */ 17 | pid_t getpid(); 18 | 19 | /*! \cond */ 20 | pid_t _getpid() { return (pid_t)task_get_pid(task_get_current()); } 21 | /*! \endcond */ 22 | 23 | /*! @} */ 24 | -------------------------------------------------------------------------------- /src/sys/pthread/pthread_cleanup.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | 5 | /*! \addtogroup pthread 6 | * @{ 7 | * 8 | */ 9 | 10 | /*! \file */ 11 | 12 | #include "config.h" 13 | 14 | #include 15 | #include 16 | 17 | 18 | /*! \details This function is not supported. 19 | */ 20 | //void pthread_cleanup_pop(int execute){} 21 | 22 | /*! \details This function is not supported. 23 | */ 24 | //void pthread_cleanup_push(void (*routine)(void*), void *arg){} 25 | 26 | /*! @} */ 27 | 28 | 29 | -------------------------------------------------------------------------------- /include/sos/dev/usbfifo.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup SYS_USBFIFO USB FIFO 4 | * @{ 5 | * 6 | * 7 | * \ingroup IFACE_DEV 8 | * 9 | * \details This device driver is used to add a FIFO read buffer to a USB port. 10 | * 11 | * 12 | * 13 | */ 14 | 15 | /*! \file 16 | */ 17 | 18 | #ifndef SOS_DEV_USBFIFO_H_ 19 | #define SOS_DEV_USBFIFO_H_ 20 | 21 | #include 22 | #include "fifo.h" 23 | #include "usb.h" 24 | 25 | 26 | #endif /* SOS_DEV_USBFIFO_H_ */ 27 | 28 | 29 | /*! @} */ 30 | -------------------------------------------------------------------------------- /include/device/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(SOURCES 3 | devfifo.h 4 | drive_ram.h 5 | fifo.h 6 | led_pwm.h 7 | random.h 8 | appfs.h 9 | mem.h 10 | sys.h 11 | usbfifo.h 12 | device_fifo.h 13 | drive_sdio.h 14 | drive_device.h 15 | full.h 16 | reset_tmr.h 17 | tty.h 18 | zero.h 19 | auth.h 20 | drive_cfi.h 21 | drive_sdspi.h 22 | i2s_ffifo.h 23 | netif_eth.h 24 | stream_ffifo.h 25 | uartfifo.h 26 | auth_flash.h 27 | cfifo.h 28 | drive_mmc.h 29 | ffifo.h 30 | led_pio.h 31 | null.h 32 | switchboard.h 33 | urandom.h 34 | microchip/sst25vf.h 35 | PARENT_SCOPE) 36 | -------------------------------------------------------------------------------- /include/device/urandom.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #ifndef MCU_URANDOM_H_ 4 | #define MCU_URANDOM_H_ 5 | 6 | #include "sos/fs/devfs.h" 7 | 8 | int urandom_open(const devfs_handle_t * handle); 9 | int urandom_ioctl(const devfs_handle_t * handle, int request, void * ctl); 10 | int urandom_read(const devfs_handle_t * handle, devfs_async_t * rop); 11 | int urandom_write(const devfs_handle_t * handle, devfs_async_t * wop); 12 | int urandom_close(const devfs_handle_t * handle); 13 | 14 | 15 | 16 | 17 | #endif /* MCU_URANDOM_H_ */ 18 | -------------------------------------------------------------------------------- /include/sos/dev/uartfifo.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup SYS_UARTFIFO UART FIFO 4 | * @{ 5 | * 6 | * 7 | * \ingroup IFACE_DEV 8 | * 9 | * \details This device driver is used to add a FIFO read buffer to a UART port. 10 | * 11 | * 12 | * 13 | */ 14 | 15 | /*! \file 16 | */ 17 | 18 | 19 | #ifndef SOS_DEV_UARTFIFO_H_ 20 | #define SOS_DEV_UARTFIFO_H_ 21 | 22 | #include 23 | #include "fifo.h" 24 | #include "uart.h" 25 | 26 | 27 | #endif /* SOS_DEV_UARTFIFO_H_ */ 28 | 29 | 30 | /*! @} */ 31 | -------------------------------------------------------------------------------- /src/sys/scheduler/scheduler_fault.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | #ifndef SCHEDULER_SCHEDULER_FAULT_H_ 5 | #define SCHEDULER_SCHEDULER_FAULT_H_ 6 | 7 | #include "scheduler_local.h" 8 | 9 | void scheduler_fault_build_memory_string(char * dest, const char * term); 10 | void scheduler_fault_build_string(char * dest, const char * term); 11 | void scheduler_fault_build_trace_string(char *dest); 12 | 13 | int scheduler_root_fault_handler(void *context, const mcu_event_t *data); 14 | 15 | #endif /* SCHEDULER_SCHEDULER_FAULT_H_ */ 16 | -------------------------------------------------------------------------------- /src/sys/termios/termios.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | 5 | 6 | #include 7 | #include 8 | #include "sos/dev/tty.h" 9 | #include "sys/ioctl.h" 10 | 11 | 12 | int tcgetattr(int fd, struct termios * termios_p){ 13 | return ioctl(fd, I_TTY_GETINFO, termios_p); 14 | } 15 | 16 | int tcsetattr(int fd, int optional_actions, const struct termios * termios_p){ 17 | if ( optional_actions == TCSANOW ){ 18 | return ioctl(fd, I_TTY_SETATTR, termios_p); 19 | } 20 | 21 | errno = ENOTSUP; 22 | return -1; 23 | } 24 | -------------------------------------------------------------------------------- /include/sos/boot/bootloader.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #ifndef SOS_BOOT_BOOTLOADER_H_ 4 | #define SOS_BOOT_BOOTLOADER_H_ 5 | 6 | #include "../dev/bootloader.h" 7 | 8 | typedef struct { 9 | int abort; 10 | int bytes; 11 | int increment; 12 | int total; 13 | } boot_event_flash_t; 14 | 15 | typedef struct { 16 | void *dest; 17 | const void *src; 18 | const char *key; 19 | } boot_event_crypt_t; 20 | 21 | void boot_main(); 22 | int boot_handle_auth_event(int event, void * args); 23 | 24 | #endif /* SOS_BOOT_BOOTLOADER_H_ */ 25 | -------------------------------------------------------------------------------- /src/sys/malloc/malloc_stats.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | #include "config.h" 5 | #include 6 | #include 7 | 8 | void malloc_stats(){ 9 | _malloc_stats_r(_REENT); 10 | } 11 | 12 | void _malloc_stats_r(struct _reent * reent_ptr){ 13 | struct mallinfo mi; 14 | mi = _mallinfo_r(reent_ptr); 15 | iprintf("Total Malloc Memory %d bytes\n", mi.arena); 16 | iprintf("Total Free Chunks %d\n", mi.ordblks); 17 | iprintf("Total Free Memory %d bytes\n", mi.fordblks); 18 | iprintf("Total Used Memory %d bytes\n", mi.uordblks); 19 | } 20 | 21 | -------------------------------------------------------------------------------- /include/mcu/can.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup CAN_DEV CAN 4 | * 5 | * @{ 6 | * 7 | * \ingroup DEV 8 | * 9 | * \details The CAN module provides an API for accessing an MCU's CAN hardware peripherals. 10 | * This is currently not implemented. 11 | * 12 | * 13 | */ 14 | 15 | /*! \file 16 | * \brief CAN Bus Header File 17 | */ 18 | 19 | #ifndef CAN_H_ 20 | #define CAN_H_ 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif /* CAN_H_ */ 31 | 32 | /*! @} */ 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/link_transport/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | if( ${CMSDK_BUILD_CONFIG} STREQUAL arm ) 4 | set(SOURCES 5 | link1_transport.c 6 | link2_transport.c 7 | link3_transport.c 8 | link_transport_slave.c 9 | link1_transport_slave.c 10 | link2_transport_slave.c 11 | link3_transport_slave.c 12 | PARENT_SCOPE) 13 | endif() 14 | 15 | if( ${CMSDK_BUILD_CONFIG} STREQUAL link ) 16 | set(SOURCES 17 | link_transport_master.c 18 | link1_transport.c 19 | link1_transport_master.c 20 | link2_transport.c 21 | link2_transport_master.c 22 | link3_transport.c 23 | link3_transport_master.c 24 | PARENT_SCOPE) 25 | endif() 26 | -------------------------------------------------------------------------------- /src/sys/sysfs/devfs_local.h: -------------------------------------------------------------------------------- 1 | /* 2 | * devfs_local.h 3 | * 4 | * Created on: Aug 12, 2017 5 | * Author: tgil 6 | */ 7 | 8 | #ifndef SYSFS_DEVFS_LOCAL_H_ 9 | #define SYSFS_DEVFS_LOCAL_H_ 10 | 11 | 12 | #include "sos/fs/sysfs.h" 13 | #include "sos/fs/devfs.h" 14 | #include "aio.h" 15 | #include "../scheduler/scheduler_local.h" 16 | #include "../signal/sig_local.h" 17 | 18 | 19 | int devfs_data_transfer(const void * config, const devfs_device_t * device, int flags, int loc, void * buf, int nbyte, int is_read); 20 | int devfs_aio_data_transfer(const devfs_device_t * device, struct aiocb * aiocbp); 21 | 22 | #endif /* SYSFS_DEVFS_LOCAL_H_ */ 23 | -------------------------------------------------------------------------------- /src/sys/time/_itimer.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup time 4 | * @{ 5 | */ 6 | 7 | /*! \file */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | // struct itimerval itimers[SYSCALLS_NUM_ITIMERS]; 14 | 15 | int _getitimer(int which, struct itimerval *value) { 16 | // Update the current value (time of day minus the start time) 17 | errno = ENOTSUP; 18 | return -1; 19 | } 20 | 21 | int _setitimer(int which, const struct itimerval *value, struct itimerval *ovalue) { 22 | errno = ENOTSUP; 23 | return -1; 24 | } 25 | 26 | /*! @} */ 27 | -------------------------------------------------------------------------------- /src/device/urandom.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | #include "device/urandom.h" 5 | #include 6 | #include 7 | 8 | int urandom_open(const devfs_handle_t *handle) { return 0; } 9 | 10 | int urandom_ioctl(const devfs_handle_t *handle, int request, void *ctl) { return 0; } 11 | 12 | int urandom_read(const devfs_handle_t *handle, devfs_async_t *rop) { 13 | return SYSFS_SET_RETURN(ENOTSUP); 14 | } 15 | 16 | int urandom_write(const devfs_handle_t *handle, devfs_async_t *wop) { 17 | return SYSFS_SET_RETURN(ENOTSUP); 18 | } 19 | 20 | int urandom_close(const devfs_handle_t *handle) { return 0; } 21 | -------------------------------------------------------------------------------- /src/device/zero.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | #include "device/zero.h" 5 | #include 6 | #include 7 | #include 8 | 9 | int zero_open(const devfs_handle_t *handle) { return 0; } 10 | 11 | int zero_ioctl(const devfs_handle_t *handle, int request, void *ctl) { return 0; } 12 | 13 | int zero_read(const devfs_handle_t *handle, devfs_async_t *rop) { 14 | memset(rop->buf, 0, rop->nbyte); 15 | return rop->nbyte; 16 | } 17 | 18 | int zero_write(const devfs_handle_t *handle, devfs_async_t *wop) { return wop->nbyte; } 19 | 20 | int zero_close(const devfs_handle_t *handle) { return 0; } 21 | -------------------------------------------------------------------------------- /include/device/random.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #ifndef MCU_RANDOM_H_ 4 | #define MCU_RANDOM_H_ 5 | 6 | #include "sos/dev/random.h" 7 | #include "sos/fs/devfs.h" 8 | 9 | typedef struct { 10 | u32 clfsr; 11 | } random_state_t; 12 | 13 | int random_open(const devfs_handle_t * handle); 14 | int random_ioctl(const devfs_handle_t * handle, int request, void * ctl); 15 | int random_read(const devfs_handle_t * handle, devfs_async_t * rop); 16 | int random_write(const devfs_handle_t * handle, devfs_async_t * wop); 17 | int random_close(const devfs_handle_t * handle); 18 | 19 | 20 | 21 | 22 | 23 | #endif /* MCU_RANDOM_H_ */ 24 | -------------------------------------------------------------------------------- /src/device/null.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | #include "device/null.h" 5 | #include 6 | #include 7 | 8 | int null_open(const devfs_handle_t *handle) { return 0; } 9 | 10 | int null_ioctl(const devfs_handle_t *handle, int request, void *ctl) { 11 | return SYSFS_SET_RETURN(ENOTSUP); 12 | } 13 | 14 | int null_read(const devfs_handle_t *handle, devfs_async_t *async) { 15 | return -1; // EOF 16 | } 17 | 18 | int null_write(const devfs_handle_t *handle, devfs_async_t *async) { 19 | // accept the data 20 | return async->nbyte; 21 | } 22 | 23 | int null_close(const devfs_handle_t *handle) { return 0; } 24 | -------------------------------------------------------------------------------- /src/library.bzl: -------------------------------------------------------------------------------- 1 | """ 2 | Library Helper 3 | """ 4 | 5 | def sos_library(name, srcs = [], deps = [], headers = []): 6 | native.cxx_library( 7 | name = name, 8 | target_compatible_with = ["toolchains//config:stratifyos"], 9 | srcs = srcs, 10 | compiler_flags = ["-DSOS_BOOTSTRAP_SOCKETS=1"], 11 | headers = headers, 12 | deps = deps + [ 13 | "//deps/StratifyOS/src:config", 14 | "//deps/StratifyOS/include:sos_include", 15 | "//config:stratifyos_config", 16 | ], 17 | _cxx_toolchain = select({ 18 | "toolchains//config:stratifyos": "toolchains//:arm-none-eabi", 19 | }), 20 | ) 21 | -------------------------------------------------------------------------------- /include/mcu/periph.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #ifndef MCU_PERIPH_H_ 4 | #define MCU_PERIPH_H_ 5 | 6 | 7 | #include "adc.h" 8 | #include "dac.h" 9 | #include "core.h" 10 | #include "crypt.h" 11 | #include "eint.h" 12 | #include "emc.h" 13 | #include "eeprom.h" 14 | #include "eth.h" 15 | #include "flash.h" 16 | #include "mci.h" 17 | #include "i2c.h" 18 | #include "i2s.h" 19 | #include "pio.h" 20 | #include "pwm.h" 21 | #include "qei.h" 22 | #include "rtc.h" 23 | #include "qspi.h" 24 | #include "spi.h" 25 | #include "sdio.h" 26 | #include "tmr.h" 27 | #include "uart.h" 28 | #include "usb.h" 29 | 30 | 31 | 32 | #endif /* MCU_PERIPH_H_ */ 33 | -------------------------------------------------------------------------------- /src/device/full.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | #include "device/full.h" 5 | #include 6 | #include 7 | #include 8 | 9 | int full_open(const devfs_handle_t *handle) { return 0; } 10 | 11 | int full_ioctl(const devfs_handle_t *handle, int request, void *ctl) { return 0; } 12 | 13 | int full_read(const devfs_handle_t *handle, devfs_async_t *rop) { 14 | memset(rop->buf, 0, rop->nbyte); 15 | return rop->nbyte; 16 | } 17 | 18 | int full_write(const devfs_handle_t *handle, devfs_async_t *wop) { 19 | return SYSFS_SET_RETURN(ENOSPC); 20 | } 21 | 22 | int full_close(const devfs_handle_t *handle) { return 0; } 23 | -------------------------------------------------------------------------------- /src/link/link_stdio.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #include 4 | 5 | #include "link_local.h" 6 | 7 | int link_open_stdio(link_transport_mdriver_t *driver /*, const char * name */) { 8 | return 0; 9 | } 10 | 11 | int link_close_stdio(link_transport_mdriver_t *driver) { return 0; } 12 | 13 | int link_read_stdout(link_transport_mdriver_t *driver, void *buf, int nbyte) { 14 | return driver->phy_driver.read(driver->phy_driver.handle, buf, nbyte); 15 | } 16 | 17 | int link_write_stdin(link_transport_mdriver_t *driver, const void *buf, int nbyte) { 18 | return driver->phy_driver.write(driver->phy_driver.handle, buf, nbyte); 19 | } 20 | -------------------------------------------------------------------------------- /src/device/i2s_spi_ffifo.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | #include 5 | #include 6 | #include 7 | #include "device/usbfifo.h" 8 | #include "sos/debug.h" 9 | 10 | #define i2s_ffifo_open i2s_spi_ffifo_open 11 | #define i2s_ffifo_close i2s_spi_ffifo_close 12 | #define i2s_ffifo_read i2s_spi_ffifo_read 13 | #define i2s_ffifo_write i2s_spi_ffifo_write 14 | #define i2s_ffifo_ioctl i2s_spi_ffifo_ioctl 15 | 16 | #define mcu_i2s_open mcu_i2s_spi_open 17 | #define mcu_i2s_close mcu_i2s_spi_close 18 | #define mcu_i2s_read mcu_i2s_spi_read 19 | #define mcu_i2s_write mcu_i2s_spi_write 20 | #define mcu_i2s_ioctl mcu_i2s_spi_ioctl 21 | 22 | 23 | #include "i2s_ffifo.c" 24 | -------------------------------------------------------------------------------- /include/device/reset_tmr.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #ifndef DEVICE_RESET_TMR_H 4 | #define DEVICE_RESET_TMR_H 5 | 6 | #include "sos/fs/devfs.h" 7 | 8 | typedef struct { 9 | const devfs_device_t *tmr_device; 10 | } reset_tmr_config_t; 11 | 12 | typedef struct { 13 | u32 o_flags; 14 | } reset_tmr_state_t; 15 | 16 | int reset_tmr_open(const devfs_handle_t *handle); 17 | int reset_tmr_ioctl(const devfs_handle_t *handle, int request, void *ctl); 18 | int reset_tmr_read(const devfs_handle_t *handle, devfs_async_t *rop); 19 | int reset_tmr_write(const devfs_handle_t *handle, devfs_async_t *wop); 20 | int reset_tmr_close(const devfs_handle_t *handle); 21 | 22 | #endif // DEVICE_RESET_TMR_H 23 | -------------------------------------------------------------------------------- /src/cortexm/cortexm_local.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | #ifndef CORTEXM_LOCAL_H_ 5 | #define CORTEXM_LOCAL_H_ 6 | 7 | #include "cortexm/cortexm.h" 8 | #include "sos/arch.h" 9 | #include "sos/debug.h" 10 | 11 | #define SYSTICK_CTRL_TICKINT (1 << 1) 12 | 13 | static inline void cortexm_enable_systick_irq() MCU_ALWAYS_INLINE; 14 | void cortexm_enable_systick_irq() { 15 | #if defined SysTick 16 | SysTick->CTRL |= SYSTICK_CTRL_TICKINT; 17 | #endif 18 | } 19 | 20 | static inline void cortexm_disable_systick_irq() MCU_ALWAYS_INLINE; 21 | void cortexm_disable_systick_irq() { 22 | #if defined SysTick 23 | SysTick->CTRL &= ~SYSTICK_CTRL_TICKINT; 24 | #endif 25 | } 26 | 27 | #endif /* CORTEXM_LOCAL_H_ */ 28 | -------------------------------------------------------------------------------- /include/device/led_pio.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #ifndef MCU_LED_H_ 4 | #define MCU_LED_H_ 5 | 6 | #include "sos/dev/led.h" 7 | #include "sos/fs/devfs.h" 8 | 9 | 10 | enum { 11 | LED_PIO_CONFIG_FLAG_IS_ACTIVE_HIGH = (1<<0), 12 | }; 13 | 14 | typedef struct MCU_PACK { 15 | u32 o_flags; 16 | u32 pin; 17 | } led_pio_config_t; 18 | 19 | int led_pio_open(const devfs_handle_t * handle); 20 | int led_pio_ioctl(const devfs_handle_t * handle, int request, void * ctl); 21 | int led_pio_read(const devfs_handle_t * handle, devfs_async_t * rop); 22 | int led_pio_write(const devfs_handle_t * handle, devfs_async_t * wop); 23 | int led_pio_close(const devfs_handle_t * handle); 24 | 25 | 26 | #endif /* MCU_LED_H_ */ 27 | -------------------------------------------------------------------------------- /src/sys/unistd/_unlink.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | /*! \addtogroup unistd 5 | * @{ 6 | */ 7 | 8 | /*! \file */ 9 | 10 | #include "unistd_fs.h" 11 | 12 | /*! \details Deletes a file or directory from the filesystem. */ 13 | int unlink(const char *name); 14 | 15 | /*! \cond */ 16 | int _unlink(const char *name) { 17 | const sysfs_t *fs; 18 | 19 | if (sysfs_ispathinvalid(name) == true) { 20 | return -1; 21 | } 22 | 23 | fs = sysfs_find(name, true); 24 | if (fs != NULL) { 25 | int ret = fs->unlink(fs->config, sysfs_stripmountpath(fs, name)); 26 | SYSFS_PROCESS_RETURN(ret); 27 | return ret; 28 | } 29 | errno = ENOENT; 30 | return -1; 31 | } 32 | /*! \endcond */ 33 | 34 | /*! @} */ 35 | -------------------------------------------------------------------------------- /include/device/zero.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup SYS_NULL Null Device 4 | * @{ 5 | * 6 | * 7 | * \ingroup IFACE_DEV 8 | * 9 | * \details This device discards input and returns EOF when read. 10 | * 11 | * 12 | */ 13 | 14 | /*! \file */ 15 | 16 | #ifndef DEV_ZERO_H_ 17 | #define DEV_ZERO_H_ 18 | 19 | #include "sos/fs/devfs.h" 20 | 21 | 22 | int zero_open(const devfs_handle_t * handle); 23 | int zero_ioctl(const devfs_handle_t * handle, int request, void * ctl); 24 | int zero_read(const devfs_handle_t * handle, devfs_async_t * rop); 25 | int zero_write(const devfs_handle_t * handle, devfs_async_t * wop); 26 | int zero_close(const devfs_handle_t * handle); 27 | 28 | 29 | #endif /* DEV_ZERO_H_ */ 30 | 31 | 32 | /*! @} */ 33 | -------------------------------------------------------------------------------- /src/sys/unistd/crypt.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | /*! \addtogroup unistd 5 | * @{ 6 | */ 7 | 8 | /*! \file 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include "sos/fs/sysfs.h" 19 | 20 | 21 | /*! \details Encrypts a block of data. 22 | * 23 | * \return No return value but errno may be set to: 24 | * - ENOSYS: function not supported on this platform 25 | * 26 | */ 27 | void encrypt(char block[64], int edflag){ 28 | 29 | } 30 | 31 | 32 | char * crypt(const char *key, const char *salt){ 33 | return 0; 34 | } 35 | 36 | void setkey(const char *key){ 37 | 38 | } 39 | 40 | 41 | /*! @} */ 42 | 43 | -------------------------------------------------------------------------------- /src/sys/check_config.h: -------------------------------------------------------------------------------- 1 | #ifndef CHECK_CONFIG_H 2 | #define CHECK_CONFIG_H 3 | 4 | #define CHECK_CONFIG_MESSAGE(x, y) ((void *)((MCU_STRINGIFY(x) "." MCU_STRINGIFY(y)))) 5 | 6 | #define CHECK_CONFIG(GROUP_VALUE, MEMBER_VALUE) \ 7 | if (sos_config.GROUP_VALUE.MEMBER_VALUE == 0) \ 8 | sos_handle_event( \ 9 | SOS_EVENT_ROOT_FATAL, CHECK_CONFIG_MESSAGE(GROUP_VALUE, MEMBER_VALUE)); 10 | 11 | #define CONFIG_ASSERT(value, message) \ 12 | if ((value) == 0) \ 13 | sos_handle_event(SOS_EVENT_ROOT_FATAL, message); 14 | 15 | #endif // CHECK_CONFIG_H 16 | -------------------------------------------------------------------------------- /src/sys/unistd/_isatty.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | 5 | /*! \addtogroup unistd 6 | * @{ 7 | */ 8 | 9 | /*! \file */ 10 | 11 | #include "unistd_local.h" 12 | #include "unistd_fs.h" 13 | 14 | /*! \details This function checks to see if \a fildes is associated 15 | * with a terminal device. 16 | * 17 | * \return Zero on success or -1 on error with errno (see \ref errno) set to: 18 | * - ENOTTY: \a fildes is not associated with a terminal device 19 | * - EBADF: \a fildes is invalid 20 | * 21 | */ 22 | int isatty(int fildes); 23 | 24 | /*! \cond */ 25 | int _isatty(int fildes){ 26 | 27 | fildes = u_fildes_is_bad(fildes); 28 | if ( fildes < 0 ){ 29 | return -1; 30 | } 31 | 32 | return 0; 33 | } 34 | /*! \endcond */ 35 | 36 | /*! @} */ 37 | 38 | -------------------------------------------------------------------------------- /include/device/devfifo.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #ifndef DEV_DEVFIFO_H_ 4 | #define DEV_DEVFIFO_H_ 5 | 6 | #include "sos/dev/devfifo.h" 7 | #include "sos/fs/devfs.h" 8 | 9 | /*! \details This stores the data for the state of the fifo buffer. 10 | * 11 | */ 12 | typedef struct { 13 | int head; 14 | int tail; 15 | bool overflow; 16 | devfs_async_t * rop; 17 | int len; 18 | } devfifo_state_t; 19 | 20 | int devfifo_open(const devfs_handle_t * handle); 21 | int devfifo_ioctl(const devfs_handle_t * handle, int request, void * ctl); 22 | int devfifo_read(const devfs_handle_t * handle, devfs_async_t * rop); 23 | int devfifo_write(const devfs_handle_t * handle, devfs_async_t * wop); 24 | int devfifo_close(const devfs_handle_t * handle); 25 | 26 | 27 | #endif /* DEV_DEVFIFO_H_ */ 28 | 29 | -------------------------------------------------------------------------------- /include/device/led_pwm.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #ifndef DEVICE_LED_PWM_H_ 4 | #define DEVICE_LED_PWM_H_ 5 | 6 | #include "mcu/pwm.h" 7 | #include "sos/dev/led.h" 8 | #include "sos/fs/devfs.h" 9 | 10 | enum { 11 | LED_PWM_CONFIG_FLAG_IS_ACTIVE_HIGH = (1 << 0), 12 | }; 13 | 14 | typedef struct MCU_PACK { 15 | pwm_config_t pwm; 16 | u32 loc; // location of the channel 17 | u32 o_flags; 18 | } led_pwm_config_t; 19 | 20 | int led_pwm_open(const devfs_handle_t *handle); 21 | int led_pwm_ioctl(const devfs_handle_t *handle, int request, void *ctl); 22 | int led_pwm_read(const devfs_handle_t *handle, devfs_async_t *rop); 23 | int led_pwm_write(const devfs_handle_t *handle, devfs_async_t *wop); 24 | int led_pwm_close(const devfs_handle_t *handle); 25 | 26 | #endif /* DEVICE_LED_PWM_H_ */ 27 | -------------------------------------------------------------------------------- /src/sys/assert_func.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #include "cortexm/cortexm.h" 4 | #include "cortexm/task.h" 5 | #include "sos/debug.h" 6 | #include "sos/events.h" 7 | 8 | void __assert_func(const char *file, int line, const char *func, const char *failedexpr) { 9 | 10 | if (cortexm_is_root_mode() || (task_get_pid(task_get_current()) == 0)) { 11 | sos_debug_printf( 12 | "assertion \"%s\" failed: file \"%s\", line %d%s%s\n", failedexpr, file, line, 13 | func ? ", function: " : "", func ? func : ""); 14 | sos_handle_event(SOS_EVENT_ASSERT, NULL); 15 | 16 | } else { 17 | fiprintf( 18 | stderr, "assertion \"%s\" failed: file \"%s\", line %d%s%s\n", failedexpr, file, 19 | line, func ? ", function: " : "", func ? func : ""); 20 | abort(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /StratifyOS.cmake: -------------------------------------------------------------------------------- 1 | if(SOS_IS_LINK) 2 | set(STRATIFYOS_CMAKE_CONFIG_LIST release debug) 3 | cmsdk_include_target(StratifyOS "${STRATIFYOS_CMAKE_CONFIG_LIST}") 4 | else() 5 | set(STRATIFYOS_CMAKE_CONFIG_LIST release debug) 6 | cmsdk_include_target(StratifyOS_mcu "${STRATIFYOS_CMAKE_CONFIG_LIST}") 7 | cmsdk_include_target(StratifyOS_linktransport "${STRATIFYOS_CMAKE_CONFIG_LIST}") 8 | cmsdk_include_target(StratifyOS_cortexm "${STRATIFYOS_CMAKE_CONFIG_LIST}") 9 | cmsdk_include_target(StratifyOS_usbd "${STRATIFYOS_CMAKE_CONFIG_LIST}") 10 | cmsdk_include_target(StratifyOS_device "${STRATIFYOS_CMAKE_CONFIG_LIST}") 11 | cmsdk_include_target(StratifyOS_sys "${STRATIFYOS_CMAKE_CONFIG_LIST}") 12 | cmsdk_include_target(StratifyOS_crt "${STRATIFYOS_CMAKE_CONFIG_LIST}") 13 | cmsdk_include_target(StratifyOS_boot "${STRATIFYOS_CMAKE_CONFIG_LIST}") 14 | endif() 15 | -------------------------------------------------------------------------------- /src/device/drive_sdssp.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | #include "mcu/spi.h" 5 | 6 | #define mcu_spi_open mcu_ssp_open 7 | #define mcu_spi_close mcu_ssp_close 8 | #define mcu_spi_setaction mcu_ssp_setaction 9 | #define mcu_spi_setduplex mcu_ssp_setduplex 10 | #define mcu_spi_swap mcu_ssp_swap 11 | #define mcu_spi_getinfo mcu_ssp_getinfo 12 | #define mcu_spi_setattr mcu_ssp_setattr 13 | #define mcu_spi_write mcu_ssp_write 14 | #define mcu_spi_read mcu_ssp_read 15 | #define mcu_spi_ioctl mcu_ssp_ioctl 16 | 17 | 18 | #define drive_sdspi_open drive_sdssp_open 19 | #define drive_sdspi_ioctl drive_sdssp_ioctl 20 | #define drive_sdspi_read drive_sdssp_read 21 | #define drive_sdspi_write drive_sdssp_write 22 | #define drive_sdspi_close drive_sdssp_close 23 | 24 | 25 | #include "drive_sdspi.c" 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/cortexm/BUCK: -------------------------------------------------------------------------------- 1 | """ 2 | CortexM Library 3 | """ 4 | 5 | load("//deps/StratifyOS/src/library.bzl", "sos_library") 6 | 7 | cxx_library( 8 | name = "cortexm_local_headers", 9 | exported_headers = [ 10 | "cortexm_local.h", 11 | "fault_local.h", 12 | "task_local.h", 13 | ], 14 | header_namespace = "cortexm", 15 | visibility = ["//deps/StratifyOS/src/sys:sys"], 16 | ) 17 | 18 | sos_library( 19 | name = "cortexm", 20 | srcs = [ 21 | "cortexm.c", 22 | "auth.c", 23 | "devfs.c", 24 | "fault.c", 25 | "util.c", 26 | "fault_handler.c", 27 | "mpu.c", 28 | "task_mpu.c", 29 | "task_process.c", 30 | "task.c", 31 | ], 32 | headers = [ 33 | "cortexm_local.h", 34 | "fault_local.h", 35 | "task_local.h", 36 | ] 37 | ) 38 | -------------------------------------------------------------------------------- /include/sos/arch/delay_cm.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup DELAY 4 | * @{ 5 | * 6 | * \ingroup HWPL 7 | */ 8 | 9 | /*! \file */ 10 | 11 | 12 | #ifndef DELAY_CM_H_ 13 | #define DELAY_CM_H_ 14 | 15 | 16 | #include "../types.h" 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | #ifndef F_CPU 23 | #define F_CPU 72000000UL 24 | #endif 25 | 26 | #if defined __lpc8xx || defined __lpc82x 27 | static inline void _delay_ms(uint32_t __ms){} 28 | 29 | static inline void _delay_us(uint32_t __us){} 30 | #else 31 | //user F_CPU to create millisecond and microsecond delay loops 32 | static inline void _delay_loop_1(u32 __count) MCU_ALWAYS_INLINE; 33 | 34 | 35 | #endif 36 | 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | 43 | #endif /* DELAY_CM_H_ */ 44 | 45 | /*! @} */ 46 | -------------------------------------------------------------------------------- /src/mcu/emc.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2016 Tyler Gilbert; 2 | * This file is part of Stratify OS. 3 | * 4 | * Stratify OS is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Stratify OS is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Stratify OS. If not, see . 16 | * 17 | * 18 | */ 19 | 20 | #include "sos/fs/devfs.h" 21 | #include "mcu/dac.h" 22 | 23 | -------------------------------------------------------------------------------- /src/mcu/enet.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2016 Tyler Gilbert; 2 | * This file is part of Stratify OS. 3 | * 4 | * Stratify OS is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Stratify OS is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Stratify OS. If not, see . 16 | * 17 | * 18 | */ 19 | 20 | #include "sos/fs/devfs.h" 21 | #include "mcu/dac.h" 22 | 23 | -------------------------------------------------------------------------------- /src/mcu/mci.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2016 Tyler Gilbert; 2 | * This file is part of Stratify OS. 3 | * 4 | * Stratify OS is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Stratify OS is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Stratify OS. If not, see . 16 | * 17 | * 18 | */ 19 | 20 | #include "sos/fs/devfs.h" 21 | #include "mcu/mci.h" 22 | 23 | -------------------------------------------------------------------------------- /src/mcu/adc.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2016 Tyler Gilbert; 2 | * This file is part of Stratify OS. 3 | * 4 | * Stratify OS is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Stratify OS is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Stratify OS. If not, see . */ 16 | 17 | #include "sos/fs/devfs.h" 18 | #include "mcu/adc.h" 19 | 20 | DEVFS_MCU_DRIVER_IOCTL_FUNCTION_MIN(adc, ADC_VERSION) 21 | -------------------------------------------------------------------------------- /include/device/tty.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #ifndef DEV_TTY_H_ 4 | #define DEV_TTY_H_ 5 | 6 | #include "sos/fs/devfs.h" 7 | 8 | int tty_usbbulk_open(const devfs_handle_t * handle); 9 | int tty_usbbulk_ioctl(const devfs_handle_t * handle, int request, void * ctl); 10 | int tty_usbbulk_write(const devfs_handle_t * handle, devfs_async_t * wop); 11 | int tty_usbbulk_read(const devfs_handle_t * handle, devfs_async_t * rop); 12 | int tty_usbbulk_close(const devfs_handle_t * handle); 13 | 14 | int tty_uart_open(const devfs_handle_t * handle); 15 | int tty_uart_ioctl(const devfs_handle_t * handle, int request, void * ctl); 16 | int tty_uart_write(const devfs_handle_t * handle, devfs_async_t * wop); 17 | int tty_uart_read(const devfs_handle_t * handle, devfs_async_t * rop); 18 | int tty_uart_close(const devfs_handle_t * handle); 19 | 20 | 21 | #endif /* DEV_TTY_H_ */ 22 | -------------------------------------------------------------------------------- /src/device/drive_sdspi_dma.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | #include "mcu/spi.h" 5 | 6 | #define mcu_spi_open mcu_spi_dma_open 7 | #define mcu_spi_close mcu_spi_dma_close 8 | #define mcu_spi_setaction mcu_spi_dma_setaction 9 | #define mcu_spi_setduplex mcu_spi_dma_setduplex 10 | #define mcu_spi_swap mcu_spi_dma_swap 11 | #define mcu_spi_getinfo mcu_spi_dma_getinfo 12 | #define mcu_spi_setattr mcu_spi_dma_setattr 13 | #define mcu_spi_write mcu_spi_dma_write 14 | #define mcu_spi_read mcu_spi_dma_read 15 | #define mcu_spi_ioctl mcu_spi_dma_ioctl 16 | 17 | 18 | #define drive_sdspi_open drive_sdspi_dma_open 19 | #define drive_sdspi_ioctl drive_sdspi_dma_ioctl 20 | #define drive_sdspi_read drive_sdspi_dma_read 21 | #define drive_sdspi_write drive_sdspi_dma_write 22 | #define drive_sdspi_close drive_sdspi_dma_close 23 | 24 | 25 | #include "drive_sdspi.c" 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/mcu/i2c.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2016 Tyler Gilbert; 2 | * This file is part of Stratify OS. 3 | * 4 | * Stratify OS is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Stratify OS is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Stratify OS. If not, see . 16 | * 17 | * 18 | */ 19 | 20 | #include "sos/fs/devfs.h" 21 | #include "mcu/i2c.h" 22 | 23 | DEVFS_MCU_DRIVER_IOCTL_FUNCTION_MIN(i2c, I2C_VERSION) 24 | -------------------------------------------------------------------------------- /src/crt/crt_common.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | #ifndef CRT_COMMON_H_ 5 | #define CRT_COMMON_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "../sys/sysfs/appfs_local.h" 16 | 17 | 18 | extern uint32_t _text; 19 | extern uint32_t _text_size; 20 | extern uint32_t _data; 21 | extern uint32_t _data_size; 22 | extern uint32_t _bss; 23 | extern uint32_t _ebss; 24 | 25 | extern uint32_t _app_ram_size; 26 | 27 | void crt_common(char *path_arg, int *ret, const char *name) 28 | __attribute__((__short_call__)); 29 | void crt_exit(int exit_code); 30 | 31 | void crt_load_data(void * global_reent, int code_size, int data_size); 32 | char ** const crt_import_argv(const char * path_arg, int * argc); 33 | 34 | #endif /* CRT_COMMON_H_ */ 35 | -------------------------------------------------------------------------------- /include/mcu/wdt.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #ifndef WDT_H_ 4 | #define WDT_H_ 5 | 6 | #include 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | typedef enum { 13 | WDT_MODE_RESET = (1 << 0), 14 | WDT_MODE_INTERRUPT = (1 << 1), 15 | WDT_MODE_CLK_SRC_INTERNAL_RC = (0 << 2), 16 | WDT_MODE_CLK_SRC_MAIN = (1 << 2), 17 | WDT_MODE_CLK_SRC_RTC = (2 << 2), 18 | WDT_MODE_CLK_SRC_WDT_OSC = (3 << 2) 19 | } wdt_mode_t; 20 | 21 | #define WDT_MODE_CLK_SRC_MASK (0x07 << 2) 22 | 23 | int mcu_wdt_init(int mode, int interval) MCU_ROOT_CODE; 24 | void mcu_wdt_reset(); 25 | void mcu_wdt_root_reset(void *args) MCU_ROOT_CODE; 26 | int mcu_wdt_setaction(int (*action)(const void *, void *)) MCU_ROOT_CODE; 27 | int mcu_wdt_setinterval(int interval) MCU_ROOT_CODE; 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | #endif /* WDT_H_ */ 34 | 35 | /*! @} */ 36 | -------------------------------------------------------------------------------- /cmake/generate_sources.cmake: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.6) 2 | 3 | #Usage: 4 | #cmake -DPATH=/Users/tgil/git/StratifyOS-libc/newlib/libm/math -P /Applications/StratifyLabs-SDK/arm-none-eabi/cmake/generate_sources.cmake 5 | 6 | file(GLOB FILELIST 7 | ${PATH}/*.c 8 | ${PATH}/*.h 9 | ${PATH}/*.cpp 10 | ${PATH}/*.hpp 11 | ${PATH}/*.S 12 | ${PATH}/*.s 13 | ${PATH}/*.cc 14 | ${PATH}/*.json 15 | ${PATH}/*.md) 16 | 17 | message(STATUS "Checking Path for sources: " ${PATH}) 18 | 19 | set(OUTPUT ${PATH}/CMakeLists.txt) 20 | 21 | file(WRITE ${OUTPUT} "set(SOURCES\n") 22 | 23 | foreach(FILE ${FILELIST}) 24 | message(STATUS "OUTPUT FILE: " ${FILE}) 25 | get_filename_component(FILENAME ${FILE} NAME) 26 | set(ENTRY "\${SOURCES_PREFIX}/${FILENAME}") 27 | message(STATUS "Adding Entry: " ${ENTRY}) 28 | file(APPEND ${OUTPUT} "\t${ENTRY}") 29 | file(APPEND ${OUTPUT} "\n") 30 | endforeach() 31 | 32 | file(APPEND ${OUTPUT} "\tPARENT_SCOPE)") 33 | -------------------------------------------------------------------------------- /src/device/drive_mmc_dma.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | #include "mcu/mmc.h" 5 | 6 | #define mcu_mmc_open mcu_mmc_dma_open 7 | #define mcu_mmc_close mcu_mmc_dma_close 8 | #define mcu_mmc_setaction mcu_mmc_dma_setaction 9 | #define mcu_mmc_getinfo mcu_mmc_dma_getinfo 10 | #define mcu_mmc_setattr mcu_mmc_dma_setattr 11 | #define mcu_mmc_write mcu_mmc_dma_write 12 | #define mcu_mmc_read mcu_mmc_dma_read 13 | #define mcu_mmc_ioctl mcu_mmc_dma_ioctl 14 | #define mcu_mmc_getcsd mcu_mmc_dma_getcsd 15 | #define mcu_mmc_getcid mcu_mmc_dma_getcid 16 | #define mcu_mmc_getstatus mcu_mmc_dma_getstatus 17 | 18 | 19 | #define drive_mmc_open drive_mmc_dma_open 20 | #define drive_mmc_ioctl drive_mmc_dma_ioctl 21 | #define drive_mmc_read drive_mmc_dma_read 22 | #define drive_mmc_write drive_mmc_dma_write 23 | #define drive_mmc_close drive_mmc_dma_close 24 | 25 | 26 | #include "drive_mmc.c" 27 | 28 | 29 | -------------------------------------------------------------------------------- /include/device/drive_mmc.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #ifndef DEVICE_MMC_H_ 4 | #define DEVICE_MMC_H_ 5 | 6 | #include "sos/dev/drive.h" 7 | #include "sos/dev/mmc.h" 8 | #include "sos/fs/devfs.h" 9 | 10 | typedef struct { 11 | const char *buf; 12 | int *nbyte; 13 | int count; 14 | int timeout; 15 | uint8_t cmd[16]; 16 | devfs_async_t op; 17 | mcu_event_handler_t handler; 18 | u32 flags; 19 | } drive_mmc_state_t; 20 | 21 | typedef struct { 22 | devfs_device_t device; 23 | } drive_mmc_config_t; 24 | 25 | int drive_mmc_open(const devfs_handle_t *handle); 26 | int drive_mmc_ioctl(const devfs_handle_t *handle, int request, void *ctl); 27 | int drive_mmc_read(const devfs_handle_t *handle, devfs_async_t *rop); 28 | int drive_mmc_write(const devfs_handle_t *handle, devfs_async_t *wop); 29 | int drive_mmc_close(const devfs_handle_t *handle); 30 | 31 | 32 | #endif /* DEVICE_MMC_H_ */ 33 | -------------------------------------------------------------------------------- /include/device/auth_flash.h: -------------------------------------------------------------------------------- 1 | #ifndef AUTH_FLASH_H 2 | #define AUTH_FLASH_H 3 | 4 | #include "sos/fs/devfs.h" 5 | #include "sos/dev/flash.h" 6 | 7 | typedef struct { 8 | u8 ecc_context_buffer[256]; 9 | void *ecc_context; 10 | u8 sha_context_buffer[256]; 11 | void *sha_context; 12 | flash_writepage_t first_page; 13 | } auth_flash_state_t; 14 | 15 | typedef struct { 16 | devfs_device_t device; 17 | u32 os_start; 18 | u32 os_start_size; 19 | u32 os_size; 20 | } auth_flash_config_t; 21 | 22 | 23 | int auth_flash_open(const devfs_handle_t *handle) MCU_ROOT_CODE; 24 | int auth_flash_read(const devfs_handle_t * handle, devfs_async_t * rop) MCU_ROOT_CODE; 25 | int auth_flash_write(const devfs_handle_t * handle, devfs_async_t * wop) MCU_ROOT_CODE; 26 | int auth_flash_ioctl(const devfs_handle_t * handle, int request, void * ctl) MCU_ROOT_CODE; 27 | int auth_flash_close(const devfs_handle_t * handle) MCU_ROOT_CODE; 28 | 29 | #endif // AUTH_FLASH_H 30 | -------------------------------------------------------------------------------- /create-gcc-hard.cmake: -------------------------------------------------------------------------------- 1 | set(SDK_PATH $ENV{SOS_SDK_PATH}) 2 | set(COMMAND ${SDK_PATH}/Tools/gcc/bin/arm-none-eabi-objcopy) 3 | set(ARGUMENTS "-W __aeabi_fmul -W __aeabi_dmul -W __aeabi_fdiv -W __aeabi_ddiv -W __aeabi_dadd -W __adddf3 -W __aeabi_fadd -W __addsf3 -W __divdc3 -W __divsc3 -W __muldc3 libgcc.a libgcc-hard.a") 4 | set(BASE_DIRECTORY ${SDK_PATH}/Tools/gcc/lib/gcc/arm-none-eabi/8.3.1) 5 | set(DIRECTORY_LIST thumb/v7+fp/hard thumb/v7e-m+dp/hard thumb/v7e-m+fp/hard) 6 | foreach (DIR ${DIRECTORY_LIST}) 7 | message(STATUS "EXECUTE ${COMMAND} ${ARGUMENTS}") 8 | set(WORKING_DIRECTORY ${BASE_DIRECTORY}/${DIR}) 9 | message(STATUS "Working directory ${WORKING_DIRECTORY}") 10 | execute_process(COMMAND ${COMMAND} -W __aeabi_fmul -W __aeabi_dmul -W __aeabi_fdiv -W __aeabi_ddiv -W __aeabi_dadd -W __adddf3 -W __aeabi_fadd -W __addsf3 -W __divdc3 -W __divsc3 -W __muldc3 libgcc.a libgcc-hard.a 11 | WORKING_DIRECTORY ${WORKING_DIRECTORY} 12 | ) 13 | endforeach(DIR) 14 | -------------------------------------------------------------------------------- /src/mcu/spi.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2016 Tyler Gilbert; 2 | * This file is part of Stratify OS. 3 | * 4 | * Stratify OS is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Stratify OS is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Stratify OS. If not, see . 16 | * 17 | * 18 | */ 19 | 20 | #include "sos/fs/devfs.h" 21 | #include "mcu/spi.h" 22 | 23 | DEVFS_MCU_DRIVER_IOCTL_FUNCTION(spi, SPI_VERSION, I_MCU_TOTAL + I_SPI_TOTAL, mcu_spi_swap) 24 | -------------------------------------------------------------------------------- /src/mcu/ssp.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2016 Tyler Gilbert; 2 | * This file is part of Stratify OS. 3 | * 4 | * Stratify OS is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Stratify OS is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Stratify OS. If not, see . 16 | * 17 | * 18 | */ 19 | 20 | #include "sos/fs/devfs.h" 21 | #include "mcu/spi.h" 22 | 23 | DEVFS_MCU_DRIVER_IOCTL_FUNCTION(ssp, SPI_VERSION, I_MCU_TOTAL + I_SPI_TOTAL, mcu_ssp_swap) 24 | -------------------------------------------------------------------------------- /src/mcu/usb.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2016 Tyler Gilbert; 2 | * This file is part of Stratify OS. 3 | * 4 | * Stratify OS is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Stratify OS is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Stratify OS. If not, see . 16 | * 17 | * 18 | */ 19 | 20 | #include "sos/fs/devfs.h" 21 | #include "mcu/usb.h" 22 | 23 | DEVFS_MCU_DRIVER_IOCTL_FUNCTION(usb, USB_VERSION, I_MCU_TOTAL + I_USB_TOTAL, mcu_usb_isconnected) 24 | -------------------------------------------------------------------------------- /src/usbd/usbd_standard.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | #ifndef USBD_STANDARD_H_ 5 | #define USBD_STANDARD_H_ 6 | 7 | #include "usbd/control.h" 8 | 9 | int usbd_standard_request_handle_setup(usbd_control_t * context); 10 | 11 | u32 usbd_standard_request_set_interface(usbd_control_t * context); 12 | u32 usbd_standard_request_get_interface(usbd_control_t * context); 13 | void * usbd_control_add_ptr(usbd_control_t * context, void * ptr, u32 n); 14 | u32 usbd_standard_request_set_clear_feature (usbd_control_t * context, u32 sc); 15 | u32 usbd_standard_request_get_descriptor(usbd_control_t * context); 16 | u32 usbd_standard_request_set_address (usbd_control_t * context); 17 | u32 usbd_standard_request_set_config (usbd_control_t * context); 18 | u32 usbd_standard_request_get_config (usbd_control_t * context); 19 | u32 usbd_standard_request_get_status (usbd_control_t * context); 20 | 21 | 22 | #endif /* USBD_STANDARD_H_ */ 23 | -------------------------------------------------------------------------------- /src/device/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | if( ${CMSDK_BUILD_CONFIG} STREQUAL arm ) 3 | set(SOURCES 4 | microchip/sst25vf_share.c 5 | microchip/sst25vf_ssp_tmr.c 6 | microchip/sst25vf_ssp.c 7 | microchip/sst25vf_tmr.c 8 | microchip/sst25vf.c 9 | microchip/sst25vf_local.h 10 | #cfifo.c 11 | #devfifo.c 12 | device_fifo.c 13 | ffifo.c 14 | fifo.c 15 | stream_ffifo.c 16 | i2s_ffifo.c 17 | i2s_spi_ffifo.c 18 | full.c 19 | #led_pio.c 20 | #led_pwm.c 21 | null.c 22 | random.c 23 | auth_flash.c 24 | drive_cfi_local.h 25 | drive_cfi_spi.c 26 | drive_cfi_qspi.c 27 | drive_sdspi_local.h 28 | drive_ram.c 29 | drive_mmc.c 30 | #drive_mmc_dma.c 31 | drive_sdio.c 32 | drive_device.c 33 | #drive_sdio_dma.c 34 | drive_sdspi.c 35 | #drive_sdspi_dma.c 36 | #drive_sdssp.c 37 | switchboard.c 38 | #tty_uart.c 39 | #tty_usbbulk.c 40 | uartfifo.c 41 | urandom.c 42 | #usbfifo.c 43 | zero.c 44 | reset_tmr.c 45 | PARENT_SCOPE) 46 | endif() 47 | -------------------------------------------------------------------------------- /src/device/drive_sdio_dma.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | #include "mcu/sdio.h" 5 | 6 | #define mcu_sdio_open mcu_sdio_dma_open 7 | #define mcu_sdio_close mcu_sdio_dma_close 8 | #define mcu_sdio_setaction mcu_sdio_dma_setaction 9 | #define mcu_sdio_getinfo mcu_sdio_dma_getinfo 10 | #define mcu_sdio_setattr mcu_sdio_dma_setattr 11 | #define mcu_sdio_write mcu_sdio_dma_write 12 | #define mcu_sdio_read mcu_sdio_dma_read 13 | #define mcu_sdio_ioctl mcu_sdio_dma_ioctl 14 | #define mcu_sdio_getcsd mcu_sdio_dma_getcsd 15 | #define mcu_sdio_getcid mcu_sdio_dma_getcid 16 | #define mcu_sdio_getstatus mcu_sdio_dma_getstatus 17 | 18 | 19 | #define drive_sdio_open drive_sdio_dma_open 20 | #define drive_sdio_ioctl drive_sdio_dma_ioctl 21 | #define drive_sdio_read drive_sdio_dma_read 22 | #define drive_sdio_write drive_sdio_dma_write 23 | #define drive_sdio_close drive_sdio_dma_close 24 | 25 | 26 | #include "drive_sdio.c" 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/mcu/rtc.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2016 Tyler Gilbert; 2 | * This file is part of Stratify OS. 3 | * 4 | * Stratify OS is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Stratify OS is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Stratify OS. If not, see . 16 | * 17 | * 18 | */ 19 | 20 | #include "sos/fs/devfs.h" 21 | #include "mcu/rtc.h" 22 | 23 | DEVFS_MCU_DRIVER_IOCTL_FUNCTION(rtc, RTC_VERSION, I_MCU_TOTAL + I_RTC_TOTAL, mcu_rtc_set, mcu_rtc_get) 24 | -------------------------------------------------------------------------------- /src/mcu/spi_dma.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2016 Tyler Gilbert; 2 | * This file is part of Stratify OS. 3 | * 4 | * Stratify OS is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Stratify OS is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Stratify OS. If not, see . 16 | * 17 | * 18 | */ 19 | 20 | #include "sos/fs/devfs.h" 21 | #include "mcu/spi.h" 22 | 23 | DEVFS_MCU_DRIVER_IOCTL_FUNCTION(spi_dma, SPI_VERSION, I_MCU_TOTAL + I_SPI_TOTAL, mcu_spi_dma_swap) 24 | -------------------------------------------------------------------------------- /src/mcu/i2s.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2016 Tyler Gilbert; 2 | * This file is part of Stratify OS. 3 | * 4 | * Stratify OS is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Stratify OS is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Stratify OS. If not, see . 16 | * 17 | * 18 | */ 19 | 20 | #include "sos/fs/devfs.h" 21 | #include "mcu/i2s.h" 22 | 23 | DEVFS_MCU_DRIVER_IOCTL_FUNCTION(i2s, I2S_VERSION, I_MCU_TOTAL + I_I2S_TOTAL, mcu_i2s_mute, mcu_i2s_unmute) 24 | -------------------------------------------------------------------------------- /src/sys/sos_led.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #include "cortexm/cortexm.h" 4 | #include "sos/led.h" 5 | #include "sos/sos.h" 6 | 7 | void sos_led_startup() { 8 | const int factor = 10; 9 | int duty; 10 | for (int i = 0; i < 100; i++) { 11 | duty = i * factor; 12 | cortexm_svcall(sos_led_svcall_enable, 0); 13 | usleep(duty); 14 | cortexm_svcall(sos_led_svcall_disable, 0); 15 | usleep(100 * factor - duty); 16 | } 17 | 18 | for (int i = 0; i < 100; i++) { 19 | duty = i * factor; 20 | cortexm_svcall(sos_led_svcall_enable, 0); 21 | usleep(100 * factor - duty); 22 | cortexm_svcall(sos_led_svcall_disable, 0); 23 | usleep(duty); 24 | } 25 | } 26 | 27 | void sos_led_boot_startup(){ 28 | for(int i = 0; i < 3; i++){ 29 | cortexm_svcall(sos_led_svcall_enable, 0); 30 | usleep(100000); 31 | cortexm_svcall(sos_led_svcall_disable, 0); 32 | usleep(100000); 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /src/sys/termios/termios_local.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | #ifndef TERMIOS_H_ 5 | #define TERMIOS_H_ 6 | 7 | 8 | #include 9 | 10 | 11 | int termios_usbbulk_open(const devfs_handle_t * handle); 12 | int termios_usbbulk_ioctl(const devfs_handle_t * handle, int request, void * ctl); 13 | int termios_usbbulk_write(const devfs_handle_t * handle, devfs_async_t * wop); 14 | int termios_usbbulk_read(const devfs_handle_t * handle, devfs_async_t * rop); 15 | int termios_usbbulk_close(const devfs_handle_t * handle); 16 | 17 | int termios_uart_open(const devfs_handle_t * handle); 18 | int termios_uart_ioctl(const devfs_handle_t * handle, int request, void * ctl); 19 | int termios_uart_write(const devfs_handle_t * handle, devfs_async_t * wop); 20 | int termios_uart_read(const devfs_handle_t * handle, devfs_async_t * rop); 21 | int termios_uart_close(const devfs_handle_t * handle); 22 | 23 | 24 | #endif /* TERMIOS_H_ */ 25 | -------------------------------------------------------------------------------- /src/mcu/i2s_spi.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2016 Tyler Gilbert; 2 | * This file is part of Stratify OS. 3 | * 4 | * Stratify OS is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Stratify OS is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Stratify OS. If not, see . 16 | * 17 | * 18 | */ 19 | 20 | #include "sos/fs/devfs.h" 21 | #include "mcu/i2s.h" 22 | 23 | DEVFS_MCU_DRIVER_IOCTL_FUNCTION(i2s_spi, I2S_VERSION, I_MCU_TOTAL + I_I2S_TOTAL, mcu_i2s_spi_mute, mcu_i2s_spi_unmute) 24 | -------------------------------------------------------------------------------- /src/device/tty_usbbulk.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | #include "mcu/usb.h" 5 | #include "sos/dev/tty.h" 6 | 7 | int tty_usbbulk_open(const devfs_handle_t *handle) { return 0; } 8 | 9 | int tty_usbbulk_ioctl(const devfs_handle_t *handle, int request, void *ctl) { 10 | return mcu_usb_ioctl(handle, request, ctl); 11 | } 12 | 13 | int tty_usbbulk_write(const devfs_handle_t *handle, devfs_async_t *wop) { 14 | const tty_config_t *dcfg; 15 | dcfg = (const tty_config_t *)handle->config; 16 | wop->loc = dcfg->write_ep; 17 | return mcu_usb_write(handle, wop); 18 | } 19 | 20 | int tty_usbbulk_read( 21 | const devfs_handle_t *handle, 22 | devfs_async_t *rop) { // The stdio is read by the USB connection 23 | const tty_config_t *dcfg; 24 | dcfg = (const tty_config_t *)handle->config; 25 | rop->loc = dcfg->read_ep; 26 | return mcu_usb_read(handle, rop); 27 | } 28 | 29 | int tty_usbbulk_close(const devfs_handle_t *handle) { return 0; } 30 | -------------------------------------------------------------------------------- /src/mcu/qei.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2016 Tyler Gilbert; 2 | * This file is part of Stratify OS. 3 | * 4 | * Stratify OS is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Stratify OS is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Stratify OS. If not, see . 16 | * 17 | * 18 | */ 19 | 20 | #include "sos/fs/devfs.h" 21 | #include "mcu/qei.h" 22 | 23 | DEVFS_MCU_DRIVER_IOCTL_FUNCTION(qei, QEI_VERSION, I_MCU_TOTAL + I_QEI_TOTAL, mcu_qei_get, mcu_qei_getvelocity, mcu_qei_getindex) 24 | -------------------------------------------------------------------------------- /src/mcu/uart.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2016 Tyler Gilbert; 2 | * This file is part of Stratify OS. 3 | * 4 | * Stratify OS is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Stratify OS is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Stratify OS. If not, see . 16 | * 17 | * 18 | */ 19 | 20 | #include "sos/fs/devfs.h" 21 | #include "mcu/uart.h" 22 | 23 | DEVFS_MCU_DRIVER_IOCTL_FUNCTION(uart, UART_VERSION, I_MCU_TOTAL + I_UART_TOTAL, mcu_uart_get, mcu_uart_put, mcu_uart_flush) 24 | -------------------------------------------------------------------------------- /src/usbd/BUCK: -------------------------------------------------------------------------------- 1 | """ 2 | USB Device Library 3 | """ 4 | 5 | load("//deps/StratifyOS/src/library.bzl", "sos_library") 6 | 7 | srcs = select( 8 | { 9 | "toolchains//config:stratifyos": [ 10 | "usbd_control.c", 11 | "usbd_standard.c", 12 | "sos_link_transport_usb_link_descriptors.c", 13 | "sos_link_transport_usb_link_vcp_descriptors.c", 14 | "sos_link_transport_usb_vcp_descriptors.c", 15 | "sos_link_transport_usb_dual_vcp_descriptors.c", 16 | "sos_link_transport_usb.c", 17 | ], 18 | }, 19 | ) 20 | 21 | sos_library( 22 | name = "usbd", 23 | srcs = [ 24 | "usbd_control.c", 25 | "usbd_standard.c", 26 | "sos_link_transport_usb_link_descriptors.c", 27 | "sos_link_transport_usb_link_vcp_descriptors.c", 28 | "sos_link_transport_usb_vcp_descriptors.c", 29 | "sos_link_transport_usb_dual_vcp_descriptors.c", 30 | "sos_link_transport_usb.c", 31 | ], 32 | ) 33 | -------------------------------------------------------------------------------- /src/mcu/i2s_spi_dma.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2016 Tyler Gilbert; 2 | * This file is part of Stratify OS. 3 | * 4 | * Stratify OS is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Stratify OS is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Stratify OS. If not, see . 16 | * 17 | * 18 | */ 19 | 20 | #include "sos/fs/devfs.h" 21 | #include "mcu/i2s.h" 22 | 23 | DEVFS_MCU_DRIVER_IOCTL_FUNCTION(i2s_spi_dma, I2S_VERSION, I_MCU_TOTAL + I_I2S_TOTAL, mcu_i2s_spi_dma_mute, mcu_i2s_spi_dma_unmute) 24 | -------------------------------------------------------------------------------- /src/mcu/mem.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2016 Tyler Gilbert; 2 | * This file is part of Stratify OS. 3 | * 4 | * Stratify OS is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Stratify OS is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Stratify OS. If not, see . 16 | * 17 | * 18 | */ 19 | 20 | #include "sos/fs/devfs.h" 21 | #include "mcu/mem.h" 22 | 23 | DEVFS_MCU_DRIVER_IOCTL_FUNCTION(mem, MEM_VERSION, I_MCU_TOTAL + I_MEM_TOTAL, mcu_mem_erasepage, mcu_mem_getpageinfo, mcu_mem_writepage) 24 | -------------------------------------------------------------------------------- /src/mcu/pio.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2016 Tyler Gilbert; 2 | * This file is part of Stratify OS. 3 | * 4 | * Stratify OS is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Stratify OS is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Stratify OS. If not, see . 16 | * 17 | * 18 | */ 19 | 20 | #include "sos/fs/devfs.h" 21 | #include "mcu/pio.h" 22 | 23 | DEVFS_MCU_DRIVER_IOCTL_FUNCTION(pio, PIO_VERSION, I_MCU_TOTAL + I_PIO_TOTAL, mcu_pio_setmask, mcu_pio_clrmask, mcu_pio_get, mcu_pio_set) 24 | -------------------------------------------------------------------------------- /include/mcu/crypt.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #ifndef MCU_CRYPT_H_ 4 | #define MCU_CRYPT_H_ 5 | 6 | #include "sos/dev/crypt.h" 7 | #include "sos/fs/devfs.h" 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | typedef struct { 14 | crypt_attr_t attr; 15 | u32 port; 16 | } crypt_config_t; 17 | 18 | #define MCU_CRYPT_IOCTL_REQUEST_DECLARATION(driver_name) \ 19 | DEVFS_DRIVER_DECLARTION_IOCTL_REQUEST(driver_name, getinfo); \ 20 | DEVFS_DRIVER_DECLARTION_IOCTL_REQUEST(driver_name, setattr); \ 21 | DEVFS_DRIVER_DECLARTION_IOCTL_REQUEST(driver_name, setaction); \ 22 | DEVFS_DRIVER_DECLARTION_IOCTL_REQUEST(driver_name, getiv) 23 | 24 | #define MCU_CRYPT_DRIVER_DECLARATION(variant) \ 25 | DEVFS_DRIVER_DECLARTION(variant); \ 26 | MCU_CRYPT_IOCTL_REQUEST_DECLARATION(variant) 27 | 28 | MCU_CRYPT_DRIVER_DECLARATION(mcu_crypt); 29 | MCU_CRYPT_DRIVER_DECLARATION(mcu_crypt_dma); 30 | 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | 37 | #endif /* MCU_CRYPT_H_ */ 38 | -------------------------------------------------------------------------------- /src/sys/unistd/rmdir.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup unistd 4 | * @{ 5 | */ 6 | 7 | /*! \file */ 8 | 9 | #include "unistd_fs.h" 10 | #include "unistd_local.h" 11 | 12 | /*! \details This function removes the directory specified by \a path. 13 | * 14 | * \return Zero on success or -1 with errno (see \ref errno) set to: 15 | * - ENOENT: \a path is an empty string or the parent directory cannot be found 16 | * - EEXIST: \a path already exists 17 | * - ENOTDIR: \a path is not a directory 18 | * - ENOTEMPTY: \a path is not an empty directory 19 | * 20 | */ 21 | int rmdir(const char *path) { 22 | const sysfs_t *fs; 23 | 24 | if (sysfs_ispathinvalid(path) == true) { 25 | return -1; 26 | } 27 | 28 | fs = sysfs_find(path, true); 29 | if (fs != NULL) { 30 | int ret = fs->rmdir(fs->config, sysfs_stripmountpath(fs, path)); 31 | SYSFS_PROCESS_RETURN(ret); 32 | return ret; 33 | } 34 | errno = ENOENT; 35 | return -1; 36 | } 37 | 38 | /*! @} */ 39 | -------------------------------------------------------------------------------- /src/mcu/pwm.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2016 Tyler Gilbert; 2 | * This file is part of Stratify OS. 3 | * 4 | * Stratify OS is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Stratify OS is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Stratify OS. If not, see . 16 | * 17 | * 18 | */ 19 | 20 | #include "sos/fs/devfs.h" 21 | #include "mcu/pwm.h" 22 | 23 | DEVFS_MCU_DRIVER_IOCTL_FUNCTION(pwm, PWM_VERSION, I_MCU_TOTAL + I_PWM_TOTAL, mcu_pwm_setchannel, mcu_pwm_getchannel, mcu_pwm_set, mcu_pwm_get, mcu_pwm_enable, mcu_pwm_disable) 24 | -------------------------------------------------------------------------------- /src/mcu/tmr.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2016 Tyler Gilbert; 2 | * This file is part of Stratify OS. 3 | * 4 | * Stratify OS is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Stratify OS is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Stratify OS. If not, see . 16 | * 17 | * 18 | */ 19 | 20 | #include "sos/fs/devfs.h" 21 | #include "mcu/tmr.h" 22 | 23 | DEVFS_MCU_DRIVER_IOCTL_FUNCTION(tmr, TMR_VERSION, I_MCU_TOTAL + I_TMR_TOTAL, mcu_tmr_setchannel, mcu_tmr_getchannel, mcu_tmr_set, mcu_tmr_get, mcu_tmr_enable, mcu_tmr_disable) 24 | -------------------------------------------------------------------------------- /src/sys/sffs/sffs_dir.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | 5 | 6 | #ifndef SFFS_DIR_H_ 7 | #define SFFS_DIR_H_ 8 | 9 | #include "../sffs/sffs_local.h" 10 | 11 | typedef struct { 12 | serial_t serialno; 13 | } sffs_dir_lookup_t; 14 | 15 | /* 16 | * 17 | * Currently, there is only one directly. The root directly. 18 | * 19 | * The root directly has a list of serial numbers that are stored. 20 | * When a file is looked up, each item in the directory serial 21 | * number is traversed. Each entry contains the status 22 | * of the entry, a serial number, and a block. The block contains 23 | * the file header and the first segment of file data. 24 | * 25 | * 26 | * 27 | * 28 | */ 29 | 30 | #define SFFS_DIR_PARENT_EXISTS 1 31 | #define SFFS_DIR_PATH_EXISTS 2 32 | 33 | int sffs_dir_exists(const void * cfg, const char * path, sffs_dir_lookup_t * dest, int amode); 34 | int sffs_dir_lookup(const void * cfg, const char * path, sffs_dir_lookup_t * dest, int amode); 35 | 36 | 37 | #endif /* SFFS_DIR_H_ */ 38 | -------------------------------------------------------------------------------- /include/device/drive_sdio.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #ifndef DEVICE_SDIO_H_ 4 | #define DEVICE_SDIO_H_ 5 | 6 | #include "sos/dev/drive.h" 7 | #include "sos/dev/sdio.h" 8 | #include "sos/fs/devfs.h" 9 | 10 | typedef struct { 11 | u32 flags; 12 | void *async_buffer; 13 | devfs_async_t *async; 14 | int bytes_read; 15 | int async_nbyte; 16 | mcu_event_handler_t async_handler; 17 | } drive_sdio_state_t; 18 | 19 | typedef struct { 20 | devfs_device_t device; 21 | void * dma_read_buffer; 22 | u16 dma_read_buffer_size; 23 | } drive_sdio_config_t; 24 | 25 | int drive_sdio_open(const devfs_handle_t *handle) MCU_ROOT_EXEC_CODE; 26 | int drive_sdio_ioctl(const devfs_handle_t *handle, int request, void *ctl) 27 | MCU_ROOT_EXEC_CODE; 28 | int drive_sdio_read(const devfs_handle_t *handle, devfs_async_t *rop) MCU_ROOT_EXEC_CODE; 29 | int drive_sdio_write(const devfs_handle_t *handle, devfs_async_t *wop) MCU_ROOT_EXEC_CODE; 30 | int drive_sdio_close(const devfs_handle_t *handle); 31 | 32 | #endif /* DEVICE_SD_SPI_H_ */ 33 | -------------------------------------------------------------------------------- /src/sys/unistd/chmod.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup unistd 4 | * @{ 5 | */ 6 | 7 | /*! \file */ 8 | 9 | #include "unistd_fs.h" 10 | #include 11 | 12 | /*! \details This function changes the mode of the specified file 13 | * or directory. 14 | * 15 | * \return Zero on success or -1 with errno (see \ref errno) set to: 16 | * - EIO: IO Error 17 | * - ENAMETOOLONG: \a path exceeds PATH_MAX or a component of \a path exceeds NAME_MAX 18 | * - ENOENT: \a path does not exist 19 | * - EACCES: search permission is denied for a component of \a path 20 | * 21 | * 22 | */ 23 | int chmod(const char *path, mode_t mode) { 24 | const sysfs_t *fs; 25 | 26 | if (sysfs_ispathinvalid(path) == true) { 27 | return -1; 28 | } 29 | 30 | fs = sysfs_find(path, true); 31 | if (fs != NULL) { 32 | int ret = fs->chmod(fs->config, sysfs_stripmountpath(fs, path), mode); 33 | SYSFS_PROCESS_RETURN(ret); 34 | return ret; 35 | } 36 | errno = ENOENT; 37 | return -1; 38 | } 39 | 40 | /*! @} */ 41 | -------------------------------------------------------------------------------- /src/mcu/flash.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2016 Tyler Gilbert; 2 | * This file is part of Stratify OS. 3 | * 4 | * Stratify OS is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Stratify OS is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Stratify OS. If not, see . 16 | * 17 | * 18 | */ 19 | 20 | #include "sos/fs/devfs.h" 21 | #include "mcu/flash.h" 22 | 23 | DEVFS_MCU_DRIVER_IOCTL_FUNCTION(flash, FLASH_VERSION, I_MCU_TOTAL + I_FLASH_TOTAL, mcu_flash_eraseaddr, mcu_flash_erasepage, mcu_flash_getpage, mcu_flash_getsize, mcu_flash_getpageinfo, mcu_flash_writepage) 24 | -------------------------------------------------------------------------------- /include/mcu/hash.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #ifndef MCU_HASH_H_ 4 | #define MCU_HASH_H_ 5 | 6 | #include "sos/dev/hash.h" 7 | #include "sos/fs/devfs.h" 8 | 9 | typedef struct { 10 | hash_attr_t attr; 11 | u32 port; 12 | } hash_config_t; 13 | 14 | typedef struct { 15 | u32 attr; 16 | u32 port; 17 | } random_config_t; 18 | 19 | typedef random_config_t rng_config_t; 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | #define MCU_HASH_IOCTL_REQUEST_DECLARATION(driver_name) \ 26 | DEVFS_DRIVER_DECLARTION_IOCTL_REQUEST(driver_name, getinfo); \ 27 | DEVFS_DRIVER_DECLARTION_IOCTL_REQUEST(driver_name, setattr); \ 28 | DEVFS_DRIVER_DECLARTION_IOCTL_REQUEST(driver_name, setaction) 29 | 30 | #define MCU_HASH_DRIVER_DECLARATION(variant) \ 31 | DEVFS_DRIVER_DECLARTION(variant); \ 32 | MCU_HASH_IOCTL_REQUEST_DECLARATION(variant) 33 | 34 | MCU_HASH_DRIVER_DECLARATION(mcu_hash); 35 | MCU_HASH_DRIVER_DECLARATION(mcu_hash_dma); 36 | 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | 43 | #endif /* MCU_HASH_H_ */ 44 | -------------------------------------------------------------------------------- /src/sys/unistd/chown.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup unistd 4 | * @{ 5 | */ 6 | 7 | /*! \file */ 8 | 9 | #include "unistd_fs.h" 10 | #include 11 | 12 | /*! \details This function changes the mode of the specified file 13 | * or directory. 14 | * 15 | * \return Zero on success or -1 with errno (see \ref errno) set to: 16 | * - EIO: IO Error 17 | * - ENAMETOOLONG: \a path exceeds PATH_MAX or a component of \a path exceeds NAME_MAX 18 | * - ENOENT: \a path does not exist 19 | * - EACCES: search permission is denied for a component of \a path 20 | * 21 | * 22 | */ 23 | int chown(const char *path, uid_t uid, gid_t gid) { 24 | const sysfs_t *fs; 25 | 26 | if (sysfs_ispathinvalid(path) == true) { 27 | return -1; 28 | } 29 | 30 | fs = sysfs_find(path, true); 31 | if (fs != NULL) { 32 | int ret = fs->chown(fs->config, sysfs_stripmountpath(fs, path), uid, gid); 33 | SYSFS_PROCESS_RETURN(ret); 34 | return ret; 35 | } 36 | errno = ENOENT; 37 | return -1; 38 | } 39 | 40 | /*! @} */ 41 | -------------------------------------------------------------------------------- /include/posix/semaphore.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #ifndef SEMAPHORE_H_ 4 | #define SEMAPHORE_H_ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #define SEM_NAME_MAX 23 15 | 16 | typedef struct { 17 | int is_initialized; 18 | int value; 19 | int pshared; 20 | pid_t pid; 21 | int references; 22 | char name[SEM_NAME_MAX + 1]; 23 | int mode; 24 | } sem_t; 25 | 26 | #define SEM_FAILED ((void *)0) 27 | #define SEM_VALUE_MAX INT_MAX 28 | 29 | int sem_close(sem_t *sem); 30 | int sem_destroy(sem_t *sem); 31 | int sem_getvalue(sem_t *sem, int *sval); 32 | int sem_init(sem_t *sem, int pshared, unsigned int value); 33 | sem_t *sem_open(const char *name, int oflag, ...); 34 | int sem_post(sem_t *sem); 35 | int sem_timedwait(sem_t *sem, const struct timespec *timeout); 36 | int sem_trywait(sem_t *sem); 37 | int sem_unlink(const char *name); 38 | int sem_wait(sem_t *sem); 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | 44 | #endif /* SEMAPHORE_H_ */ 45 | -------------------------------------------------------------------------------- /include/mcu/mci.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup SPI_DEV SPI 4 | * @{ 5 | * 6 | * \ingroup DEV 7 | */ 8 | 9 | #ifndef mcu_mci_H_ 10 | #define mcu_mci_H_ 11 | 12 | 13 | #include "sos/dev/mci.h" 14 | 15 | #include "sos/fs/devfs.h" 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | int mcu_mci_open(const devfs_handle_t * handle) MCU_ROOT_CODE; 22 | int mcu_mci_read(const devfs_handle_t * handle, devfs_async_t * rop) MCU_ROOT_CODE; 23 | int mcu_mci_write(const devfs_handle_t * handle, devfs_async_t * wop) MCU_ROOT_CODE; 24 | int mcu_mci_ioctl(const devfs_handle_t * handle, int request, void * ctl) MCU_ROOT_CODE; 25 | int mcu_mci_close(const devfs_handle_t * handle) MCU_ROOT_CODE; 26 | 27 | int mcu_mci_getinfo(const devfs_handle_t * handle, void * ctl) MCU_ROOT_CODE; 28 | int mcu_mci_setattr(const devfs_handle_t * handle, void * ctl) MCU_ROOT_CODE; 29 | int mcu_mci_setaction(const devfs_handle_t * handle, void * ctl) MCU_ROOT_CODE; 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | 36 | #endif /* mcu_mci_H_ */ 37 | 38 | /*! @} */ 39 | -------------------------------------------------------------------------------- /src/device/BUCK: -------------------------------------------------------------------------------- 1 | """ 2 | Device library 3 | """ 4 | 5 | load("//deps/StratifyOS/src/library.bzl", "sos_library") 6 | 7 | sos_library( 8 | name = "device", 9 | srcs = [ 10 | "microchip/sst25vf_share.c", 11 | "microchip/sst25vf_ssp_tmr.c", 12 | "microchip/sst25vf_ssp.c", 13 | "microchip/sst25vf_tmr.c", 14 | "microchip/sst25vf.c", 15 | "device_fifo.c", 16 | "ffifo.c", 17 | "fifo.c", 18 | "stream_ffifo.c", 19 | "i2s_ffifo.c", 20 | "i2s_spi_ffifo.c", 21 | "full.c", 22 | "null.c", 23 | "random.c", 24 | "auth_flash.c", 25 | "drive_cfi_spi.c", 26 | "drive_cfi_qspi.c", 27 | "drive_ram.c", 28 | "drive_mmc.c", 29 | "drive_sdio.c", 30 | "drive_device.c", 31 | "drive_sdspi.c", 32 | "switchboard.c", 33 | "uartfifo.c", 34 | "urandom.c", 35 | "zero.c", 36 | "reset_tmr.c", 37 | ], 38 | headers = [ 39 | "drive_cfi_local.h", 40 | "drive_sdspi_local.h", 41 | "microchip/sst25vf_local.h", 42 | ] 43 | ) 44 | -------------------------------------------------------------------------------- /src/sys/sos_led_root.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #include "cortexm/cortexm.h" 4 | #include "sos/config.h" 5 | #include "sos/led.h" 6 | #include "sos/sos.h" 7 | 8 | void sos_led_svcall_enable(void *args) { 9 | CORTEXM_SVCALL_ENTER(); 10 | MCU_UNUSED_ARGUMENT(args); 11 | sos_led_root_enable(); 12 | } 13 | 14 | void sos_led_root_enable() { 15 | if (sos_config.debug.enable_led) { 16 | sos_config.debug.enable_led(); 17 | } 18 | } 19 | 20 | void sos_led_svcall_disable(void *args) { 21 | CORTEXM_SVCALL_ENTER(); 22 | MCU_UNUSED_ARGUMENT(args); 23 | sos_led_root_disable(); 24 | } 25 | 26 | void sos_led_root_disable() { 27 | if (sos_config.debug.disable_led) { 28 | sos_config.debug.disable_led(); 29 | } 30 | } 31 | 32 | void sos_led_svcall_error(void *args) { 33 | CORTEXM_SVCALL_ENTER(); 34 | MCU_UNUSED_ARGUMENT(args); 35 | sos_led_root_error(); 36 | } 37 | 38 | void sos_led_root_error() { 39 | while (1) { 40 | sos_led_root_enable(); 41 | cortexm_delay_ms(50); 42 | sos_led_root_disable(); 43 | cortexm_delay_ms(50); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/sys/unistd/_fstat.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup unistd 4 | * @{ 5 | */ 6 | 7 | /*! \file */ 8 | 9 | #include "unistd_fs.h" 10 | #include "unistd_local.h" 11 | 12 | /*! \details This function gets various file statistics for 13 | * the specified file descriptor. 14 | * 15 | * \return Zero on success or -1 on error with errno (see \ref errno) set to: 16 | * - EBADF: \a fildes is invalid 17 | * - EINVAL: \a buf is NULL 18 | * 19 | */ 20 | int fstat(int fildes, struct stat *buf); 21 | 22 | /*! \cond */ 23 | int _fstat(int fildes, struct stat *buf) { 24 | void *handle; 25 | const sysfs_t *fs; 26 | 27 | fildes = u_fildes_is_bad(fildes); 28 | if (fildes < 0) { 29 | errno = EBADF; 30 | return -1; 31 | } 32 | 33 | handle = get_handle(fildes); 34 | *buf = (struct stat){}; 35 | fs = get_fs(fildes); 36 | if (fs != NULL) { 37 | int ret = fs->fstat(fs->config, handle, buf); 38 | SYSFS_PROCESS_RETURN(ret); 39 | return ret; 40 | } 41 | errno = EBADF; 42 | return -1; 43 | } 44 | /*! \endcond */ 45 | 46 | /*! @} */ 47 | -------------------------------------------------------------------------------- /src/sys/unistd/lstat.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup unistd 4 | * @{ 5 | */ 6 | 7 | /*! \file */ 8 | 9 | #include "unistd_fs.h" 10 | 11 | /*! \details This function is equivalent to \ref stat() except 12 | * path refers to a symbolic link. 13 | * 14 | * \return Zero on success or -1 on error with errno (see \ref errno) set to: 15 | * - ENAMETOOLONG: \a path exceeds PATH_MAX or a component of \a path exceeds NAME_MAX 16 | * - ENOENT: \a path does not exist 17 | * - EACCES: search permission is denied for a component of \a path 18 | * 19 | */ 20 | int lstat( 21 | const char *path /*! The path the to symbolic link */, 22 | struct stat *buf /*! The destination buffer */) { 23 | const sysfs_t *fs; 24 | 25 | if (sysfs_ispathinvalid(path) == true) { 26 | return -1; 27 | } 28 | 29 | fs = sysfs_find(path, true); 30 | if (fs != NULL) { 31 | int ret = fs->lstat(fs->config, sysfs_stripmountpath(fs, path), buf); 32 | SYSFS_PROCESS_RETURN(ret); 33 | return ret; 34 | } 35 | errno = ENOENT; 36 | return -1; 37 | } 38 | 39 | /*! @} */ 40 | -------------------------------------------------------------------------------- /include/device/sys.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #ifndef DEVICE_SYS_H_ 4 | #define DEVICE_SYS_H_ 5 | 6 | #include "sos/dev/sys.h" 7 | #include "sos/dev/spi.h" 8 | 9 | #include "sos/fs/devfs.h" 10 | #include "cortexm/task.h" 11 | 12 | int sys_open(const devfs_handle_t *handle) MCU_ROOT_EXEC_CODE; 13 | int sys_ioctl(const devfs_handle_t *handle, int request, void *ctl) MCU_ROOT_EXEC_CODE; 14 | int sys_read(const devfs_handle_t *handle, devfs_async_t *rop) MCU_ROOT_EXEC_CODE; 15 | int sys_write(const devfs_handle_t *handle, devfs_async_t *wop) MCU_ROOT_EXEC_CODE; 16 | int sys_close(const devfs_handle_t *handle) MCU_ROOT_EXEC_CODE; 17 | 18 | int sys_23_open(const devfs_handle_t *handle) MCU_ROOT_EXEC_CODE; 19 | int sys_23_ioctl(const devfs_handle_t *handle, int request, void *ctl) MCU_ROOT_EXEC_CODE; 20 | int sys_23_read(const devfs_handle_t *handle, devfs_async_t *rop) MCU_ROOT_EXEC_CODE; 21 | int sys_23_write(const devfs_handle_t *handle, devfs_async_t *wop) MCU_ROOT_EXEC_CODE; 22 | int sys_23_close(const devfs_handle_t *handle) MCU_ROOT_EXEC_CODE; 23 | 24 | #endif /* DEVICE_SYS_H_ */ 25 | -------------------------------------------------------------------------------- /src/sys/unistd/_stat.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | /*! \addtogroup unistd 5 | * @{ 6 | */ 7 | 8 | /*! \file */ 9 | 10 | #include "unistd_fs.h" 11 | 12 | /*! \details This function gets various file statistics for 13 | * a given file name. 14 | * 15 | * \return Zero on success or -1 on error with errno (see \ref errno) set to: 16 | * - ENAMETOOLONG: \a path exceeds PATH_MAX or a component of \a path exceeds NAME_MAX 17 | * - ENOENT: \a path does not exist 18 | * - EACCES: search permission is denied for a component of \a path 19 | * 20 | */ 21 | int stat(const char * path, struct stat *buf); 22 | 23 | /*! \cond */ 24 | int _stat(const char * path, struct stat *buf){ 25 | const sysfs_t * fs; 26 | 27 | if ( sysfs_ispathinvalid(path) == true ){ 28 | return -1; 29 | } 30 | 31 | fs = sysfs_find(path, true); 32 | if ( fs != NULL ){ 33 | int ret = fs->stat(fs->config, sysfs_stripmountpath(fs, path), buf); 34 | SYSFS_PROCESS_RETURN(ret); 35 | return ret; 36 | } 37 | errno = ENOENT; 38 | return -1; 39 | } 40 | /*! \endcond */ 41 | 42 | /*! @} */ 43 | 44 | 45 | -------------------------------------------------------------------------------- /src/sys/sffs/sffs_tp.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | #ifndef CL_TP_H_ 5 | #define CL_TP_H_ 6 | 7 | #ifdef CL_TEST 8 | 9 | void sffs_tp_setfailroutine(void (*routine)()); //function called when failing 10 | int sffs_tp(const char * file, int line, const char * func, float failrate, const char * desc); //this is a test point 11 | int sffs_tp_createreport(const char * name); 12 | int sffs_getcount(const char * desc); 13 | 14 | 15 | #define CL_TP(failrate) sffs_tp(__FILE__, __LINE__, __func__, failrate, NULL) 16 | #define CL_TP_DESC(failrate, desc) sffs_tp(__FILE__, __LINE__, __func__, failrate, desc) 17 | 18 | #else 19 | #define CL_TP(failrate) 20 | #define CL_TP_DESC(failrate, desc) 21 | #endif 22 | 23 | #define NEVER_FAIL 24 | 25 | #ifdef NEVER_FAIL 26 | #define CL_PROB_COMMON (0.0) 27 | #define CL_PROB_RARE (0.0) 28 | #define CL_PROB_IMPROBABLE (0.0) 29 | #define CL_PROB_IMPOSSIBLE (0.0) 30 | #else 31 | #define CL_PROB_COMMON (0.005) 32 | #define CL_PROB_RARE (0.00001) 33 | #define CL_PROB_IMPROBABLE (0.000001) 34 | #define CL_PROB_IMPOSSIBLE (0.0) 35 | #endif 36 | 37 | 38 | #endif /* CL_TP_H_ */ 39 | -------------------------------------------------------------------------------- /src/link/link_debug.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #include "link_local.h" 4 | 5 | int link_debug_level = 0; 6 | 7 | void link_set_debug(int debug_level) { link_debug_level = debug_level; } 8 | 9 | int link_debug_printf(int x, const char *function, int line, const char *fmt, ...) { 10 | 11 | if (x <= link_debug_level) { 12 | 13 | switch (x) { 14 | case LINK_DEBUG_FATAL: 15 | printf("FATAL:"); 16 | break; 17 | case LINK_DEBUG_CRITICAL: 18 | printf("CRITICAL:"); 19 | break; 20 | case LINK_DEBUG_WARNING: 21 | printf("WARNING:"); 22 | break; 23 | case LINK_DEBUG_INFO: 24 | printf("INFO:"); 25 | break; 26 | case LINK_DEBUG_MESSAGE: 27 | printf("MESSAGE:"); 28 | break; 29 | case LINK_DEBUG_DEBUG: 30 | printf("DEBUG:"); 31 | break; 32 | } 33 | 34 | printf("%s():%d -> ", function, line); 35 | 36 | va_list args; 37 | va_start(args, fmt); 38 | vprintf(fmt, args); 39 | va_end(args); 40 | 41 | printf("\n"); 42 | fflush(stdout); 43 | 44 | return 1; 45 | } 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /src/sys/unistd/mkdir.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | /*! \addtogroup unistd 5 | * @{ 6 | */ 7 | 8 | /*! \file */ 9 | 10 | #include "unistd_local.h" 11 | #include "unistd_fs.h" 12 | 13 | /*! \details This function creates a new directory. 14 | * 15 | * \param path Path to the new directory 16 | * \param mode Ignored 17 | * 18 | * \return Zero on success or -1 with errno (see \ref errno) set to: 19 | * - ENOENT: \a path is an empty string or the parent directory cannot be found 20 | * - EEXIST: \a path already exists 21 | * - ENOSPC: Not enough space on the disk to add a new directory 22 | * 23 | */ 24 | int mkdir(const char *path, mode_t mode){ 25 | const sysfs_t * fs; 26 | 27 | if ( sysfs_ispathinvalid(path) == true ){ 28 | return -1; 29 | } 30 | 31 | fs = sysfs_find(path, true); 32 | if ( fs != NULL ){ 33 | int ret = fs->mkdir(fs->config, 34 | sysfs_stripmountpath(fs, path), 35 | mode); 36 | SYSFS_PROCESS_RETURN(ret); 37 | return ret; 38 | } 39 | errno = ENOENT; 40 | return -1; 41 | } 42 | 43 | /*! @} */ 44 | -------------------------------------------------------------------------------- /include/device/auth.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #ifndef DEVICE_AUTH_H_ 4 | #define DEVICE_AUTH_H_ 5 | 6 | #include 7 | 8 | #include "sos/dev/auth.h" 9 | #include "sos/fs/types.h" 10 | 11 | int auth_open(const devfs_handle_t *handle); 12 | 13 | __attribute__((unused)) int auth_ioctl(const devfs_handle_t *handle, int request, void *ctl); 14 | int auth_read(const devfs_handle_t *handle, devfs_async_t *async); 15 | int auth_write(const devfs_handle_t *handle, devfs_async_t *async); 16 | int auth_close(const devfs_handle_t *handle); 17 | 18 | #define AUTH_PURE_CODE_KEY_IS_FIRST 1 19 | #define AUTH_PURE_CODE_KEY_IS_SECOND 0 20 | 21 | int auth_pure_code_calculate_authentication( 22 | auth_token_t *dest, 23 | const auth_token_t *input, 24 | int key_is_first); 25 | 26 | #define AUTH_PURE_CODE_IS_ENCRYPT 1 27 | #define AUTH_PURE_CODE_IS_DECRYPT 0 28 | 29 | int auth_pure_code_encrypt_decrypt( 30 | u8* iv, //iv size is always 16 31 | const u8 *source, 32 | u8 *dest, 33 | size_t nbyte, 34 | int is_encrypt); 35 | 36 | extern const crypt_random_api_t random_root_api; 37 | 38 | #endif /* DEVICE_AUTH_H_ */ 39 | -------------------------------------------------------------------------------- /src/sys/process/_system.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | /*! \addtogroup SYSCALLS_PROCESS 5 | * @{ 6 | */ 7 | 8 | /*! \file */ 9 | 10 | #include "config.h" 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | #include "process_start.h" 17 | #include "../scheduler/scheduler_local.h" 18 | 19 | 20 | /*! \details This function creates a new process. 21 | * The calling process blocks until the new process completes. 22 | * 23 | * \return The return value of the child process. 24 | */ 25 | int _system(const char * s){ 26 | int err; 27 | int status; 28 | 29 | //Check for a NULL argument 30 | if ( s == NULL ){ 31 | return 1; //command processor is available 32 | } 33 | 34 | //Start the new process 35 | err = process_start(s, NULL); 36 | if ( err < 0 ){ 37 | //Process failed to start 38 | status = -1; 39 | } else { 40 | //Wait for the process to complete before returning 41 | if ( waitpid(err, &status, 0) < 0 ){ 42 | status = -1; 43 | } 44 | } 45 | 46 | //free the argument memory 47 | 48 | return status; 49 | } 50 | 51 | 52 | /*! @} */ 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /src/sys/unistd/_rename.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | /*! \addtogroup unistd 5 | * @{ 6 | */ 7 | 8 | /*! \file */ 9 | 10 | #include "unistd_fs.h" 11 | 12 | /*! \details This functions renames \a old to \a new. 13 | * 14 | * \return Zero on success or -1 with errno set to: 15 | * - EEXIST: \a new already exists 16 | * - EIO: IO error 17 | * - ENOENT: \a old does not exist 18 | * - EACCESS: \a old or \a new cannot be written 19 | */ 20 | int rename(const char *old, const char *new); 21 | 22 | /*! \cond */ 23 | int _rename(const char *old, const char *new){ 24 | const sysfs_t * fs_old; 25 | const sysfs_t * fs_new; 26 | 27 | if ( sysfs_ispathinvalid(old) == true ){ 28 | return -1; 29 | } 30 | 31 | if ( sysfs_ispathinvalid(new) == true ){ 32 | return -1; 33 | } 34 | 35 | fs_old = sysfs_find(old, true); 36 | fs_new = sysfs_find(new, true); 37 | 38 | if ( (fs_old == fs_new) && (fs_new != NULL) ){ 39 | return fs_new->rename(fs_new->config, sysfs_stripmountpath(fs_old, old), sysfs_stripmountpath(fs_new, new) ); 40 | } 41 | 42 | errno = ENOTSUP; 43 | return -1; 44 | } 45 | /*! \endcond */ 46 | 47 | /*! @} */ 48 | -------------------------------------------------------------------------------- /src/sys/unistd/_symlink.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | /*! \addtogroup unistd 5 | * @{ 6 | */ 7 | 8 | /*! \file */ 9 | 10 | #include "unistd_local.h" 11 | #include "unistd_fs.h" 12 | 13 | /*! \details This function creates a hard link between \a old and \a new. 14 | * 15 | * \return Zero on success or -1 on error with errno (see \ref errno) set to: 16 | * - ENOTSUP: operation not supported 17 | * 18 | */ 19 | int symlink(const char *old, const char *new); 20 | 21 | /*! \cond */ 22 | int _symlink(const char *old, const char *new){ 23 | const sysfs_t * fs_old; 24 | const sysfs_t * fs_new; 25 | 26 | if ( sysfs_ispathinvalid(old) == true ){ 27 | return -1; 28 | } 29 | 30 | if ( sysfs_ispathinvalid(new) == true ){ 31 | return -1; 32 | } 33 | 34 | fs_old = sysfs_find(old, true); 35 | fs_new = sysfs_find(new, true); 36 | 37 | if ( (fs_old == fs_new) && (fs_new != NULL) ){ 38 | return fs_new->symlink(&fs_new->config, 39 | sysfs_stripmountpath(fs_old, old), 40 | sysfs_stripmountpath(fs_new, new) 41 | ); 42 | } 43 | 44 | errno = ENOTSUP; 45 | return -1; 46 | } 47 | /*! \endcond */ 48 | 49 | /*! @} */ 50 | 51 | -------------------------------------------------------------------------------- /include/sos/dev/eeprom.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #ifndef SOS_DEV_EEPROM_H_ 4 | #define SOS_DEV_EEPROM_H_ 5 | 6 | #include 7 | 8 | #define EEPROM_VERSION (0x030000) 9 | #define EEPROM_IOC_IDENT_CHAR 'E' 10 | 11 | /*! \brief EEPROM Attribute Data Structure 12 | * \details This structure defines how the control structure 13 | * for opening or reconfiguring the EEPROM port. 14 | */ 15 | typedef struct MCU_PACK { 16 | u32 size; 17 | u32 resd[8]; 18 | } eeprom_attr_t; 19 | 20 | typedef struct MCU_PACK { 21 | u32 o_flags /*! EEPROM flags */; 22 | u32 size /*! EEPROM size */; 23 | u16 page_size /*! EEPROM page size */; 24 | u16 resd16; 25 | u32 resd[7]; 26 | } eeprom_info_t; 27 | 28 | #define I_EEPROM_GETVERSION _IOCTL(EEPROM_IOC_IDENT_CHAR, I_MCU_GETVERSION) 29 | #define I_EEPROM_GETINFO _IOCTLR(EEPROM_IOC_IDENT_CHAR, I_MCU_GETINFO, eeprom_info_t) 30 | #define I_EEPROM_SETATTR _IOCTLW(EEPROM_IOC_IDENT_CHAR, I_MCU_SETATTR, eeprom_attr_t) 31 | #define I_EEPROM_SETACTION _IOCTLW(EEPROM_IOC_IDENT_CHAR, I_MCU_SETACTION, mcu_action_t) 32 | 33 | 34 | 35 | #define I_EEPROM_TOTAL 0 36 | 37 | 38 | 39 | #endif /* SOS_DEV_EEPROM_H_ */ 40 | -------------------------------------------------------------------------------- /include/sos/ioctl.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #ifndef SOS_IOCTL_H_ 4 | #define SOS_IOCTL_H_ 5 | 6 | #define _IOCTLPARM_MASK 0x1FFF 7 | #define _IOCTLTYPE_MASK 0xFFFF 8 | #define _IOCTLIDENT_MASK 0xFF 9 | #define _IOCTLNUM_MASK 0xFF 10 | #define _IOCTL_ROOT 0x20000000 11 | #define _IOCTL_IN 0x40000000 12 | #define _IOCTL_OUT 0x80000000 13 | #define _IOCTL_INOUT (_IOCTL_IN | _IOCTL_OUT) 14 | #define _IOCTL_VOID 0 15 | 16 | #define _IOCTL(x,y) ((x << 8) | (y) | ((0 & _IOCTLPARM_MASK) << 16) | _IOCTL_VOID) 17 | #define _IOCTLR(x,y,t) ((x << 8) | (y) | ((sizeof(t) & _IOCTLPARM_MASK) << 16) | _IOCTL_OUT) 18 | #define _IOCTLW(x,y,t) ((x << 8) | (y) | ((sizeof(t) & _IOCTLPARM_MASK) << 16) | _IOCTL_IN) 19 | #define _IOCTLRW(x,y,t) ((x << 8) | (y) | ((sizeof(t) & _IOCTLPARM_MASK) << 16) | _IOCTL_INOUT) 20 | 21 | 22 | #define _IOCTL_NUM(i) ((i) & _IOCTLNUM_MASK) 23 | #define _IOCTL_IDENT(i) (((i) >> 8) & _IOCTLIDENT_MASK) 24 | #define _IOCTL_SIZE(i) (((i) >> 16) & _IOCTLPARM_MASK) 25 | #define _IOCTL_IOCTLR(i) ((i) & _IOCTL_OUT) 26 | #define _IOCTL_IOCTLRW(i) ((i) & _IOCTL_INOUT) 27 | #define _IOCTL_IOCTLW(i) ((i) & _IOCTL_IN) 28 | 29 | #endif /* SOS_IOCTL_H_ */ 30 | -------------------------------------------------------------------------------- /src/sys/signal/_kill.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup signal 4 | * @{ 5 | */ 6 | 7 | /*! \file */ 8 | 9 | #include 10 | #include 11 | 12 | #include "../scheduler/scheduler_local.h" 13 | #include "sig_local.h" 14 | 15 | /*! \details This function sends the signal \a signo to the process \a pid. 16 | * 17 | * \return Zero or -1 with errno (see \ref errno) set to: 18 | * - EINVAL: \a signo is not a valid signal number 19 | * - ESRCH: \a pid is not a valid process id 20 | * 21 | */ 22 | int kill(pid_t pid, int signo); 23 | 24 | /*! \cond */ 25 | int _kill(pid_t pid, int signo) { 26 | int tid; 27 | 28 | for (tid = 1; tid < task_get_total(); tid++) { 29 | if ((pid == task_get_pid(tid)) && (task_thread_asserted(tid) == 0)) { 30 | break; 31 | } 32 | } 33 | 34 | if ((pid == task_get_pid(task_get_current())) && (signo == SIGABRT)) { 35 | sos_trace_event(LINK_POSIX_TRACE_FATAL, "sigabrt", sizeof("sigabrt")); 36 | sos_trace_stack((u32)-1); 37 | } 38 | 39 | //! \todo Add permission error checking 40 | return signal_send(tid, signo, SI_USER, 0); 41 | } 42 | /*! \endcond */ 43 | 44 | /*! @} */ 45 | -------------------------------------------------------------------------------- /include/posix/sys/dirent.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup directory 4 | * @{ 5 | */ 6 | 7 | /*! \file */ 8 | 9 | #ifndef DIRENT_H_ 10 | #define DIRENT_H_ 11 | 12 | #include 13 | #include 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | 20 | #if !defined __link 21 | 22 | /*! \brief Directory Entry 23 | * \details This defines the data structure for a directory entry. 24 | * 25 | */ 26 | struct dirent { 27 | ino_t d_ino /*! \brief File Serial number */; 28 | char d_name[NAME_MAX+1] /*! \brief Name of entry */; 29 | }; 30 | 31 | /*! \cond */ 32 | typedef struct { 33 | const void * fs; 34 | void * handle; 35 | long loc; 36 | unsigned int checksum; 37 | } DIR; 38 | /*! \endcond */ 39 | 40 | int closedir(DIR * dirp); 41 | DIR * opendir(const char * dirname); 42 | struct dirent *readdir(DIR * dirp); 43 | int readdir_r(DIR * dirp, struct dirent * entry, struct dirent ** result); 44 | void rewinddir(DIR * dirp); 45 | void seekdir(DIR * dirp, long loc); 46 | long telldir(DIR * dirp); 47 | 48 | #endif 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif /* DIRENT_H_ */ 55 | 56 | /*! @} */ 57 | -------------------------------------------------------------------------------- /include/mcu/eeprom.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup EEPROM EEPROM (EE) 4 | * 5 | * @{ 6 | * 7 | * \ingroup IFACE_DEV 8 | * 9 | * \details The EEPROM module has functions to access the on chip EEPROM. 10 | * 11 | * 12 | */ 13 | 14 | /*! \file 15 | * \brief EEPROM Header file 16 | */ 17 | 18 | #ifndef DEV_EEPROM_H_ 19 | #define DEV_EEPROM_H_ 20 | 21 | #include "sos/dev/eeprom.h" 22 | 23 | #include "sos/fs/devfs.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | int mcu_eeprom_open(const devfs_handle_t * handle); 30 | int mcu_eeprom_read(const devfs_handle_t * handle, devfs_async_t * rop); 31 | int mcu_eeprom_write(const devfs_handle_t * handle, devfs_async_t * wop); 32 | int mcu_eeprom_ioctl(const devfs_handle_t * handle, int request, void * ctl); 33 | int mcu_eeprom_close(const devfs_handle_t * handle); 34 | 35 | int mcu_eeprom_getinfo(const devfs_handle_t * handle, void * ctl); 36 | int mcu_eeprom_setattr(const devfs_handle_t * handle, void * ctl); 37 | int mcu_eeprom_setaction(const devfs_handle_t * handle, void * ctl); 38 | 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | 44 | #endif // EEPROM_HEADER 45 | 46 | /*! @} */ 47 | -------------------------------------------------------------------------------- /src/mcu/mcu_sync_io.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #include 4 | 5 | #include "mcu/mcu.h" 6 | 7 | static int mcu_sync_io_complete(void *context, const mcu_event_t *data); 8 | 9 | int mcu_sync_io_complete(void *context, const mcu_event_t *data) { 10 | MCU_UNUSED_ARGUMENT(data); 11 | int *done = context; 12 | *done = 1234567; 13 | // return 0 to delete the callback 14 | return 0; 15 | } 16 | 17 | int mcu_sync_io( 18 | const devfs_handle_t *handle, 19 | int (*func)(const devfs_handle_t *, devfs_async_t *), 20 | int loc, 21 | const void *buf, 22 | int nbyte, 23 | int flags) { 24 | devfs_async_t op; 25 | volatile int done; 26 | int ret; 27 | 28 | if (nbyte == 0) { 29 | return 0; 30 | } 31 | 32 | done = 0; 33 | op.buf_const = buf; 34 | op.loc = loc; 35 | op.flags = flags | O_RDWR; 36 | op.nbyte = nbyte; 37 | op.handler.context = (void *)&done; 38 | op.handler.callback = mcu_sync_io_complete; 39 | op.tid = 0; 40 | ret = func(handle, &op); 41 | 42 | if (ret == 0) { 43 | 44 | while (done != 1234567) { // cppcheck-suppress[knownConditionTrueFalse] 45 | ; 46 | } 47 | return op.result; 48 | } 49 | return ret; 50 | } 51 | -------------------------------------------------------------------------------- /src/mcu/sys.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2016 Tyler Gilbert; 2 | * This file is part of Stratify OS. 3 | * 4 | * Stratify OS is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Stratify OS is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Stratify OS. If not, see . 16 | * 17 | * 18 | */ 19 | 20 | #include "device/sys.h" 21 | 22 | 23 | extern const uint32_t * mcu_core_vector_table[]; 24 | 25 | static bool security_lock MCU_SYS_MEM; 26 | static bool security_lock = true; 27 | 28 | uint32_t mcu_sys_getsecurity(){ 29 | if( security_lock == true ){ 30 | return (u32)mcu_core_vector_table[9]; 31 | } 32 | return 0xFFFFFFFF; //all allowed 33 | } 34 | 35 | void mcu_sys_setsecuritylock(bool enabled){ 36 | security_lock = enabled; 37 | } 38 | -------------------------------------------------------------------------------- /include/mcu/rng.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup rng_DEV RTC 4 | * @{ 5 | * 6 | * \ingroup DEV 7 | */ 8 | 9 | #ifndef _MCU_rng_H_ 10 | #define _MCU_rng_H_ 11 | 12 | #include "sos/dev/random.h" 13 | #include "sos/fs/devfs.h" 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | typedef struct MCU_PACK { 20 | u32 value; 21 | } rng_event_data_t; 22 | 23 | int mcu_rng_open(const devfs_handle_t *handle) MCU_ROOT_CODE; 24 | int mcu_rng_read(const devfs_handle_t *handle, devfs_async_t *rop) MCU_ROOT_CODE; 25 | int mcu_rng_write(const devfs_handle_t *handle, devfs_async_t *wop) MCU_ROOT_CODE; 26 | int mcu_rng_ioctl(const devfs_handle_t *handle, int request, void *ctl) MCU_ROOT_CODE; 27 | int mcu_rng_close(const devfs_handle_t *handle) MCU_ROOT_CODE; 28 | 29 | int mcu_rng_getinfo(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 30 | int mcu_rng_setattr(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 31 | int mcu_rng_setaction(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 32 | 33 | int mcu_rng_get(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif /* _MCU_rng_H_ */ 40 | 41 | /*! @} */ 42 | -------------------------------------------------------------------------------- /src/sys/sffs/tests.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | #ifndef TESTS_H_ 5 | #define TESTS_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | int test_run(bool file_test, bool dir_test); 13 | 14 | int test_dir(); 15 | int test_listdir(const char * path); 16 | int test_file(); 17 | 18 | int test_rw(const char * file); 19 | int test_rw_long(const char * file); 20 | int test_rw_short(const char * file); 21 | 22 | 23 | 24 | 25 | extern int test_close(void * handle); 26 | extern void * test_opendir(const char * path); 27 | extern int test_readdir_r(void * handle, int loc, struct dirent * entry); 28 | extern int test_closedir(void * handle); 29 | extern int test_fstat(void * handle, struct stat * stat); 30 | extern void * test_open(const char * path, int flags, int mode); 31 | extern int test_read(void * handle, int loc, void * buf, int nbyte); 32 | extern int test_write(void * handle, int loc, const void * buf, int nbyte); 33 | extern int test_close(void * handle); 34 | extern int test_remove(const char * path); 35 | extern int test_unlink(const char * path); 36 | extern int test_stat(const char * path, struct stat * stat); 37 | 38 | 39 | #endif /* TESTS_H_ */ 40 | -------------------------------------------------------------------------------- /link.cmake: -------------------------------------------------------------------------------- 1 | 2 | # Globs - these don't affect the build 3 | file(GLOB_RECURSE CMAKE_SOURCES ${CMAKE_SOURCE_DIR}/cmake/*) 4 | 5 | #Add sources to the project 6 | cmsdk_add_subdirectory(SOS_INTERFACE_SOURCELIST ${CMAKE_CURRENT_SOURCE_DIR}/include) 7 | cmsdk_add_subdirectory(SOS_SOURCELIST ${CMAKE_CURRENT_SOURCE_DIR}/src) 8 | 9 | 10 | set(CMSDK_ARCH link) 11 | 12 | cmsdk_library_target(BUILD_RELEASE StratifyOS "" release link) 13 | 14 | add_library(${BUILD_RELEASE_TARGET} STATIC) 15 | target_sources(${BUILD_RELEASE_TARGET} 16 | PRIVATE 17 | ${SOS_INTERFACE_SOURCELIST} 18 | ${SOS_SOURCELIST} 19 | ${CMAKE_SOURCES} 20 | ) 21 | 22 | target_include_directories(${BUILD_RELEASE_TARGET} 23 | PUBLIC 24 | $ 25 | $ 26 | ) 27 | 28 | 29 | cmsdk_library_target(BUILD_DEBUG StratifyOS "" debug link) 30 | add_library(${BUILD_DEBUG_TARGET} STATIC) 31 | cmsdk_copy_target(${BUILD_RELEASE_TARGET} ${BUILD_DEBUG_TARGET}) 32 | 33 | cmsdk_library("${BUILD_RELEASE_OPTIONS}") 34 | cmsdk_library("${BUILD_DEBUG_OPTIONS}") 35 | 36 | install(FILES include/mcu/mcu.h DESTINATION include/StratifyOS/mcu) 37 | install(DIRECTORY include/sos DESTINATION include/StratifyOS PATTERN CMakelists.txt EXCLUDE) 38 | 39 | 40 | -------------------------------------------------------------------------------- /src/sys/sffs/sffs_diag.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | 5 | 6 | #ifndef SFFS_DIAG_H_ 7 | #define SFFS_DIAG_H_ 8 | 9 | 10 | #include "sffs_local.h" 11 | 12 | typedef struct { 13 | int free_blocks; 14 | int allocated_blocks; 15 | int used_blocks; 16 | int dirty_blocks; 17 | int eraseable_blocks; 18 | int total_blocks; 19 | int dir_list_blocks; 20 | int file_data_blocks; 21 | int serialno_list_blocks; 22 | int del_serialno_list_blocks; 23 | int file_list_blocks; 24 | } sffs_diag_t; 25 | 26 | 27 | 28 | typedef struct { 29 | int list_blocks; 30 | int dirty_blocks; 31 | int used_blocks; 32 | int allocated_blocks; 33 | int total_blocks; 34 | } sffs_diag_file_t; 35 | 36 | 37 | int sffs_diag_scan(const void * cfg); 38 | int sffs_diag_get(const void * cfg, sffs_diag_t * dest); 39 | void sffs_diag_show(sffs_diag_t * data); 40 | 41 | int sffs_diag_getfile(const void * cfg, const char * path, sffs_diag_file_t * dest); 42 | void sffs_diag_showfile(sffs_diag_file_t * data); 43 | 44 | int sffs_diag_show_eraseable(const void * cfg); 45 | 46 | int sffs_diag_scandir(const void * cfg, serial_t serialno); 47 | int sffs_diag_scanfile(const void * cfg, serial_t serialno); 48 | 49 | 50 | 51 | #endif /* SFFS_DIAG_H_ */ 52 | -------------------------------------------------------------------------------- /src/link_transport/BUCK: -------------------------------------------------------------------------------- 1 | """ 2 | Transport Link library 3 | """ 4 | 5 | load("//deps/StratifyOS/src/library.bzl", "sos_library") 6 | 7 | cxx_library( 8 | name = "link_transport_host", 9 | target_compatible_with = ["//config:os_macos"], 10 | srcs = [ 11 | "link_transport_master.c", 12 | "link1_transport.c", 13 | "link1_transport_master.c", 14 | "link2_transport.c", 15 | "link2_transport_master.c", 16 | "link3_transport.c", 17 | "link3_transport_master.c", 18 | ], 19 | _cxx_toolchain = select({ 20 | "config//os:macos": "toolchains//:cxx", 21 | }), 22 | ) 23 | 24 | sos_library( 25 | name = "link_transport", 26 | srcs = [ 27 | "link1_transport.c", 28 | "link2_transport.c", 29 | "link3_transport.c", 30 | "link_transport_slave.c", 31 | "link1_transport_slave.c", 32 | "link2_transport_slave.c", 33 | "link3_transport_slave.c", 34 | ], 35 | deps = [ 36 | "//deps/StratifyOS/include:sos_include", 37 | "//config:stratifyos_config", 38 | ], 39 | _cxx_toolchain = select({ 40 | "toolchains//config:stratifyos": "toolchains//:arm-none-eabi", 41 | "config//os:macos": "toolchains//:cxx", 42 | }), 43 | ) 44 | -------------------------------------------------------------------------------- /src/sys/unistd/_link.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | /*! \addtogroup unistd 5 | * @{ 6 | */ 7 | 8 | /*! \file */ 9 | 10 | #include "unistd_local.h" 11 | #include "unistd_fs.h" 12 | 13 | /*! \details This function creates a hard link between \a old and \a new. 14 | * 15 | * \return Zero on success or -1 on error with errno (see \ref errno) set to: 16 | * - ENOTSUP: operation not supported 17 | * 18 | */ 19 | int link(const char *old, const char *new); 20 | 21 | /*! \cond */ 22 | int _link(const char *old, const char *new){ 23 | const sysfs_t * fs_old; 24 | const sysfs_t * fs_new; 25 | 26 | if ( sysfs_ispathinvalid(old) == true ){ 27 | return -1; 28 | } 29 | 30 | if ( sysfs_ispathinvalid(new) == true ){ 31 | return -1; 32 | } 33 | 34 | fs_old = sysfs_find(old, true); 35 | fs_new = sysfs_find(new, true); 36 | 37 | if ( (fs_old == fs_new) && (fs_new != NULL) ){ 38 | return fs_new->link(&fs_new->config, 39 | sysfs_stripmountpath(fs_old, old), 40 | sysfs_stripmountpath(fs_new, new) 41 | ); 42 | } 43 | 44 | if ( (fs_new == NULL) || (fs_old == NULL) ){ 45 | errno = ENOENT; 46 | } else { 47 | errno = ENOTSUP; 48 | } 49 | return -1; 50 | } 51 | /*! \endcond */ 52 | 53 | /*! @} */ 54 | 55 | -------------------------------------------------------------------------------- /src/crt/crt.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | #include "crt_common.h" 5 | 6 | extern u32 _signature; 7 | extern u32 _app_ram_size; 8 | 9 | void crt(char *path_arg); 10 | 11 | void *__dso_handle; 12 | 13 | extern struct _reent global_impure_data __attribute__((section(".global_reent"))); 14 | struct _reent global_impure_data = _REENT_INIT(global_impure_data); 15 | 16 | const appfs_file_t startup_data __attribute__((section(".startup"))) = { 17 | .hdr.name = "", 18 | .hdr.mode = 0555, 19 | .hdr.version = 0x0000, 20 | .hdr.id = "", 21 | .exec.startup = (u32)crt, 22 | .exec.code_start = (u32)&_text, 23 | .exec.code_size = (u32)&_text_size, 24 | .exec.ram_start = (u32)&_data, 25 | .exec.ram_size = (int)&_app_ram_size, 26 | .exec.data_size = (int)&_data_size, 27 | .exec.o_flags = APPFS_FLAG_IS_FLASH, 28 | .exec.signature = (u32)&_signature}; 29 | 30 | void crt(char *path_arg) { 31 | int ret; 32 | 33 | // Copy the heap to RAM -- since the heap copy is in no man's land this needs to be 34 | // privileged 35 | crt_load_data( 36 | &global_impure_data, startup_data.exec.code_size, startup_data.exec.data_size); 37 | 38 | crt_common(path_arg, &ret, startup_data.hdr.name); 39 | 40 | exit(ret); 41 | } 42 | -------------------------------------------------------------------------------- /include/device/netif_eth.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #ifndef DEVICE_NETIF_ENET_H_ 4 | #define DEVICE_NETIF_ENET_H_ 5 | 6 | #include "mcu/eth.h" 7 | #include "sos/dev/netif.h" 8 | #include "sos/fs/devfs.h" 9 | 10 | typedef struct { 11 | const char *buf; 12 | int *nbyte; 13 | int count; 14 | int timeout; 15 | uint8_t cmd[16]; 16 | devfs_async_t op; 17 | mcu_event_handler_t handler; 18 | u32 flags; 19 | } netif_eth_state_t; 20 | 21 | typedef struct { 22 | eth_config_t sdio; 23 | } netif_eth_config_t; 24 | 25 | int netif_eth_open(const devfs_handle_t *handle); 26 | int netif_eth_ioctl(const devfs_handle_t *handle, int request, void *ctl); 27 | int netif_eth_read(const devfs_handle_t *handle, devfs_async_t *rop); 28 | int netif_eth_write(const devfs_handle_t *handle, devfs_async_t *wop); 29 | int netif_eth_close(const devfs_handle_t *handle); 30 | 31 | int netif_eth_dma_open(const devfs_handle_t *handle); 32 | int netif_eth_dma_ioctl(const devfs_handle_t *handle, int request, void *ctl); 33 | int netif_eth_dma_read(const devfs_handle_t *handle, devfs_async_t *rop); 34 | int netif_eth_dma_write(const devfs_handle_t *handle, devfs_async_t *wop); 35 | int netif_eth_dma_close(const devfs_handle_t *handle); 36 | 37 | #endif /* DEVICE_NETIF_ENET_H_ */ 38 | -------------------------------------------------------------------------------- /src/sys/scheduler/scheduler_root.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | /*! \addtogroup SCHED 5 | * @{ 6 | * 7 | */ 8 | 9 | /*! \file */ 10 | 11 | #include "scheduler_root.h" 12 | 13 | void scheduler_svcall_set_delaymutex(void *args) { 14 | CORTEXM_SVCALL_ENTER(); 15 | sos_sched_table[task_get_current()].signal_delay_mutex = args; 16 | } 17 | 18 | void scheduler_root_set_trace_id(int tid, trace_id_t id) { 19 | sos_sched_table[tid].trace_id = id; 20 | } 21 | 22 | void scheduler_root_assert_active(int id, int unblock_type) { 23 | task_assert_active(id); 24 | scheduler_root_set_unblock_type(id, unblock_type); 25 | scheduler_root_deassert_aiosuspend(id); 26 | // Remove all blocks (mutex, timing, etc) 27 | sos_sched_table[id].block_object = NULL; 28 | sos_sched_table[id].wake.tv_sec = SCHEDULER_TIMEVAL_SEC_INVALID; 29 | sos_sched_table[id].wake.tv_usec = 0; 30 | } 31 | 32 | void scheduler_root_deassert_active(int id) { 33 | task_deassert_active(id); 34 | task_deassert_exec(id); // stop executing the task 35 | } 36 | 37 | 38 | void scheduler_root_assert(int id, int flag) { sos_sched_table[id].flags |= (1 << flag); } 39 | void scheduler_root_deassert(int id, int flag) { 40 | sos_sched_table[id].flags &= ~(1 << flag); 41 | } 42 | 43 | /*! @} */ 44 | -------------------------------------------------------------------------------- /include/mcu/eint.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup EINT_DEV EINT 4 | * @{ 5 | * 6 | * \ingroup DEV 7 | */ 8 | 9 | #ifndef _MCU_EINT_H_ 10 | #define _MCU_EINT_H_ 11 | 12 | #include "sos/dev/eint.h" 13 | 14 | #include "sos/fs/devfs.h" 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | typedef struct MCU_PACK { 21 | u32 status; 22 | u32 rising; 23 | u32 falling; 24 | } eint_event_t; 25 | 26 | typedef struct MCU_PACK { 27 | eint_attr_t attr; // default attributes 28 | u32 port; 29 | } eint_config_t; 30 | 31 | int mcu_eint_open(const devfs_handle_t *handle) MCU_ROOT_CODE; 32 | int mcu_eint_read(const devfs_handle_t *handle, devfs_async_t *rop) MCU_ROOT_CODE; 33 | int mcu_eint_write(const devfs_handle_t *handle, devfs_async_t *wop) MCU_ROOT_CODE; 34 | int mcu_eint_ioctl(const devfs_handle_t *handle, int request, void *ctl) MCU_ROOT_CODE; 35 | int mcu_eint_close(const devfs_handle_t *handle) MCU_ROOT_CODE; 36 | 37 | int mcu_eint_getinfo(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 38 | int mcu_eint_setattr(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 39 | int mcu_eint_setaction(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif /* EINT_H_ */ 46 | 47 | /*! @} */ 48 | -------------------------------------------------------------------------------- /include/mcu/adc.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup ADC_DEV ADC 4 | * @{ 5 | * 6 | * \ingroup DEV 7 | */ 8 | 9 | #ifndef _MCU_ADC_H_ 10 | #define _MCU_ADC_H_ 11 | 12 | #include "sos/dev/adc.h" 13 | #include "sos/fs/devfs.h" 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | typedef struct MCU_PACK { 20 | u32 value; 21 | } adc_event_t; 22 | 23 | typedef struct MCU_PACK { 24 | adc_attr_t attr; // default attributes 25 | u32 port; 26 | u32 reference_mv; 27 | } adc_config_t; 28 | 29 | #define MCU_ADC_IOCTL_REQUEST_DECLARATION(driver_name) \ 30 | DEVFS_DRIVER_DECLARTION_IOCTL_REQUEST(driver_name, getinfo); \ 31 | DEVFS_DRIVER_DECLARTION_IOCTL_REQUEST(driver_name, setattr); \ 32 | DEVFS_DRIVER_DECLARTION_IOCTL_REQUEST(driver_name, setaction) 33 | 34 | #define MCU_ADC_DRIVER_DECLARATION(variant) \ 35 | DEVFS_DRIVER_DECLARTION(variant); \ 36 | MCU_ADC_IOCTL_REQUEST_DECLARATION(variant) 37 | 38 | MCU_ADC_DRIVER_DECLARATION(mcu_adc); 39 | MCU_ADC_DRIVER_DECLARATION(mcu_adc_dma); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif // ADC_H_ 46 | 47 | /*! @} */ 48 | -------------------------------------------------------------------------------- /include/mcu/ltdc.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup LTDC_DEV LTDC 4 | * @{ 5 | * 6 | * \ingroup DEV 7 | */ 8 | 9 | #ifndef _MCU_LTDC_H_ 10 | #define _MCU_LTDC_H_ 11 | 12 | #include "sos/dev/ltdc.h" 13 | 14 | #include "sos/fs/devfs.h" 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | typedef struct MCU_PACK { 21 | u32 status; 22 | u32 rising; 23 | u32 falling; 24 | } ltdc_event_t; 25 | 26 | typedef struct MCU_PACK { 27 | ltdc_attr_t attr; // default attributes 28 | u32 port; 29 | } ltdc_config_t; 30 | 31 | int mcu_ltdc_open(const devfs_handle_t *handle) MCU_ROOT_CODE; 32 | int mcu_ltdc_read(const devfs_handle_t *handle, devfs_async_t *async) MCU_ROOT_CODE; 33 | int mcu_ltdc_write(const devfs_handle_t *handle, devfs_async_t *async) MCU_ROOT_CODE; 34 | int mcu_ltdc_ioctl(const devfs_handle_t *handle, int request, void *ctl) MCU_ROOT_CODE; 35 | int mcu_ltdc_close(const devfs_handle_t *handle) MCU_ROOT_CODE; 36 | 37 | int mcu_ltdc_getinfo(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 38 | int mcu_ltdc_setattr(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 39 | int mcu_ltdc_setaction(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif /* _MCU_LTDC_H_ */ 46 | 47 | /*! @} */ 48 | -------------------------------------------------------------------------------- /src/device/reset_tmr.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include "device/reset_tmr.h" 5 | #include "sos/dev/tmr.h" 6 | 7 | enum { RESET_TMR_FLAG_IS_INITIALIZED = (1 << 0) }; 8 | 9 | static int initialize(const devfs_handle_t *handle); 10 | 11 | int reset_tmr_open(const devfs_handle_t *handle) { 12 | // start counting 13 | } 14 | 15 | int reset_tmr_ioctl(const devfs_handle_t *handle, int request, void *ctl) { 16 | return SYSFS_SET_RETURN(ENOTSUP); 17 | } 18 | 19 | int reset_tmr_read(const devfs_handle_t *handle, devfs_async_t *rop) {} 20 | 21 | int reset_tmr_write(const devfs_handle_t *handle, devfs_async_t *wop) { 22 | // reset the tmr if "reset" written to tmr 23 | const int len = sizeof("reset"); 24 | if (wop->nbyte != len) { 25 | return SYSFS_SET_RETURN(EINVAL); 26 | } 27 | if (memcpy(wop->buf, "reset", sizeof("reset") == 0)) { 28 | 29 | return len; 30 | } 31 | 32 | return SYSFS_SET_RETURN(EINVAL); 33 | } 34 | 35 | int reset_tmr_close(const devfs_handle_t *handle) { return 0; } 36 | 37 | int initialize(const devfs_handle_t *handle) { 38 | reset_tmr_state_t *state = handle->state; 39 | if (state->o_flags & RESET_TMR_FLAG_IS_INITIALIZED) { 40 | return 0; 41 | } 42 | 43 | const reset_tmr_config_t *config = handle->config; 44 | const devfs_device_t *device = config->tmr_device; 45 | 46 | tmr_attr_t tmr; 47 | } 48 | -------------------------------------------------------------------------------- /include/device/drive_device.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #ifndef DRIVE_DEVICE_H 4 | #define DRIVE_DEVICE_H 5 | 6 | #include "sos/dev/drive.h" 7 | #include "sos/fs/devfs.h" 8 | 9 | typedef struct { 10 | u32 flags; 11 | } drive_device_state_t; 12 | 13 | typedef struct { 14 | devfs_device_t device; 15 | } drive_device_config_t; 16 | 17 | int drive_device_open(const devfs_handle_t *handle) MCU_ROOT_EXEC_CODE; 18 | int drive_device_ioctl(const devfs_handle_t *handle, int request, void *ctl) 19 | MCU_ROOT_EXEC_CODE; 20 | int drive_device_read(const devfs_handle_t *handle, devfs_async_t *rop) 21 | MCU_ROOT_EXEC_CODE; 22 | int drive_device_write(const devfs_handle_t *handle, devfs_async_t *wop) 23 | MCU_ROOT_EXEC_CODE; 24 | int drive_device_close(const devfs_handle_t *handle) MCU_ROOT_EXEC_CODE; 25 | 26 | int drive_device_dma_open(const devfs_handle_t *handle) MCU_ROOT_EXEC_CODE; 27 | int drive_device_dma_ioctl(const devfs_handle_t *handle, int request, void *ctl) 28 | MCU_ROOT_EXEC_CODE; 29 | int drive_device_dma_read(const devfs_handle_t *handle, devfs_async_t *rop) 30 | MCU_ROOT_EXEC_CODE; 31 | int drive_device_dma_write(const devfs_handle_t *handle, devfs_async_t *wop) 32 | MCU_ROOT_EXEC_CODE; 33 | int drive_device_dma_close(const devfs_handle_t *handle) MCU_ROOT_EXEC_CODE; 34 | 35 | #endif // DRIVE_DEVICE_H 36 | -------------------------------------------------------------------------------- /src/sys/unistd/_close.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | /*! \addtogroup unistd 5 | * @{ 6 | */ 7 | 8 | /*! \file 9 | */ 10 | 11 | #include "../scheduler/scheduler_local.h" 12 | #include "sos/debug.h" 13 | #include "sos/fs/sysfs.h" 14 | #include "sos/sos.h" 15 | #include "sys/socket.h" 16 | #include "unistd_fs.h" 17 | #include "unistd_local.h" 18 | 19 | /*! \details This function closes the file associated 20 | * with the specified descriptor. 21 | * \param fildes The File descriptor \a fildes. 22 | * \return Zero on success or -1 on error with errno (see \ref errno) set to: 23 | * - EBADF: Invalid file descriptor 24 | */ 25 | int close(int fildes); 26 | 27 | /*! \cond */ 28 | int _close(int fildes) { 29 | scheduler_check_cancellation(); 30 | // Close the file if it's open 31 | int ret; 32 | 33 | if (FILDES_IS_SOCKET(fildes)) { 34 | if (sos_config.socket_api != 0) { 35 | return SOS_SOCKET_API()->close(fildes & ~FILDES_SOCKET_FLAG); 36 | } 37 | errno = EBADF; 38 | return -1; 39 | } 40 | 41 | fildes = u_fildes_is_bad(fildes); 42 | if (fildes < 0) { 43 | // check to see if fildes is a socket 44 | errno = EBADF; 45 | return -1; 46 | } 47 | 48 | ret = sysfs_file_close(get_open_file(fildes)); 49 | u_reset_fildes(fildes); 50 | return ret; 51 | } 52 | /*! \endcond */ 53 | 54 | /*! @} */ 55 | -------------------------------------------------------------------------------- /src/sys/pwd/pwd.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | #include 5 | #include 6 | 7 | /*! \addtogroup PWD Password 8 | * @{ 9 | * 10 | * \ingroup POSIX 11 | * 12 | * \details This interface is not supported in this version. 13 | * 14 | */ 15 | 16 | /*! \file */ 17 | 18 | 19 | /*! \details Not implemented (stub only). 20 | * \return NULL 21 | */ 22 | struct passwd *getpwuid (uid_t uid){ 23 | return NULL; 24 | } 25 | 26 | /*! \details Not implemented (stub only). 27 | * \return NULL 28 | */ 29 | struct passwd *getpwnam (const char * name){ 30 | return NULL; 31 | } 32 | 33 | /*! \details Not implemented (stub only). 34 | * \return 0 35 | */ 36 | int getpwnam_r(const char * name, struct passwd * pwd, char * buffer, size_t bufsize, struct passwd **result){ 37 | return 0; 38 | } 39 | 40 | /*! \details Not implemented (stub only). 41 | * \return 0 42 | */ 43 | int getpwuid_r (uid_t uid, struct passwd * pwd, char * buffer, size_t bufsize, struct passwd **result){ 44 | return 0; 45 | } 46 | 47 | /*! \details Not implemented (stub only). 48 | * \return NULL 49 | */ 50 | struct passwd *getpwent (){ 51 | return NULL; 52 | } 53 | 54 | /*! \details Not implemented (stub only). 55 | */ 56 | void setpwent (){ 57 | 58 | } 59 | 60 | /*! \details Not implemented (stub only). 61 | */ 62 | void endpwent (){ 63 | 64 | } 65 | 66 | /*! @} */ 67 | -------------------------------------------------------------------------------- /src/sys/unistd/fsync.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | /*! \addtogroup unistd 5 | * @{ 6 | */ 7 | 8 | /*! \file */ 9 | 10 | #include 11 | #include 12 | 13 | #include "../scheduler/scheduler_local.h" 14 | #include "sys/socket.h" 15 | #include "unistd_local.h" 16 | 17 | /*! \details This function performs a control request on the device 18 | * associated with \a fildes. \a request is specific to the device. 19 | * The value of \a request determines what value should be passed 20 | * as the \a ctl argument. 21 | * 22 | * \param fildes The file descriptor returned by \ref open() 23 | * 24 | * \return The number of bytes actually read of -1 with errno (see \ref errno) set to: 25 | * - EBADF: \a fildes is bad 26 | * - EIO: IO error 27 | * - EAGAIN: O_NONBLOCK is set for \a fildes and the device is busy 28 | * 29 | */ 30 | int fsync(int fildes) { 31 | scheduler_check_cancellation(); 32 | 33 | fildes = u_fildes_is_bad(fildes); 34 | if (fildes < 0) { 35 | // check to see if fildes is a socket 36 | errno = EBADF; 37 | return -1; 38 | } 39 | 40 | if (FILDES_IS_SOCKET(fildes)) { 41 | if (sos_config.socket_api != 0) { 42 | return SOS_SOCKET_API()->fsync(fildes); 43 | } 44 | errno = EBADF; 45 | return -1; 46 | } 47 | 48 | return sysfs_file_fsync(get_open_file(fildes)); 49 | } 50 | 51 | /*! @} */ 52 | -------------------------------------------------------------------------------- /include/sos/dev/i2s_ffifo.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup SYS_USBFIFO USB FIFO 4 | * @{ 5 | * 6 | * 7 | * \ingroup IFACE_DEV 8 | * 9 | * \details This device driver is used to add a FIFO read buffer to a USB port. 10 | * 11 | * 12 | * 13 | */ 14 | 15 | /*! \file 16 | */ 17 | 18 | #ifndef SOS_DEV_I2S_FFIFO_H_ 19 | #define SOS_DEV_I2S_FFIFO_H_ 20 | 21 | #include 22 | #include "ffifo.h" 23 | #include "i2s.h" 24 | 25 | 26 | typedef struct MCU_PACK { 27 | ffifo_attr_t tx; 28 | ffifo_attr_t rx; 29 | } i2s_ffifo_attr_t; 30 | 31 | typedef struct MCU_PACK { 32 | ffifo_info_t ffifo; 33 | u32 access_count; 34 | s32 error; 35 | } i2s_ffifo_channel_info_t; 36 | 37 | typedef struct MCU_PACK { 38 | i2s_ffifo_channel_info_t rx; 39 | i2s_ffifo_channel_info_t tx; 40 | } i2s_ffifo_info_t; 41 | 42 | 43 | #define I2S_FFIFO_VERSION (0x030000) 44 | #define I2S_FFIFO_IOC_IDENT_CHAR 'j' 45 | 46 | #define I_I2S_FFIFO_GETVERSION _IOCTL(I2S_FFIFO_IOC_IDENT_CHAR, I_MCU_GETVERSION) 47 | #define I_I2S_FFIFO_GETINFO _IOCTLR(I2S_FFIFO_IOC_IDENT_CHAR, I_MCU_GETINFO, i2s_ffifo_info_t) 48 | #define I_I2S_FFIFO_SETATTR _IOCTLW(I2S_FFIFO_IOC_IDENT_CHAR, I_MCU_SETATTR, i2s_ffifo_attr_t) 49 | #define I_I2S_FFIFO_SETACTION _IOCTLW(I2S_FFIFO_IOC_IDENT_CHAR, I_MCU_SETACTION, mcu_action_t) 50 | 51 | 52 | #endif /* SOS_DEV_USBFIFO_H_ */ 53 | 54 | 55 | /*! @} */ 56 | -------------------------------------------------------------------------------- /include/mcu/qspi.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup QSPI_DEV QSPI 4 | * @{ 5 | * 6 | * \ingroup DEV 7 | */ 8 | 9 | #ifndef _MCU_QSPI_H_ 10 | #define _MCU_QSPI_H_ 11 | 12 | #include "sos/dev/qspi.h" 13 | #include "sos/fs/devfs.h" 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | typedef struct MCU_PACK { 20 | u32 value; 21 | } qspi_event_data_t; 22 | 23 | typedef struct MCU_PACK { 24 | qspi_attr_t attr; // default attributes 25 | u32 port; 26 | } qspi_config_t; 27 | 28 | #define MCU_QSPI_IOCTL_REQUEST_DECLARATION(driver_name) \ 29 | DEVFS_DRIVER_DECLARTION_IOCTL_REQUEST(driver_name, getinfo); \ 30 | DEVFS_DRIVER_DECLARTION_IOCTL_REQUEST(driver_name, setattr); \ 31 | DEVFS_DRIVER_DECLARTION_IOCTL_REQUEST(driver_name, setaction); \ 32 | DEVFS_DRIVER_DECLARTION_IOCTL_REQUEST(driver_name, execcommand) 33 | 34 | #define MCU_QSPI_DRIVER_DECLARATION(variant) \ 35 | DEVFS_DRIVER_DECLARTION(variant); \ 36 | MCU_QSPI_IOCTL_REQUEST_DECLARATION(variant) 37 | 38 | MCU_QSPI_DRIVER_DECLARATION(mcu_qspi); 39 | MCU_QSPI_DRIVER_DECLARATION(mcu_qspi_dma); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif /* _MCU_QSPI_H_ */ 46 | 47 | /*! @} */ 48 | -------------------------------------------------------------------------------- /src/link_transport/link_transport_slave.c: -------------------------------------------------------------------------------- 1 | 2 | #include "sos/link/transport.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "cortexm/cortexm.h" 9 | 10 | #include "sos/boot/boot_debug.h" 11 | #include "sos/sos.h" 12 | 13 | void transport_svcall_fatal(void *args) { 14 | CORTEXM_SVCALL_ENTER(); 15 | sos_config.event_handler(SOS_EVENT_ROOT_FATAL, args); 16 | } 17 | 18 | int link_transport_slaveread( 19 | link_transport_driver_t *driver, 20 | void *buf, 21 | int nbyte, 22 | int (*callback)(void *, void *, int), 23 | void *context) { 24 | // get sos board config for link transport 25 | if (driver->transport_read == NULL) { 26 | cortexm_svcall(transport_svcall_fatal, "transport read"); 27 | } 28 | return driver->transport_read(driver, buf, nbyte, callback, context); 29 | } 30 | 31 | int link_transport_slavewrite( 32 | link_transport_driver_t *driver, 33 | const void *buf, 34 | int nbyte, 35 | int (*callback)(void *, void *, int), 36 | void *context) { 37 | // get sos board config for link transport 38 | if (driver->transport_write == NULL) { 39 | cortexm_svcall(transport_svcall_fatal, "transport write"); 40 | } 41 | return driver->transport_write(driver, buf, nbyte, callback, context); 42 | } 43 | 44 | u64 link_transport_gettime() { 45 | // the slave using blocking calls to read() so there is not need to manage timing 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /src/link/link_time.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #include "link_local.h" 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | int link_settime(link_transport_mdriver_t *driver, struct link_tm *t) { 10 | int fd; 11 | int ret; 12 | struct link_tm ltm; 13 | 14 | memcpy(<m, t, sizeof(struct link_tm)); 15 | 16 | link_debug(LINK_DEBUG_MESSAGE, "open rtc device"); 17 | fd = link_open(driver, "/dev/rtc", LINK_O_RDWR); 18 | if (fd < 0) { 19 | return -1; 20 | } 21 | 22 | link_debug(LINK_DEBUG_MESSAGE, "write time"); 23 | ret = link_ioctl(driver, fd, I_RTC_SET, <m); 24 | 25 | link_debug(LINK_DEBUG_MESSAGE, "close"); 26 | if (link_close(driver, fd) < 0) { 27 | return -1; 28 | } 29 | 30 | return ret; 31 | } 32 | 33 | int link_gettime(link_transport_mdriver_t *driver, struct link_tm *t) { 34 | int fd; 35 | int ret; 36 | 37 | link_debug(LINK_DEBUG_MESSAGE, "Open RTC fildes"); 38 | fd = link_open(driver, "/dev/rtc", LINK_O_RDWR); 39 | if (fd < 0) { 40 | return -1; 41 | } 42 | 43 | ret = link_ioctl(driver, fd, I_RTC_GET, t); 44 | if (ret < 0) { 45 | link_error("Failed to I_RTC_GET"); 46 | } 47 | 48 | link_debug(LINK_DEBUG_MESSAGE, "Close RTC fildes"); 49 | if (link_close(driver, fd) < 0) { 50 | link_error("failed to close"); 51 | return -1; 52 | } 53 | 54 | return ret; 55 | } 56 | 57 | /*! @} */ 58 | -------------------------------------------------------------------------------- /src/sys/malloc/malloc_local.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #ifndef MALLOC_LOCAL_H_ 4 | #define MALLOC_LOCAL_H_ 5 | 6 | #include "config.h" 7 | #include <_ansi.h> 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include "cortexm/task.h" 18 | 19 | typedef struct MCU_PACK { 20 | u16 task_id; 21 | u16 num_chunks; 22 | u32 actual_size; 23 | u32 checksum; 24 | } malloc_chunk_header_t; 25 | 26 | #define MALLOC_DATA_SIZE (CONFIG_MALLOC_CHUNK_SIZE - (sizeof(malloc_chunk_header_t))) 27 | 28 | typedef struct { 29 | malloc_chunk_header_t header; 30 | char memory[MALLOC_DATA_SIZE]; 31 | } malloc_chunk_t; 32 | 33 | void malloc_set_chunk_used( 34 | struct _reent *reent, 35 | malloc_chunk_t *chunk, 36 | u16 num_chunks, 37 | u32 actual_size); 38 | void malloc_set_chunk_free(malloc_chunk_t *chunk, u16 num_chunks); 39 | int malloc_chunk_is_free(malloc_chunk_t *chunk); 40 | u16 malloc_calc_num_chunks(u32 size); 41 | malloc_chunk_t *malloc_chunk_from_addr(void *addr); 42 | 43 | int malloc_get_more_memory(struct _reent *reent_ptr, u32 size, int is_new_heap); 44 | 45 | 46 | void malloc_free_task_r(struct _reent *reent_ptr, int task_id); 47 | 48 | void __malloc_lock(struct _reent *ptr); 49 | void __malloc_unlock(struct _reent *ptr); 50 | 51 | #endif /* MALLOC_LOCAL_H_ */ 52 | -------------------------------------------------------------------------------- /src/sys/unistd/_fork.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | /*! \addtogroup UNI_PROCESS 5 | * @{ 6 | */ 7 | 8 | /*! \file */ 9 | 10 | #include 11 | #include 12 | 13 | /*! \details This function is not supported. 14 | * 15 | * \return Zero on success or -1 on error with errno (see \ref errno) set to: 16 | * - ENOTSUP: function is not supported 17 | * 18 | */ 19 | pid_t fork(); 20 | 21 | pid_t _fork(){ 22 | //This function can not be supported unless the CPU has an MMU 23 | errno = ENOTSUP; 24 | return -1; 25 | } 26 | 27 | /*! \details This function is not supported. 28 | * 29 | * \return Zero on success or -1 on error with errno (see \ref errno) set to: 30 | * - ENOTSUP: function is not supported 31 | * 32 | */ 33 | pid_t vfork(); 34 | 35 | pid_t _vfork(){ 36 | 37 | //create a new process copying the characteristic of the current process (has new process ID -- all else identical) 38 | 39 | //manipulate the stack of the current task so that the child process ID is immediately returned 40 | 41 | 42 | //Force a switch to the child process -- block the parent process execution 43 | 44 | 45 | //return 0 (as the child) 46 | 47 | 48 | //when exec() or _exit() is run -- the parent process needs to be woken up 49 | 50 | 51 | //Use the following label as the PC for the parent 52 | //parent_process_resume: 53 | 54 | errno = ENOTSUP; 55 | return -1; 56 | } 57 | 58 | /*! @} */ 59 | 60 | -------------------------------------------------------------------------------- /include/mcu/rtc.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup RTC_DEV RTC 4 | * @{ 5 | * 6 | * \ingroup DEV 7 | */ 8 | 9 | #ifndef _MCU_RTC_H_ 10 | #define _MCU_RTC_H_ 11 | 12 | #include "sos/dev/rtc.h" 13 | 14 | #include "sos/fs/devfs.h" 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | typedef struct MCU_PACK { 21 | u32 value; 22 | } rtc_event_data_t; 23 | 24 | typedef struct { 25 | rtc_time_t time; 26 | } rtc_event_t; 27 | 28 | typedef struct { 29 | rtc_attr_t attr; 30 | u32 port; 31 | } rtc_config_t; 32 | 33 | int mcu_rtc_open(const devfs_handle_t *handle) MCU_ROOT_CODE; 34 | int mcu_rtc_read(const devfs_handle_t *handle, devfs_async_t *rop) MCU_ROOT_CODE; 35 | int mcu_rtc_write(const devfs_handle_t *handle, devfs_async_t *wop) MCU_ROOT_CODE; 36 | int mcu_rtc_ioctl(const devfs_handle_t *handle, int request, void *ctl) MCU_ROOT_CODE; 37 | int mcu_rtc_close(const devfs_handle_t *handle) MCU_ROOT_CODE; 38 | 39 | int mcu_rtc_getinfo(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 40 | int mcu_rtc_setattr(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 41 | int mcu_rtc_setaction(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 42 | 43 | int mcu_rtc_set(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 44 | int mcu_rtc_get(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif /* _MCU_RTC_H_ */ 51 | 52 | /*! @} */ 53 | -------------------------------------------------------------------------------- /include/mcu/crc.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #ifndef MCU_CRC_H_ 4 | #define MCU_CRC_H_ 5 | 6 | #include "sos/dev/crc.h" 7 | #include "sos/fs/devfs.h" 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | typedef struct MCU_PACK { 14 | crc_attr_t attr; // default attributes 15 | u32 port; 16 | } crc_config_t; 17 | 18 | typedef struct MCU_PACK { 19 | u32 value; 20 | } crc_event_data_t; 21 | 22 | u32 mcu_calc_crc32(u32 seed, u32 polynomial, const u8 *buffer, u32 nbyte); 23 | u16 mcu_calc_crc16(u16 seed, u16 polynomial, const u8 *buffer, u32 nbyte); 24 | u8 mcu_calc_crc7(u8 seed, u8 polynomial, const u8 *chr, u32 len); 25 | 26 | int mcu_crc_open(const devfs_handle_t *handle) MCU_ROOT_CODE; 27 | int mcu_crc_read(const devfs_handle_t *handle, devfs_async_t *rop) MCU_ROOT_CODE; 28 | int mcu_crc_write(const devfs_handle_t *handle, devfs_async_t *wop) MCU_ROOT_CODE; 29 | int mcu_crc_ioctl(const devfs_handle_t *handle, int request, void *ctl) MCU_ROOT_CODE; 30 | int mcu_crc_close(const devfs_handle_t *handle) MCU_ROOT_CODE; 31 | 32 | int mcu_crc_getinfo(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 33 | int mcu_crc_setattr(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 34 | int mcu_crc_setaction(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 35 | 36 | int mcu_crc_get(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif /* MCU_CRC_H_ */ 43 | -------------------------------------------------------------------------------- /include/mcu/eth.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup ENET Ethernet 4 | * @{ 5 | * 6 | * \ingroup IFACE_DEV 7 | * 8 | * \details 9 | * 10 | */ 11 | 12 | /*! \file 13 | * \brief Ethernet Header File 14 | * 15 | */ 16 | 17 | #ifndef MCU_ETH_H_ 18 | #define MCU_ETH_H_ 19 | 20 | #include "sos/dev/eth.h" 21 | 22 | #include "sos/fs/devfs.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | typedef struct MCU_PACK { 29 | eth_attr_t attr; // default attributes 30 | u32 port; 31 | } eth_config_t; 32 | 33 | int mcu_eth_open(const devfs_handle_t *handle) MCU_ROOT_CODE; 34 | int mcu_eth_read(const devfs_handle_t *handle, devfs_async_t *rop) MCU_ROOT_CODE; 35 | int mcu_eth_write(const devfs_handle_t *handle, devfs_async_t *wop) MCU_ROOT_CODE; 36 | int mcu_eth_ioctl(const devfs_handle_t *handle, int request, void *ctl) MCU_ROOT_CODE; 37 | 38 | int mcu_eth_close(const devfs_handle_t *handle) MCU_ROOT_CODE; 39 | int mcu_eth_getinfo(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 40 | int mcu_eth_setattr(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 41 | int mcu_eth_setaction(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 42 | int mcu_eth_setregister(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 43 | int mcu_eth_getregister(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | 49 | #endif /* MCU_ETH_H_ */ 50 | 51 | /*! @} */ 52 | -------------------------------------------------------------------------------- /ldscript/common.ld: -------------------------------------------------------------------------------- 1 | 2 | 3 | .text : { 4 | _text = .; 5 | KEEP(*(.startup)) 6 | KEEP(*(.reset_vector)) 7 | KEEP(*(.isr_vector)) 8 | . = 0x2fc; 9 | KEEP(*(.crp_section)) 10 | *(.text) 11 | *(.init) 12 | *(.fini) 13 | *(.eh_frame) 14 | _ctors = .; 15 | KEEP(*(.init_array)) 16 | KEEP(*(.ctors)) 17 | _dtors = .; 18 | KEEP(*(.dtors)) 19 | KEEP(*(.fini_array)) 20 | _dtors_end = .; 21 | *(.jcr) 22 | *(.rodata) 23 | *(.rodata*) 24 | *(.glue_7) 25 | *(.glue_7t) 26 | 27 | *(.text.*) 28 | _priv_code = .; 29 | *(.priv_code) 30 | _priv_exec_code = .; 31 | *(.priv_exec_code) 32 | _epriv_code = .; 33 | } >flash 34 | 35 | 36 | .ARM.extab : 37 | { 38 | *(.ARM.extab* .gnu.linkonce.armextab.*) 39 | } > flash 40 | __exidx_start = .; 41 | .ARM.exidx : { 42 | *(.ARM.exidx* .gnu.linkonce.armexidx.*) 43 | } >flash 44 | 45 | . = ALIGN(4); 46 | __exidx_end = .; 47 | _etext = .; 48 | .data : { 49 | _data = .; 50 | *(.data) 51 | *(.data.*) 52 | } >ram AT>flash 53 | _edata = .; 54 | .bss : { 55 | _bss = .; 56 | *(.bss) 57 | *(.bss.*) 58 | } >ram 59 | . = ALIGN(4); 60 | _ebss = .; 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /include/mcu/qei.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup QEI_DEV QEI 4 | * @{ 5 | * 6 | * \ingroup DEV 7 | */ 8 | 9 | #ifndef _MCU_QEI_H_ 10 | #define _MCU_QEI_H_ 11 | 12 | #include "sos/dev/qei.h" 13 | #include "sos/fs/devfs.h" 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | typedef struct MCU_PACK { 20 | u32 value; 21 | } qei_event_data_t; 22 | 23 | typedef struct MCU_PACK { 24 | qei_attr_t attr; 25 | u32 port; 26 | } qei_config_t; 27 | 28 | int mcu_qei_open(const devfs_handle_t *handle) MCU_ROOT_CODE; 29 | int mcu_qei_read(const devfs_handle_t *handle, devfs_async_t *rop) MCU_ROOT_CODE; 30 | int mcu_qei_write(const devfs_handle_t *handle, devfs_async_t *wop) MCU_ROOT_CODE; 31 | int mcu_qei_ioctl(const devfs_handle_t *handle, int request, void *ctl) MCU_ROOT_CODE; 32 | int mcu_qei_close(const devfs_handle_t *handle) MCU_ROOT_CODE; 33 | 34 | int mcu_qei_getinfo(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 35 | int mcu_qei_setattr(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 36 | int mcu_qei_setaction(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 37 | 38 | int mcu_qei_get(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 39 | int mcu_qei_getvelocity(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 40 | int mcu_qei_getindex(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | #endif /* _MCU_QEI_H_ */ 47 | 48 | /*! @} */ 49 | -------------------------------------------------------------------------------- /src/sos_config_template.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef CONFIG_SOS_CONFIG_H 3 | #define CONFIG_SOS_CONFIG_H 4 | 5 | //This file should be copied to another folder and renamed sos_config.h 6 | //The folder should assigned to SOS_CONFIG_PATH by the super project 7 | 8 | 9 | // PTHREAD CONFIGURATION OPTIONS 10 | #define CONFIG_PTHREAD_MAX_LOCKS 1024 11 | #define CONFIG_PTHREAD_MUTEX_PRIO_CEILING 0 12 | #define CONFIG_PTHREAD_STACK_MIN 128 13 | #define CONFIG_PTHREAD_DEFAULT_STACK_SIZE 1536 14 | 15 | // SCHED CONFIGURATION OPTIONS 16 | #define CONFIG_SCHED_LOWEST_PRIORITY 0 17 | #define CONFIG_SCHED_HIGHEST_PRIORITY 31 18 | #define CONFIG_SCHED_DEFAULT_PRIORITY 0 19 | // duration is in milliseconds 20 | #define CONFIG_SCHED_RR_DURATION 10 21 | 22 | // Task options 23 | // total number of threads (system and application) 24 | // more tasks use require more sysmem 25 | #define CONFIG_TASK_TOTAL 16 26 | #define CONFIG_TASK_PROCESS_TIMER_COUNT 2 27 | #define CONFIG_TASK_DEFAULT_STACKGUARD_SIZE 128 28 | 29 | #define CONFIG_TASK_NUM_SIGNALS 32 30 | 31 | #define CONFIG_MALLOC_CHUNK_SIZE 32 32 | #define CONFIG_MALLOC_SBRK_JUMP_SIZE 128 33 | 34 | // require a valid digital signature when installing applications 35 | #define CONFIG_APPFS_IS_VERIFY_SIGNATURE 1 36 | // require the OS to be digitally signed 37 | #define CONFIG_BOOT_IS_VERIFY_SIGNATURE 1 38 | 39 | // Bootloader provides AES cryptography using a device unique secret key 40 | #define CONFIG_BOOT_IS_AES_CRYPTO 1 41 | 42 | #define CONFIG_USE_STDIO 1 43 | 44 | #endif /* CONFIG_SOS_CONFIG_H */ 45 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | push: 5 | branches: [ development ] 6 | pull_request: 7 | branches: [ development ] 8 | 9 | jobs: 10 | buildLinuxArm32: 11 | runs-on: [self-hosted, linux, ARM] 12 | steps: 13 | - uses: actions/checkout@v2 14 | with: 15 | ref: 'development' 16 | - name: prepare 17 | run: mkdir cmake_link && mkdir cmake_arm 18 | - name: configure-link 19 | run: cmake -DSOS_SDK_PATH=/StratifyLabs-SDK .. 20 | working-directory: cmake_link 21 | - name: make-link 22 | run: make -j3 23 | working-directory: cmake_link 24 | - name: configure 25 | run: cmake -DSOS_SDK_PATH=/StratifyLabs-SDK .. 26 | working-directory: cmake_arm 27 | - name: make 28 | run: make -j3 29 | working-directory: cmake_arm 30 | buildMacOS: 31 | runs-on: [self-hosted, macOS, X64] 32 | steps: 33 | - uses: actions/checkout@v2 34 | with: 35 | ref: 'development' 36 | - name: prepare 37 | run: mkdir cmake_link && mkdir cmake_arm 38 | - name: configure-link 39 | run: cmake -DSOS_SDK_PATH=/Applications/StratifyLabs-SDK .. 40 | working-directory: cmake_link 41 | - name: make-link 42 | run: make -j3 43 | working-directory: cmake_link 44 | - name: configure 45 | run: cmake -DSOS_SDK_PATH=/Applications/StratifyLabs-SDK .. 46 | working-directory: cmake_arm 47 | - name: make 48 | run: make -j3 49 | working-directory: cmake_arm 50 | 51 | -------------------------------------------------------------------------------- /src/sys/unistd/access.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup unistd 4 | * @{ 5 | */ 6 | 7 | /*! \file 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include "sos/fs/sysfs.h" 19 | #include "sos/sos.h" 20 | 21 | /*! \details This function checks to see if the specified access (\a amode) 22 | * is allowed for \a path. 23 | * 24 | * \return Zero on success (ie \a amode is allowed) or -1 with errno (see \ref errno) set 25 | * to: 26 | * - ENAMETOOLONG: \a path exceeds PATH_MAX or a component of \a path exceeds NAME_MAX 27 | * - ENOENT: \a path does not exist 28 | * - EACCES: \a amode is not allowed for \a path or search permission is denied for a 29 | * component of \a path 30 | * 31 | */ 32 | int access(const char *path, int amode) { 33 | const sysfs_t *fs; 34 | struct stat st; 35 | int ret; 36 | 37 | // Do a safe check of the path string length 38 | if (sysfs_ispathinvalid(path) == true) { 39 | return -1; 40 | } 41 | 42 | fs = sysfs_find(path, true); 43 | if (fs == NULL) { 44 | errno = ENOENT; 45 | return -1; 46 | } 47 | 48 | if ((ret = fs->stat(fs->config, sysfs_stripmountpath(fs, path), &st)) < 0) { 49 | SYSFS_PROCESS_RETURN(ret); 50 | return ret; 51 | } 52 | 53 | return sysfs_access(st.st_mode, st.st_uid, st.st_gid, amode); 54 | } 55 | 56 | /*! @} */ 57 | -------------------------------------------------------------------------------- /include/sos/trace.h: -------------------------------------------------------------------------------- 1 | #ifndef SOS_TRACE_H 2 | #define SOS_TRACE_H 3 | 4 | #include "link/types.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | #define SOS_TRACE_MESSAGE(msg) \ 11 | sos_trace_event(LINK_POSIX_TRACE_MESSAGE, msg, sizeof(msg)) 12 | #define SOS_TRACE_WARNING(msg) \ 13 | sos_trace_event(LINK_POSIX_TRACE_WARNING, msg, sizeof(msg)) 14 | #define SOS_TRACE_CRITICAL(msg) \ 15 | sos_trace_event( \ 16 | LINK_POSIX_TRACE_CRITICAL, msg, sizeof(msg)) 17 | #define SOS_TRACE_FATAL(msg) \ 18 | sos_trace_event(LINK_POSIX_TRACE_FATAL, msg, sizeof(msg)) 19 | 20 | void sos_trace_event( 21 | link_trace_event_id_t event_id, 22 | const void *data_ptr, 23 | size_t data_len); 24 | int sos_trace_stack(u32 count); 25 | int sos_trace_stack_with_pointer( 26 | const u32 *first_link_register, 27 | const u32 *sp, 28 | const u32 *stack_top, 29 | u32 count); 30 | void sos_trace_event_addr_tid( 31 | link_trace_event_id_t event_id, 32 | const void *data_ptr, 33 | size_t data_len, 34 | u32 addr, 35 | int tid); 36 | void sos_trace_root_trace_event( 37 | link_trace_event_id_t event_id, 38 | const void *data_ptr, 39 | size_t data_len); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif // SOS_TRACE_H 46 | -------------------------------------------------------------------------------- /src/sys/sos_interrupt_handlers.c: -------------------------------------------------------------------------------- 1 | 2 | #include "cortexm/cortexm.h" 3 | #include "sos/events.h" 4 | #include "sos/sos.h" 5 | #include "sos/symbols.h" 6 | 7 | void cortexm_reset_handler() { 8 | cortexm_initialize_heap(); 9 | sos_handle_event(SOS_EVENT_ROOT_RESET, 0); 10 | sos_main(); // This function should never return 11 | sos_handle_event(SOS_EVENT_ROOT_FATAL, "main"); 12 | while (1) { 13 | ; 14 | } 15 | } 16 | 17 | void cortexm_svcall_handler() { 18 | register u32 *frame; 19 | register cortexm_svcall_t call; 20 | register void *args; 21 | asm volatile("MRS %0, psp\n\t" : "=r"(frame)); 22 | call = (cortexm_svcall_t)frame[0]; 23 | args = (void *)(frame[1]); 24 | // verify call is located secure kernel region ROOT_EXEC ONLY 25 | if ( 26 | (((u32)call >= (u32)&_text) 27 | && ((u32)call < (u32)&_etext)) // cppcheck-suppress[clarifyCondition] 28 | || (((u32)call >= (u32)&_tcim) && ((u32)call < (u32)&_etcim)) // cppcheck-suppress[clarifyCondition] 29 | ) { 30 | // args must point to kernel RAM or kernel flash -- can't be SYS MEM or registers or 31 | // anything like that 32 | call(args); 33 | } else { 34 | // this needs to be a fault 35 | } 36 | #if 0 37 | // add this when security update is ready 38 | if (cortexm_svcall_validation != call) { 39 | // this is a security violation 40 | } 41 | cortexm_svcall_validation = 0; 42 | #endif 43 | } 44 | 45 | void cortexm_nmi_handler() { sos_handle_event(SOS_EVENT_ROOT_FATAL, "nmi"); } 46 | 47 | void cortexm_debug_monitor_handler() {} 48 | -------------------------------------------------------------------------------- /include/mcu/ohci.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #ifndef OHCI_H_ 4 | #define OHCI_H_ 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | typedef struct { 11 | const uint32_t HcRevision; 12 | volatile uint32_t HcControl; 13 | volatile uint32_t HcCommandStatus; 14 | volatile uint32_t HcInterruptStatus; 15 | volatile uint32_t HcInterruptEnable; 16 | volatile uint32_t HcInterruptDisable; 17 | volatile uint32_t HcHCCA; 18 | const uint32_t HcPeriodCurrentED; 19 | volatile uint32_t HcControlHeadED; 20 | volatile uint32_t HcControlCurrentED; 21 | volatile uint32_t HcBulkHeadED; 22 | volatile uint32_t HcBulkCurrentED; 23 | const uint32_t HcDoneHead; 24 | volatile uint32_t HcFmInterval; 25 | const uint32_t HcFmRemaining; 26 | const uint32_t HcFmNumber; 27 | volatile uint32_t HcPeriodicStart; 28 | volatile uint32_t HcLSTreshold; 29 | volatile uint32_t HcRhDescriptorA; 30 | volatile uint32_t HcRhDescriptorB; 31 | volatile uint32_t HcRhStatus; 32 | volatile uint32_t HcRhPortStatus1; 33 | volatile uint32_t HcRhPortStatus2; 34 | } ohci_t; 35 | 36 | typedef struct { 37 | volatile uint32_t ctrl; 38 | volatile uint32_t curr_buf_ptr; 39 | volatile uint32_t next_td; 40 | volatile uint32_t buf_end; 41 | } ohci_td_t; 42 | 43 | typedef struct { 44 | volatile uint32_t ctrl; 45 | volatile uint32_t tail_td; 46 | volatile uint32_t head_td; 47 | volatile uint32_t next_ed; 48 | } ohci_ed_t; 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif /* OHCI_H_ */ 55 | -------------------------------------------------------------------------------- /src/cortexm/task_process.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #include 4 | 5 | #include "task_local.h" 6 | 7 | int task_create_process( 8 | void (*p)(char *), 9 | void (*cleanup)(void *), 10 | const char *path_arg, 11 | task_memories_t *mem, 12 | void *reent_ptr, 13 | int parent_id) { 14 | 15 | int tid; 16 | int err; 17 | void *stackaddr; 18 | new_task_t task; 19 | task_memories_t task_memories; 20 | static int task_process_counter = 1; 21 | 22 | // Variable initialization 23 | stackaddr = mem->data.address + mem->data.size; 24 | 25 | // Check the stack alignment 26 | if ((unsigned int)stackaddr & 0x03) { 27 | errno = EIO; 28 | return -1; 29 | } 30 | 31 | // Initialize the task 32 | task.stackaddr = stackaddr; 33 | task.start = (uint32_t)p; 34 | task.stop = (uint32_t)cleanup; 35 | task.r0 = (uint32_t)path_arg; 36 | task.r1 = (uint32_t)0; 37 | 38 | task.pid = task_process_counter++; // Assign a new pid 39 | task.reent = (struct _reent *)reent_ptr; 40 | task.global_reent = task.reent; 41 | 42 | task.flags = TASK_FLAGS_USED; 43 | task.priority = 0; 44 | task.parent = parent_id; 45 | 46 | task_memories = *mem; 47 | if ((err = task_mpu_calc_protection(&task_memories)) < 0) { 48 | return err; 49 | } 50 | task.mem = &task_memories; 51 | 52 | // Do a priv call while accessing the task table so there are no interruptions 53 | cortexm_svcall((cortexm_svcall_t)task_svcall_new_task, &task); 54 | tid = task.tid; 55 | return tid; 56 | } 57 | -------------------------------------------------------------------------------- /src/boot/boot_interrupt_handlers.c: -------------------------------------------------------------------------------- 1 | #include "sos/symbols.h" 2 | #include 3 | 4 | #include "cortexm/cortexm.h" 5 | #include "cortexm/fault.h" 6 | 7 | extern void boot_main(); 8 | 9 | void cortexm_reset_handler() { 10 | u32 *src, *dest; 11 | src = &_etext; // point src to copy of data that is stored in flash 12 | for (dest = &_data; dest < &_edata;) { 13 | *dest++ = *src++; 14 | } // Copy from flash to RAM (data) 15 | for (src = &_bss; src < &_ebss;) 16 | *src++ = 0; // Zero out BSS section 17 | for (src = &_sys; src < &_esys;) 18 | *src++ = 0; // Zero out sysmem 19 | 20 | boot_main(); // This function should never return 21 | } 22 | 23 | // prevent linkage to real handlers 24 | void cortexm_hardfault_handler() { 25 | while (1) { 26 | } 27 | } 28 | void cortexm_memfault_handler() { 29 | while (1) { 30 | } 31 | } 32 | void cortexm_busfault_handler() { 33 | while (1) { 34 | } 35 | } 36 | void cortexm_usagefault_handler() { 37 | while (1) { 38 | } 39 | } 40 | void cortexm_systick_handler() { 41 | while (1) { 42 | } 43 | } 44 | void cortexm_svcall_handler() { 45 | while (1) { 46 | } 47 | } 48 | void cortexm_pendsv_handler() { 49 | while (1) { 50 | } 51 | } 52 | void cortexm_nmi_handler() { 53 | while (1) { 54 | } 55 | } 56 | void cortexm_debug_monitor_handler() { 57 | while (1) { 58 | } 59 | } 60 | 61 | // used by startup for newlib 62 | int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr) { 63 | MCU_UNUSED_ARGUMENT(mutex); 64 | MCU_UNUSED_ARGUMENT(attr); 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /include/mcu/mmc.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup SD_DEV MMC 4 | * @{ 5 | * 6 | * \ingroup DEV 7 | */ 8 | 9 | #ifndef _MCU_MMC_H_ 10 | #define _MCU_MMC_H_ 11 | 12 | #include "sos/dev/mmc.h" 13 | #include "sos/fs/devfs.h" 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | typedef struct MCU_PACK { 20 | u32 value; 21 | } mmc_event_data_t; 22 | 23 | typedef struct { 24 | mmc_attr_t attr; // default attributes 25 | u32 port; 26 | } mmc_config_t; 27 | 28 | #define MCU_MMC_IOCTL_REQUEST_DECLARATION(driver_name) \ 29 | DEVFS_DRIVER_DECLARTION_IOCTL_REQUEST(driver_name, getinfo); \ 30 | DEVFS_DRIVER_DECLARTION_IOCTL_REQUEST(driver_name, setattr); \ 31 | DEVFS_DRIVER_DECLARTION_IOCTL_REQUEST(driver_name, setaction); \ 32 | DEVFS_DRIVER_DECLARTION_IOCTL_REQUEST(driver_name, getcid); \ 33 | DEVFS_DRIVER_DECLARTION_IOCTL_REQUEST(driver_name, getcsd); \ 34 | DEVFS_DRIVER_DECLARTION_IOCTL_REQUEST(driver_name, getstatus) 35 | 36 | #define MCU_MMC_DRIVER_DECLARATION(variant) \ 37 | DEVFS_DRIVER_DECLARTION(variant); \ 38 | MCU_MMC_IOCTL_REQUEST_DECLARATION(variant) 39 | 40 | MCU_MMC_DRIVER_DECLARATION(mcu_mmc); 41 | MCU_MMC_DRIVER_DECLARATION(mcu_mmc_dma); 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif /* _MCU_MMC_H_ */ 48 | 49 | /*! @} */ 50 | -------------------------------------------------------------------------------- /include/mcu/pio.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup PIO_DEV PIO 4 | * 5 | * \ingroup DEV 6 | * 7 | */ 8 | 9 | #ifndef _MCU_PIO_H_ 10 | #define _MCU_PIO_H_ 11 | 12 | #include "core.h" 13 | #include "sos/dev/pio.h" 14 | #include "sos/fs/devfs.h" 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | typedef struct MCU_PACK { 21 | u32 status; 22 | u32 rising; 23 | u32 falling; 24 | } pio_event_data_t; 25 | 26 | typedef struct { 27 | u32 port; 28 | } pio_config_t; 29 | 30 | int mcu_pio_open(const devfs_handle_t *handle) MCU_ROOT_CODE; 31 | int mcu_pio_read(const devfs_handle_t *handle, devfs_async_t *rop) MCU_ROOT_CODE; 32 | int mcu_pio_write(const devfs_handle_t *handle, devfs_async_t *wop) MCU_ROOT_CODE; 33 | int mcu_pio_ioctl(const devfs_handle_t *handle, int request, void *ctl) MCU_ROOT_CODE; 34 | int mcu_pio_close(const devfs_handle_t *handle) MCU_ROOT_CODE; 35 | 36 | int mcu_pio_getinfo(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 37 | int mcu_pio_setattr(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 38 | int mcu_pio_setaction(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 39 | 40 | int mcu_pio_setmask(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 41 | int mcu_pio_clrmask(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 42 | int mcu_pio_get(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 43 | int mcu_pio_set(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | 49 | #endif /* _MCU_PIO_H_ */ 50 | 51 | /*! @} */ 52 | -------------------------------------------------------------------------------- /include/mcu/emc.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup EINT_DEV EINT 4 | * @{ 5 | * 6 | * \ingroup DEV 7 | */ 8 | 9 | #ifndef _MCU_EMC_H_ 10 | #define _MCU_EMC_H_ 11 | 12 | #include "sos/dev/emc.h" 13 | #include "sos/fs/devfs.h" 14 | 15 | typedef struct MCU_PACK { 16 | u32 value; 17 | } emc_event_data_t; 18 | 19 | typedef struct MCU_PACK { 20 | emc_attr_t attr; // default attributes 21 | u32 base_address; 22 | u32 size; 23 | u32 freq; 24 | u16 data_bus_width; 25 | u16 resd; 26 | } emc_config_t; 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | #define MCU_EMC_IOCTL_REQUEST_DECLARATION(driver_name) \ 33 | DEVFS_DRIVER_DECLARTION_IOCTL_REQUEST(driver_name, getinfo); \ 34 | DEVFS_DRIVER_DECLARTION_IOCTL_REQUEST(driver_name, setattr); \ 35 | DEVFS_DRIVER_DECLARTION_IOCTL_REQUEST(driver_name, setaction) 36 | 37 | #define MCU_EMC_DRIVER_DECLARATION(variant) \ 38 | DEVFS_DRIVER_DECLARTION(variant); \ 39 | MCU_EMC_IOCTL_REQUEST_DECLARATION(variant) 40 | 41 | MCU_EMC_DRIVER_DECLARATION(mcu_emc_sram); 42 | MCU_EMC_DRIVER_DECLARATION(mcu_emc_sdram); 43 | MCU_EMC_DRIVER_DECLARATION(mcu_emc_nand); 44 | MCU_EMC_DRIVER_DECLARATION(mcu_emc_nor); 45 | MCU_EMC_DRIVER_DECLARATION(mcu_emc_psram); 46 | MCU_EMC_DRIVER_DECLARATION(mcu_emc_fmc_ahb); 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif /* _EMC_H_ */ 53 | 54 | /*! @} */ 55 | -------------------------------------------------------------------------------- /include/posix/arpa/inet.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | #ifndef POSIX_ARPA_INET_H_ 4 | #define POSIX_ARPA_INET_H_ 5 | 6 | /* Include the LWIP sockets header 7 | * 8 | * If LWIP isn't installed in the SDK, any apps that use netdb will get an error. 9 | * 10 | */ 11 | 12 | #if SOS_BOOTSTRAP_SOCKETS 13 | #include 14 | typedef u32 in_addr_t; 15 | typedef u16 in_port_t; 16 | #define INET_ADDRSTRLEN 8 17 | #define INET6_ADDRSTRLEN 8 18 | #else 19 | #include 20 | #endif //SOS_BOOTSTRAP_SOCKETS 21 | 22 | 23 | #if defined __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | #if defined inet_addr 28 | #undef inet_addr 29 | #endif 30 | 31 | #if defined inet_ntoa 32 | #undef inet_ntoa 33 | #endif 34 | 35 | #if defined inet_ntop 36 | #undef inet_ntop 37 | #endif 38 | 39 | #if defined inet_pton 40 | #undef inet_pton 41 | #endif 42 | 43 | #if defined htonl 44 | #undef htonl 45 | #endif 46 | 47 | #if defined htons 48 | #undef htons 49 | #endif 50 | 51 | #if defined ntohl 52 | #undef ntohl 53 | #endif 54 | 55 | #if defined ntohs 56 | #undef ntohs 57 | #endif 58 | 59 | in_addr_t inet_addr(const char * cp); 60 | char * inet_ntoa(struct in_addr in); 61 | const char * inet_ntop(int af, const void * src, char * dst, socklen_t size); 62 | int inet_pton(int af, const char * src, void * dst); 63 | 64 | uint32_t htonl(uint32_t hostlong); 65 | uint16_t htons(uint16_t hostshort); 66 | uint32_t ntohl(uint32_t netlong); 67 | uint16_t ntohs(uint16_t netshort); 68 | 69 | #if defined __cplusplus 70 | } 71 | #endif 72 | 73 | 74 | #endif /* POSIX_ARPA_INET_H_ */ 75 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # StratifyOS 2 | 3 | ## What's New 4 | 5 | Welcome to Stratify OS 4. Version 3 is available as [master](https://github.com/StratifyLabs/StratifyOS/tree/master). The main change from Stratify OS 3 to 4 is how to port and integrate with the board support package. See the [porting guide](guides/Porting.md) for details. 6 | 7 | ## Getting Started 8 | 9 | The fastest way to get started is to use one of the following board support packages: 10 | 11 | - [Nucleo144](https://github.com/StratifyLabs/StratifyOS-Nucleo144) 12 | - [STM32H735G-DK](https://github.com/StratifyLabs/STM32H735G-DK) 13 | 14 | The above projects have instructions to quickly and easily clone and build the required code. 15 | 16 | ## About 17 | 18 | Stratify OS is a fully featured microcontroller operating system designed specifically for the ARM Cortex M architecture. It features: 19 | 20 | - [Decoupled System and Application Binaries](guides/Overview.md) 21 | - [Deep integration with Cortex M hardware](guides/ARM-Cortex-M.md) such as the MPU, SysTick/PendSV, SVCall, Dual Stacks, NVIC, BPU, and Cache 22 | - [POSIX Style Filesystems](guides/Filesystems.md) 23 | - [Complete Hardware Abstraction](guides/Device-Drivers.md) 24 | - [Threads](guides/Threads.md) 25 | 26 | ## License 27 | 28 | The Stratify OS source code is available under a commercial source available license. The license requires a hardware ID be issued by Stratify Labs, Inc and used to identify unique hardware configurations. Hardware IDs are available free of charge and allow the licensee to use Stratify OS without any charges or fees on the hardware design associated with the ID. 29 | 30 | 31 | -------------------------------------------------------------------------------- /include/mcu/sdio.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup SD_DEV SDIO 4 | * @{ 5 | * 6 | * \ingroup DEV 7 | */ 8 | 9 | #ifndef _MCU_SDIO_H_ 10 | #define _MCU_SDIO_H_ 11 | 12 | #include "sos/dev/sdio.h" 13 | #include "sos/fs/devfs.h" 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | typedef struct MCU_PACK { 20 | u32 value; 21 | } sdio_event_data_t; 22 | 23 | typedef struct { 24 | sdio_attr_t attr; // default attributes 25 | u32 port; 26 | } sdio_config_t; 27 | 28 | #define MCU_SDIO_IOCTL_REQUEST_DECLARATION(driver_name) \ 29 | DEVFS_DRIVER_DECLARTION_IOCTL_REQUEST(driver_name, getinfo); \ 30 | DEVFS_DRIVER_DECLARTION_IOCTL_REQUEST(driver_name, setattr); \ 31 | DEVFS_DRIVER_DECLARTION_IOCTL_REQUEST(driver_name, setaction); \ 32 | DEVFS_DRIVER_DECLARTION_IOCTL_REQUEST(driver_name, getcid); \ 33 | DEVFS_DRIVER_DECLARTION_IOCTL_REQUEST(driver_name, getcsd); \ 34 | DEVFS_DRIVER_DECLARTION_IOCTL_REQUEST(driver_name, getstatus) 35 | 36 | #define MCU_SDIO_DRIVER_DECLARATION(variant) \ 37 | DEVFS_DRIVER_DECLARTION(variant); \ 38 | MCU_SDIO_IOCTL_REQUEST_DECLARATION(variant) 39 | 40 | MCU_SDIO_DRIVER_DECLARATION(mcu_sdio); 41 | MCU_SDIO_DRIVER_DECLARATION(mcu_sdio_dma); 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif /* _MCU_SDIO_H_ */ 48 | 49 | /*! @} */ 50 | -------------------------------------------------------------------------------- /src/sys/grp/grp.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | 5 | /*! \addtogroup GRP 6 | * @{ 7 | * 8 | * \details This interface is not implemented in this version. 9 | * 10 | * 11 | */ 12 | 13 | /*! \file */ 14 | 15 | 16 | #include 17 | 18 | static struct group default_group = { 19 | .gr_name = "users", 20 | .gr_passwd = NULL, 21 | .gr_gid = 0, 22 | .gr_mem = NULL 23 | }; 24 | 25 | /*! \details Not implemented (stub only). 26 | * 27 | * \return default group 28 | */ 29 | struct group *getgrgid (gid_t gid){ 30 | return &default_group; 31 | } 32 | 33 | /*! \details Not implemented (stub only). 34 | * 35 | * \return default group 36 | */ 37 | struct group *getgrnam (const char * name){ 38 | return &default_group; 39 | } 40 | 41 | /*! \details Not implemented (stub only). 42 | * 43 | * \return 0 44 | */ 45 | int getgrnam_r(const char * name, struct group * grp, 46 | char * buffer, size_t bufsize, struct group **result){ 47 | return 0; 48 | } 49 | 50 | /*! \details Not implemented (stub only). 51 | * 52 | * \return 0 53 | */ 54 | int getgrgid_r (gid_t gid, struct group * grp, 55 | char * buffer, size_t bufsize, struct group ** result){ 56 | return 0; 57 | } 58 | 59 | /*! \details Not implemented (stub only). 60 | * 61 | * \return NULL 62 | */ 63 | struct group *getgrent (){ 64 | return NULL; 65 | } 66 | 67 | /*! \details Not implemented (stub only). 68 | * 69 | */ 70 | void setgrent (){ 71 | 72 | } 73 | 74 | /*! \details Not implemented (stub only). 75 | * 76 | */ 77 | void endgrent (){ 78 | 79 | } 80 | 81 | /*! @} */ 82 | 83 | -------------------------------------------------------------------------------- /src/sys/malloc/mallinfo.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | #include "sys/malloc/malloc_local.h" 5 | 6 | struct mallinfo mallinfo() { 7 | return _mallinfo_r(_REENT); 8 | } 9 | 10 | struct mallinfo _mallinfo_r(struct _reent *reent_ptr) { 11 | int total_chunks; 12 | int total_used_memory; 13 | int total_free_chunks; 14 | struct mallinfo mi; 15 | malloc_chunk_t *chunk; 16 | proc_mem_t *procmem_base; 17 | 18 | mi.arena = 0; 19 | mi.ordblks = 0; 20 | mi.fordblks = 0; 21 | mi.uordblks = 0; 22 | if (reent_ptr->procmem_base == NULL) { 23 | return mi; 24 | } 25 | 26 | procmem_base = (proc_mem_t *)reent_ptr->procmem_base; 27 | chunk = (malloc_chunk_t *)&(procmem_base->base); 28 | 29 | total_chunks = 0; 30 | total_used_memory = 0; 31 | total_free_chunks = 0; 32 | 33 | while (chunk->header.num_chunks != 0) { 34 | int chunk_free = malloc_chunk_is_free(chunk); 35 | if (chunk_free == -1) { 36 | return mi; 37 | } 38 | total_chunks += chunk->header.num_chunks; 39 | if (chunk_free == 1) { 40 | total_free_chunks += chunk->header.num_chunks; 41 | } else { 42 | total_used_memory += chunk->header.actual_size; 43 | } 44 | chunk += chunk->header.num_chunks; 45 | } 46 | 47 | // this calculation may be wrong -- needs to account for the number o header entries 48 | // Issue #143 49 | mi.arena = (total_chunks)*CONFIG_MALLOC_CHUNK_SIZE; 50 | mi.ordblks = total_free_chunks; 51 | mi.fordblks = total_free_chunks * CONFIG_MALLOC_CHUNK_SIZE; 52 | mi.uordblks = total_used_memory; 53 | 54 | return mi; 55 | } 56 | -------------------------------------------------------------------------------- /src/sys/pthread/pthread_mutex_init.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup pthread 4 | * @{ 5 | * 6 | * 7 | */ 8 | 9 | /*! \file */ 10 | 11 | #include "config.h" 12 | #include 13 | #include 14 | 15 | #include "cortexm/task.h" 16 | 17 | int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr) MCU_WEAK; 18 | 19 | /*! \details This function initializes \a mutex with \a attr. 20 | * \return Zero on success or -1 with \a errno (see \ref errno) set to: 21 | * - EINVAL: mutex is NULL 22 | */ 23 | int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr) { 24 | if (mutex == NULL) { 25 | SOS_DEBUG_LINE_TRACE(); 26 | errno = EINVAL; 27 | return -1; 28 | } 29 | 30 | mutex->flags = PTHREAD_MUTEX_FLAGS_INITIALIZED; 31 | 32 | if (attr == NULL) { 33 | mutex->prio_ceiling = CONFIG_PTHREAD_MUTEX_PRIO_CEILING; 34 | if (task_get_current() == 0) { 35 | mutex->pid = 0; 36 | } else { 37 | mutex->pid = task_get_pid(task_get_current()); 38 | } 39 | mutex->lock = 0; 40 | mutex->pthread = -1; 41 | return 0; 42 | } 43 | 44 | if (attr->process_shared != 0) { 45 | // Enter priv mode to modify a shared object 46 | mutex->flags |= (PTHREAD_MUTEX_FLAGS_PSHARED); 47 | } 48 | 49 | if (attr->recursive) { 50 | mutex->flags |= (PTHREAD_MUTEX_FLAGS_RECURSIVE); 51 | } 52 | mutex->prio_ceiling = attr->prio_ceiling; 53 | mutex->pid = task_get_pid(task_get_current()); 54 | mutex->lock = 0; 55 | mutex->pthread = -1; 56 | return 0; 57 | } 58 | 59 | /*! @} */ 60 | -------------------------------------------------------------------------------- /guides/Porting.md: -------------------------------------------------------------------------------- 1 | # Porting Guide 2 | 3 | Stratify OS is an operating system specifically designed for the ARM Cortex-M architecture. It supports the following architectures: 4 | 5 | - ARM Cortex M3 (armv7m) 6 | - ARM Cortex M4 (armv7em) 7 | - ARM Cortex M4F (armv7em_f4sh) 8 | - ARM Cortex M7 (armv7em_f5sh and armv7em_f5dh) 9 | 10 | There is planned support for the ARM Cortex M23 and M33 architectures though no chips are currently supported. 11 | 12 | # Configuration 13 | 14 | Stratify OS is ported using link level configuration. Your board support package must provide the following variable symbols: 15 | 16 | ```c++ 17 | extern volatile sched_task_t sos_sched_table[]; 18 | extern volatile task_t sos_task_table[]; 19 | extern const sos_config_t sos_config; 20 | ``` 21 | 22 | The `sos_config_t` structure looks like this: 23 | 24 | ```c++ 25 | typedef struct MCU_PACK { 26 | sos_sys_config_t sys; 27 | sos_fs_config_t fs; 28 | sos_clock_config_t clock; 29 | sos_task_config_t task; 30 | sos_debug_config_t debug; 31 | sos_cache_config_t cache; 32 | sos_sleep_config_t sleep; 33 | sos_usb_config_t usb; 34 | const sos_socket_api_t *socket_api; 35 | void (*event_handler)(int, void *); 36 | } sos_config_t; 37 | ``` 38 | 39 | The details of `sos_config_t` are listed in the [sos/config.h](../include/sos/config.h) header file. The code contains relevant comments for implementing the functionality. 40 | 41 | There is a sample project for a collection of [Nucleo144 development boards](https://github.com/StratifyLabs/StratifyOS-Nucleo144) that is also a great resource for understanding how to port to your own board. 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /include/sos/dev/device_fifo.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup DEVICE_FIFO Device FIFO 4 | * @{ 5 | * 6 | * 7 | * \ingroup IFACE_DEV 8 | * 9 | * \details 10 | * 11 | * 12 | */ 13 | 14 | /*! \file 15 | */ 16 | 17 | #ifndef SOS_DEV_DEVICE_FIFO_H_ 18 | #define SOS_DEV_DEVICE_FIFO_H_ 19 | 20 | #include 21 | #include "ffifo.h" 22 | 23 | 24 | enum { 25 | DEVICE_FIFO_FLAG_START /*! Start streaming */= (1<<0), 26 | DEVICE_FIFO_FLAG_STOP /*! Stop streaming */ = (1<<1), 27 | DEVICE_FIFO_FLAG_FLUSH /*! Flush all stream data */ = (1<<2) 28 | }; 29 | 30 | typedef struct MCU_PACK { 31 | u32 o_flags /*! Use with DEVICE_FIFO_FLAG_START or DEVICE_FIFO_FLAG_STOP */; 32 | fifo_attr_t tx; 33 | fifo_attr_t rx; 34 | } device_fifo_attr_t; 35 | 36 | typedef struct MCU_PACK { 37 | fifo_info_t fifo; 38 | u32 count; 39 | s32 error; 40 | } device_fifo_channel_info_t; 41 | 42 | typedef struct MCU_PACK { 43 | device_fifo_channel_info_t rx; 44 | device_fifo_channel_info_t tx; 45 | } device_fifo_info_t; 46 | 47 | 48 | #define DEVICE_FIFO_VERSION (0x030000) 49 | #define DEVICE_FIFO_IOC_IDENT_CHAR 'd' 50 | 51 | #define I_DEVICE_FIFO_GETVERSION _IOCTL(DEVICE_FIFO_IOC_IDENT_CHAR, I_MCU_GETVERSION) 52 | #define I_DEVICE_FIFO_GETINFO _IOCTLR(DEVICE_FIFO_IOC_IDENT_CHAR, I_MCU_GETINFO, device_fifo_info_t) 53 | #define I_DEVICE_FIFO_SETATTR _IOCTLW(DEVICE_FIFO_IOC_IDENT_CHAR, I_MCU_SETATTR, device_fifo_attr_t) 54 | #define I_DEVICE_FIFO_SETACTION _IOCTLW(DEVICE_FIFO_IOC_IDENT_CHAR, I_MCU_SETACTION, mcu_action_t) 55 | 56 | 57 | #endif /* SOS_DEV_DEVICE_FIFO_H_ */ 58 | 59 | 60 | /*! @} */ 61 | -------------------------------------------------------------------------------- /include/mcu/flash.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup FLASH_DEV Flash 4 | * @{ 5 | * 6 | * \ingroup DEV 7 | */ 8 | 9 | #ifndef _MCU_FLASH_H_ 10 | #define _MCU_FLASH_H_ 11 | 12 | #include "sos/dev/flash.h" 13 | #include "sos/fs/devfs.h" 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | int mcu_flash_open(const devfs_handle_t *handle) MCU_ROOT_CODE; 20 | int mcu_flash_read(const devfs_handle_t * handle, devfs_async_t * rop) MCU_ROOT_CODE; 21 | int mcu_flash_write(const devfs_handle_t * handle, devfs_async_t * wop) MCU_ROOT_CODE; 22 | int mcu_flash_ioctl(const devfs_handle_t * handle, int request, void * ctl) MCU_ROOT_CODE; 23 | int mcu_flash_close(const devfs_handle_t * handle) MCU_ROOT_CODE; 24 | 25 | int mcu_flash_getinfo(const devfs_handle_t * handle, void * ctl) MCU_ROOT_CODE; 26 | int mcu_flash_setattr(const devfs_handle_t * handle, void * ctl) MCU_ROOT_CODE; 27 | int mcu_flash_setaction(const devfs_handle_t * handle, void * ctl) MCU_ROOT_CODE; 28 | 29 | int mcu_flash_eraseaddr(const devfs_handle_t * handle, void * ctl) MCU_ROOT_CODE; 30 | int mcu_flash_erasepage(const devfs_handle_t * handle, void * ctl) MCU_ROOT_CODE; 31 | int mcu_flash_getpage(const devfs_handle_t * handle, void * ctl) MCU_ROOT_CODE; 32 | int mcu_flash_getsize(const devfs_handle_t * handle, void * ctl) MCU_ROOT_CODE; 33 | int mcu_flash_getpageinfo(const devfs_handle_t * handle, void * ctl) MCU_ROOT_CODE; 34 | int mcu_flash_writepage(const devfs_handle_t * handle, void * ctl) MCU_ROOT_CODE; 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | 40 | 41 | #endif // _MCU_FLASH_H_ 42 | 43 | /*! @} */ 44 | 45 | 46 | -------------------------------------------------------------------------------- /include/mcu/usb.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup USB_DEV USB 4 | * @{ 5 | * \ingroup DEV 6 | * 7 | */ 8 | 9 | #ifndef _MCU_USB_H_ 10 | #define _MCU_USB_H_ 11 | 12 | #include "sos/dev/usb.h" 13 | 14 | #include "sos/fs/devfs.h" 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | typedef struct { 21 | u8 epnum; 22 | } usb_event_t; 23 | 24 | typedef struct MCU_PACK { 25 | usb_attr_t attr; // default attributes 26 | u32 port; 27 | } usb_config_t; 28 | 29 | int mcu_usb_open(const devfs_handle_t *handle) MCU_ROOT_CODE; 30 | int mcu_usb_read(const devfs_handle_t *handle, devfs_async_t *rop) MCU_ROOT_CODE; 31 | int mcu_usb_write(const devfs_handle_t *handle, devfs_async_t *wop) MCU_ROOT_CODE; 32 | int mcu_usb_ioctl(const devfs_handle_t *handle, int request, void *ctl) MCU_ROOT_CODE; 33 | int mcu_usb_close(const devfs_handle_t *handle) MCU_ROOT_CODE; 34 | 35 | int mcu_usb_getinfo(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 36 | int mcu_usb_setattr(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 37 | int mcu_usb_setaction(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 38 | int mcu_usb_isconnected(const devfs_handle_t *handle, void *ctl) MCU_ROOT_CODE; 39 | 40 | // Endpoint functions 41 | int mcu_usb_root_read_endpoint(const devfs_handle_t *handle, u32 endpoint_num, void *dest) 42 | MCU_ROOT_CODE; 43 | int mcu_usb_root_write_endpoint( 44 | const devfs_handle_t *handle, 45 | u32 endpoint_num, 46 | const void *src, 47 | u32 size) MCU_ROOT_CODE; 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif /* _MCU_USB_H_ */ 54 | 55 | /*! @} */ 56 | -------------------------------------------------------------------------------- /src/sys/unistd/ioctl.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup unistd 4 | * @{ 5 | */ 6 | 7 | /*! \file */ 8 | 9 | #include 10 | #include 11 | 12 | #include "config.h" 13 | #include "device/sys.h" 14 | #include "sos/config.h" 15 | #include "sos/ioctl.h" 16 | #include "sys/socket.h" 17 | #include "unistd_local.h" 18 | 19 | /*! \details This function performs a control request on the device 20 | * associated with \a fildes. \a request is specific to the device. 21 | * The value of \a request determines what value should be passed 22 | * as the \a ctl argument. 23 | * 24 | * \param fildes The file descriptor returned by \ref open() 25 | * \param request The request to the device. 26 | * 27 | * \return The number of bytes actually read of -1 with errno (see \ref errno) set to: 28 | * - EBADF: \a fildes is bad 29 | * - EIO: IO error 30 | * - EAGAIN: O_NONBLOCK is set for \a fildes and the device is busy 31 | * 32 | */ 33 | int ioctl(int fildes, int request, ...) { 34 | void *ctl; 35 | va_list ap; 36 | va_start(ap, request); 37 | ctl = va_arg(ap, void *); 38 | va_end(ap); 39 | 40 | if (FILDES_IS_SOCKET(fildes)) { 41 | if (sos_config.socket_api != 0) { 42 | return SOS_SOCKET_API()->ioctl(fildes & ~FILDES_SOCKET_FLAG, request, ctl); 43 | } 44 | errno = EBADF; 45 | return -1; 46 | } 47 | 48 | fildes = u_fildes_is_bad(fildes); 49 | if (fildes < 0) { 50 | // check to see if fildes is a socket 51 | errno = EBADF; 52 | return -1; 53 | } 54 | 55 | return sysfs_file_ioctl(get_open_file(fildes), request, ctl); 56 | } 57 | 58 | /*! @} */ 59 | -------------------------------------------------------------------------------- /src/sys/scheduler/scheduler.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | 4 | /*! \addtogroup SCHED Scheduler 5 | * @{ 6 | * 7 | * \ingroup MULTITASK 8 | * 9 | * \details This software module is the CAOS scheduler. It manages processes in multi-threaded 10 | * applications. The basic approach is to execute the highest priority tasks in a round robin 11 | * fashion. A task with a lower priority will only be executed if all higher priority tasks 12 | * are in the idle state. Hardware interrupts have priority over all tasks (as well as any 13 | * callbacks which have been attached to those interrupts). 14 | * 15 | * The following is a checklist for things that must be done before calling the scheduler() function: 16 | * - Enable the RTC -- if RTC is not enabled sleep() won't work properly 17 | * - Call sched_hwcfg_init(): enables core processes and microsecond timer 18 | * - Enable interrupts 19 | * - Call scheduler_init() 20 | * - Call scheduler() 21 | * 22 | * 23 | */ 24 | 25 | 26 | /*! \file */ 27 | #ifndef SCHEDULER_H_ 28 | #define SCHEDULER_H_ 29 | 30 | //#include "config.h" 31 | 32 | #include 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | void scheduler_start(void *(*init)(void *)); 39 | void scheduler_init(); 40 | 41 | //Schedule Debugging 42 | void scheduler_debug_print_tasks(); 43 | void scheduler_debug_print_active(); 44 | void scheduler_debug_print_executing(); 45 | void scheduler_debug_print_timers(); 46 | 47 | void scheduler_set_fault(int pid, int tid, fault_t * fault); 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif /* SCHEDULER_H_ */ 54 | 55 | /*! @} */ 56 | -------------------------------------------------------------------------------- /src/sys/malloc/calloc.c: -------------------------------------------------------------------------------- 1 | #ifdef MALLOC_PROVIDED 2 | int _dummy_calloc = 1; 3 | #else 4 | /* 5 | FUNCTION 6 | <>---allocate space for arrays 7 | 8 | INDEX 9 | calloc 10 | 11 | INDEX 12 | _calloc_r 13 | 14 | ANSI_SYNOPSIS 15 | #include 16 | void *calloc(size_t <[n]>, size_t <[s]>); 17 | void *_calloc_r(void *<[reent]>, size_t <[n]>, size_t <[s]>); 18 | 19 | TRAD_SYNOPSIS 20 | #include 21 | char *calloc(<[n]>, <[s]>) 22 | size_t <[n]>, <[s]>; 23 | 24 | char *_calloc_r(<[reent]>, <[n]>, <[s]>) 25 | char *<[reent]>; 26 | size_t <[n]>; 27 | size_t <[s]>; 28 | 29 | 30 | 31 | DESCRIPTION 32 | Use <> to request a block of memory sufficient to hold an 33 | array of <[n]> elements, each of which has size <[s]>. 34 | 35 | The memory allocated by <> comes out of the same memory pool 36 | used by <>, but the memory block is initialized to all zero 37 | bytes. (To avoid the overhead of initializing the space, use 38 | <> instead.) 39 | 40 | The alternate function <<_calloc_r>> is reentrant. 41 | The extra argument <[reent]> is a pointer to a reentrancy structure. 42 | 43 | RETURNS 44 | If successful, a pointer to the newly allocated space. 45 | 46 | If unsuccessful, <>. 47 | 48 | PORTABILITY 49 | <> is ANSI. 50 | 51 | Supporting OS subroutines required: <>, <>, <>, 52 | <>, <>, <>, <>. 53 | */ 54 | 55 | #include 56 | #include 57 | 58 | #ifndef _REENT_ONLY 59 | 60 | _PTR 61 | _DEFUN (calloc, (n, size), 62 | size_t n _AND 63 | size_t size) 64 | { 65 | return _calloc_r (_GLOBAL_REENT, n, size); 66 | } 67 | 68 | #endif 69 | #endif /* MALLOC_PROVIDED */ 70 | -------------------------------------------------------------------------------- /include/sos/dev/tty.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup TTY TTY (terminal devices) 4 | * @{ 5 | * 6 | * 7 | * \ingroup IFACE_DEV 8 | * 9 | * \details This is the interface to accessing terminal devices. This driver is not implemented 10 | * in this version. 11 | * 12 | * 13 | */ 14 | 15 | /*! \file 16 | */ 17 | 18 | #ifndef SOS_DEV_TTY_H_ 19 | #define SOS_DEV_TTY_H_ 20 | 21 | #include 22 | 23 | #include 24 | #include "termios.h" 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | 31 | #define TTY_VERSION (0x000000) 32 | #define TTY_IOC_CHAR 't' 33 | 34 | /*! \brief This request sets the terminal attributes 35 | * \hideinitializer 36 | */ 37 | #define I_TTY_SETATTR _IOCTLW(TTY_IOC_CHAR, 0, struct termios) 38 | 39 | /*! \brief This request gets the terminal attributes 40 | * \hideinitializer 41 | */ 42 | #define I_TTY_ATTR _IOCTLR(TTY_IOC_CHAR, 1, struct termios) 43 | #define I_TTY_GETINFO I_TTY_ATTR 44 | 45 | 46 | 47 | #define TTY_FLAG_ICRNL 0 48 | #define TTY_FLAG_IGNBRK 1 49 | #define TTY_FLAG_IGNCR 2 50 | #define TTY_FLAG_IGNPAR 3 51 | #define TTY_FLAG_ECHO 4 52 | #define TTY_FLAG_ECHOE 5 53 | #define TTY_FLAG_ECHOK 6 54 | #define TTY_FLAG_ECHONL 7 55 | #define TTY_FLAG_ICANON 8 56 | #define TTY_FLAG_IEXTEN 9 57 | #define TTY_FLAG_ISIG 10 58 | #define TTY_FLAG_NOFLSH 11 59 | #define TTY_FLAG_TOSTOP 12 60 | 61 | 62 | typedef struct { 63 | int flags; 64 | } tty_state_t; 65 | 66 | typedef struct { 67 | uint8_t write_ep; 68 | uint8_t read_ep; 69 | } tty_config_t; 70 | 71 | #ifdef __cplusplus 72 | } 73 | #endif 74 | 75 | 76 | #endif /* SOS_DEV_TTY_H_ */ 77 | 78 | /*! @} */ 79 | -------------------------------------------------------------------------------- /src/cortexm/auth.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include "sos/config.h" 5 | #include "device/auth.h" 6 | 7 | #include "sos_config.h" 8 | 9 | static const u8 *get_public_key() { 10 | return (const u8 *)((u32)sos_config.sys.secret_key_address & ~0x01); 11 | } 12 | 13 | int cortexm_auth_handle_event(int event, void *args) { 14 | #if CONFIG_BOOT_IS_VERIFY_SIGNATURE 15 | if (event == BOOTLOADER_EVENT_AUTHENTICATE) { 16 | bootloader_event_authenication_t *auth = args; 17 | auth_token_t input; 18 | auth_token_t result; 19 | memcpy(input.data, auth->auth_data, 32); 20 | const int auth_result = 21 | auth_pure_code_calculate_authentication(&result, &input, auth->is_key_first); 22 | if (auth_result < 0) { 23 | return auth_result; 24 | } 25 | 26 | memcpy(auth->result, result.data, 32); 27 | return 0; 28 | } 29 | 30 | if (event == BOOTLOADER_EVENT_GET_PUBLIC_KEY) { 31 | auth_public_key_t *key = args; 32 | memcpy(key, get_public_key(), sizeof(auth_public_key_t)); 33 | return 0; 34 | } 35 | #endif 36 | 37 | #if CONFIG_BOOT_IS_AES_CRYPTO 38 | if (event == BOOTLOADER_EVENT_ENCRYPT) { 39 | bootloader_event_crypto_t *crypto = args; 40 | const int crypto_result = auth_pure_code_encrypt_decrypt( 41 | crypto->iv, crypto->plain, crypto->cipher, crypto->nbyte, AUTH_PURE_CODE_IS_ENCRYPT); 42 | return crypto_result; 43 | } 44 | 45 | if (event == BOOTLOADER_EVENT_DECRYPT) { 46 | bootloader_event_crypto_t *crypto = args; 47 | const int crypto_result = auth_pure_code_encrypt_decrypt( 48 | crypto->iv, crypto->plain, crypto->cipher, crypto->nbyte, AUTH_PURE_CODE_IS_DECRYPT); 49 | return crypto_result; 50 | } 51 | #endif 52 | 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /src/sys/pthread/pthread_mutexattr_init.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md 2 | 3 | /*! \addtogroup pthread 4 | * @{ 5 | * 6 | * 7 | */ 8 | 9 | /*! \file */ 10 | 11 | #include "config.h" 12 | 13 | #include 14 | #include 15 | 16 | /*! \cond */ 17 | int pthread_mutexattr_check_initialized(const pthread_mutexattr_t *attr); 18 | /*! \endcond */ 19 | 20 | /*! \details This function initializes \a attr with default values. 21 | * 22 | * \return Zero on success or -1 with errno set to: 23 | * - EINVAL: \a attr is NULL 24 | * 25 | */ 26 | int pthread_mutexattr_init(pthread_mutexattr_t *attr) { 27 | #if PTHREAD_SINGLE_MODE == 1 28 | return 0; 29 | #else 30 | attr->is_initialized = 1; 31 | attr->process_shared = 0; 32 | attr->prio_ceiling = 0; //! \todo This should be a compile time define 33 | attr->protocol = 0; 34 | attr->recursive = 0; 35 | return 0; 36 | #endif 37 | } 38 | 39 | /*! \details This function destroys \a attr. 40 | * 41 | * \return Zero on success or -1 with errno set to: 42 | * - EINVAL: \a attr is not an initialized mutex attribute object 43 | * 44 | */ 45 | int pthread_mutexattr_destroy(pthread_mutexattr_t *attr) { 46 | #if PTHREAD_SINGLE_MODE == 1 47 | return 0; 48 | #else 49 | if (pthread_mutexattr_check_initialized(attr)) { 50 | return -1; 51 | } 52 | attr->is_initialized = 0; 53 | return 0; 54 | #endif 55 | } 56 | 57 | /*! \cond */ 58 | int pthread_mutexattr_check_initialized(const pthread_mutexattr_t *attr) { 59 | if (attr == NULL) { 60 | return EINVAL; 61 | } 62 | 63 | if (attr->is_initialized != 1) { 64 | errno = EINVAL; 65 | return -1; 66 | } 67 | return 0; 68 | } 69 | /*! \endcond */ 70 | 71 | /*! @} */ 72 | --------------------------------------------------------------------------------