CMSIS-Compiler Support  
Standard C Library File, I/O and OS Retargeting
 
Loading...
Searching...
No Matches
OS Interface

OS Interface provides Custom component that can be used to implement its functionality using code templates below.

Exposed OS Interface API is toolchain specific therefore make sure to select correct code template:

Arm Compiler

/*-----------------------------------------------------------------------------
* Name: retarget_os.c
* Purpose: OS Interface Retarget Template
* Rev.: 1.0.0
*-----------------------------------------------------------------------------*/
/*
* Copyright (C) 2023 ARM Limited or its affiliates. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* Mutex identifier */
typedef void *mutex;
/* Mutex function prototypes */
int _mutex_initialize(mutex *m);
void _mutex_acquire (mutex *m);
void _mutex_release (mutex *m);
void _mutex_free (mutex *m);
/* Initialize mutex */
int _mutex_initialize(mutex *m) {
/* .. */
return 0;
}
/* Acquire mutex */
void _mutex_acquire(mutex *m) {
/* .. */
}
/* Release mutex */
void _mutex_release(mutex *m) {
/* .. */
}
/* Free mutex */
void _mutex_free(mutex *m) {
/* .. */
}

GCC Newlib

Code template used to retarget locking routines

/*-----------------------------------------------------------------------------
* Name: retarget_lock.c
* Purpose: Locking Routines Retarget Template
* Rev.: 1.0.0
*-----------------------------------------------------------------------------*/
/*
* Copyright (C) 2023 ARM Limited or its affiliates. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
/* Lock structure definition */
struct __lock {
/* ... */
};
/* Newlib mutexes */
struct __lock __lock___sinit_recursive_mutex = {0};
struct __lock __lock___sfp_recursive_mutex = {0};
struct __lock __lock___atexit_recursive_mutex = {0};
struct __lock __lock___at_quick_exit_mutex = {0};
struct __lock __lock___malloc_recursive_mutex = {0};
struct __lock __lock___env_recursive_mutex = {0};
struct __lock __lock___tz_mutex = {0};
struct __lock __lock___dd_hash_mutex = {0};
struct __lock __lock___arc4random_mutex = {0};
/* Allocate lock related resources */
void __retarget_lock_init (_LOCK_T *lock) {
/* .. */
}
/* Allocate recursive lock related resources */
void __retarget_lock_init_recursive (_LOCK_T *lock) {
/* .. */
}
/* Free lock related resources */
void __retarget_lock_close (_LOCK_T lock) {
/* .. */
}
/* Free recursive lock related resources */
void __retarget_lock_close_recursive (_LOCK_T lock) {
/* .. */
}
/* Acquire lock immediately after the lock object is available */
void __retarget_lock_acquire (_LOCK_T lock) {
/* .. */
}
/* Acquire recursive lock immediately after the lock object is available */
void __retarget_lock_acquire_recursive (_LOCK_T lock) {
/* .. */
}
/* Acquire lock if the lock object is available */
int __retarget_lock_try_acquire (_LOCK_T lock) {
/* .. */
return -1;
}
/* Acquire recursive lock if the lock object is available */
/* .. */
return -1;
}
/* Relinquish the lock ownership */
void __retarget_lock_release (_LOCK_T lock) {
/* .. */
}
/* Relinquish the recursive lock ownership */
void __retarget_lock_release_recursive (_LOCK_T lock) {
/* .. */
}

Code template used to retarget system calls

Note

  • All system call functions are provided in this template although there may not be necessary to reimplement them all. Functions that are not necessary may be removed or kept depending on the linker settings.
  • Reimplementing functions like _open, _close,_write, etc. breaks compatibility with the CMSIS-Compiler:IO component. Make sure to remove them from custom implementation when application does not require to reimplement them.
/*-----------------------------------------------------------------------------
* Name: retarget_syscalls.c
* Purpose: System Call Routines Retarget Template
* Rev.: 1.0.0
*-----------------------------------------------------------------------------*/
/*
* Copyright (C) 2023 ARM Limited or its affiliates. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
/* Open file */
int _open (const char *path, int oflag, ...) {
// ...
return (-1);
}
/* Close a file descriptor */
int _close (int fildes) {
// ...
return (-1);
}
/* Write on a file */
ssize_t _write (int fildes, const void *buf, size_t nbyte) {
// ...
return (-1);
}
/* Read from a file */
ssize_t _read (int fildes, void *buf, size_t nbyte) {
// ...
return (-1);
}
/* Move the read/write file offset */
off_t _lseek (int fildes, off_t offset, int whence) {
// ...
return (-1);
}
/* Test for a terminal device */
int _isatty (int fildes) {
// ...
return (0);
}
/* Get file status */
int _fstat (int fildes, struct stat *buf) {
// ...
return (-1);
}
/* Link one file to another file */
int _link(const char *path1, const char *path2) {
// ...
return (-1);
}
/* Remove a directory entry */
int _unlink (const char *path) {
// ...
return (-1);
}
/* Execute a file */
int _execve(const char *path, char *const argv[], char *const envp[]) {
// ...
return -1;
}
/* Create a new process */
pid_t fork (void) {
// ...
return -1;
}
/* Terminate a process */
void _exit (int status) {
// ...
}
/* Send a signal to a process or a group of processes */
int _kill (pid_t pid, int sig) {
// ...
return -1;
}
/* Get the current process id */
pid_t _getpid (void) {
// ...
return 0;
}
/* Wait for a child process to stop or terminate */
pid_t _wait (int *stat_loc) {
// ...
return -1;
}
/* Extend heap space by incr bytes */
void *_sbrk (ptrdiff_t incr) {
// ...
return -1;
}