Updated fileheaders and styled files using astyle.

This commit is contained in:
t-moe
2015-06-08 11:00:52 +02:00
parent 7e61a129a3
commit fceb2d15b2
63 changed files with 6045 additions and 4691 deletions

View File

@@ -1,3 +1,16 @@
/**************************************************************************************************************************************
* Project: discoverpixy
* Website: https://github.com/t-moe/discoverpixy
* Authors: Aaron Schmocker, Timo Lang
* Institution: BFH Bern University of Applied Sciences
* File: discovery/src/newlib_stubs.c
*
* Version History:
* Date Autor Email SHA Changes
* 2015-04-03 timolang@gmail.com 21dd1e2 Starting to integrate usb branch. Optimized Makefiles
*
**************************************************************************************************************************************/
/*
* newlib_stubs.c
*
@@ -32,26 +45,30 @@ extern int errno;
A pointer to a list of environment variables and their values.
For a minimal environment, this empty list is adequate:
*/
char *__env[1] = { 0 };
char **environ = __env;
char* __env[1] = { 0 };
char** environ = __env;
int _write(int file, char *ptr, int len);
int _write(int file, char* ptr, int len);
void _exit(int status) {
void _exit(int status)
{
_write(1, "exit", 4);
while (1) {
;
}
}
int _close(int file) {
int _close(int file)
{
return -1;
}
/*
execve
Transfer control to a new process. Minimal implementation (for a system without processes):
*/
int _execve(char *name, char **argv, char **env) {
int _execve(char* name, char** argv, char** env)
{
errno = ENOMEM;
return -1;
}
@@ -60,7 +77,8 @@ int _execve(char *name, char **argv, char **env) {
Create a new process. Minimal implementation (for a system without processes):
*/
int _fork() {
int _fork()
{
errno = EAGAIN;
return -1;
}
@@ -70,7 +88,8 @@ int _fork() {
all files are regarded as character special devices.
The `sys/stat.h' header file required is distributed in the `include' subdirectory for this C library.
*/
int _fstat(int file, struct stat *st) {
int _fstat(int file, struct stat* st)
{
st->st_mode = S_IFCHR;
return 0;
}
@@ -80,7 +99,8 @@ int _fstat(int file, struct stat *st) {
Process-ID; this is sometimes used to generate strings unlikely to conflict with other processes. Minimal implementation, for a system without processes:
*/
int _getpid() {
int _getpid()
{
return 1;
}
@@ -88,12 +108,14 @@ int _getpid() {
isatty
Query whether output stream is a terminal. For consistency with the other minimal implementations,
*/
int _isatty(int file) {
switch (file){
int _isatty(int file)
{
switch (file) {
case STDOUT_FILENO:
case STDERR_FILENO:
case STDIN_FILENO:
return 1;
default:
//errno = ENOTTY;
errno = EBADF;
@@ -106,7 +128,8 @@ int _isatty(int file) {
kill
Send a signal. Minimal implementation:
*/
int _kill(int pid, int sig) {
int _kill(int pid, int sig)
{
errno = EINVAL;
return (-1);
}
@@ -116,7 +139,8 @@ int _kill(int pid, int sig) {
Establish a new name for an existing file. Minimal implementation:
*/
int _link(char *old, char *new) {
int _link(char* old, char* new)
{
errno = EMLINK;
return -1;
}
@@ -125,7 +149,8 @@ int _link(char *old, char *new) {
lseek
Set position in a file. Minimal implementation:
*/
int _lseek(int file, int ptr, int dir) {
int _lseek(int file, int ptr, int dir)
{
return 0;
}
@@ -134,25 +159,27 @@ int _lseek(int file, int ptr, int dir) {
Increase program data space.
Malloc and related functions depend on this
*/
caddr_t _sbrk(int incr) {
caddr_t _sbrk(int incr)
{
extern char _ebss; // Defined by the linker
static char *heap_end;
char *prev_heap_end;
static char* heap_end;
char* prev_heap_end;
if (heap_end == 0) {
heap_end = &_ebss;
}
prev_heap_end = heap_end;
char * stack = (char*) __get_MSP();
if (heap_end + incr > stack)
{
_write (STDERR_FILENO, "Heap and stack collision\n", 25);
errno = ENOMEM;
return (caddr_t) -1;
//abort ();
}
char* stack = (char*) __get_MSP();
if (heap_end + incr > stack) {
_write(STDERR_FILENO, "Heap and stack collision\n", 25);
errno = ENOMEM;
return (caddr_t) - 1;
//abort ();
}
heap_end += incr;
return (caddr_t) prev_heap_end;
@@ -161,10 +188,10 @@ char * stack = (char*) __get_MSP();
int _open(char *path, int flags, ...)
int _open(char* path, int flags, ...)
{
/* Pretend like we always fail */
return -1;
/* Pretend like we always fail */
return -1;
}
/*
@@ -174,30 +201,33 @@ int _open(char *path, int flags, ...)
*/
int _read(int file, char *ptr, int len) {
int _read(int file, char* ptr, int len)
{
int n;
int num = 0;
switch (file) {
/*case STDIN_FILENO:
for (n = 0; n < len; n++) {
#if STDIN_USART == 1
while ((USART1->SR & USART_FLAG_RXNE) == (uint16_t)RESET) {}
char c = (char)(USART1->DR & (uint16_t)0x01FF);
#elif STDIN_USART == 2
while ((USART2->SR & USART_FLAG_RXNE) == (uint16_t) RESET) {}
char c = (char) (USART2->DR & (uint16_t) 0x01FF);
#elif STDIN_USART == 3
while ((USART3->SR & USART_FLAG_RXNE) == (uint16_t)RESET) {}
char c = (char)(USART3->DR & (uint16_t)0x01FF);
#endif
*ptr++ = c;
num++;
}
break;
default:*/
/*case STDIN_FILENO:
for (n = 0; n < len; n++) {
#if STDIN_USART == 1
while ((USART1->SR & USART_FLAG_RXNE) == (uint16_t)RESET) {}
char c = (char)(USART1->DR & (uint16_t)0x01FF);
#elif STDIN_USART == 2
while ((USART2->SR & USART_FLAG_RXNE) == (uint16_t) RESET) {}
char c = (char) (USART2->DR & (uint16_t) 0x01FF);
#elif STDIN_USART == 3
while ((USART3->SR & USART_FLAG_RXNE) == (uint16_t)RESET) {}
char c = (char)(USART3->DR & (uint16_t)0x01FF);
#endif
*ptr++ = c;
num++;
}
break;
default:*/
errno = EBADF;
return -1;
}
return num;
}
@@ -207,7 +237,8 @@ int _read(int file, char *ptr, int len) {
int _EXFUN(stat,( const char *__path, struct stat *__sbuf ));
*/
int _stat(const char *filepath, struct stat *st) {
int _stat(const char* filepath, struct stat* st)
{
st->st_mode = S_IFCHR;
return 0;
}
@@ -217,7 +248,8 @@ int _stat(const char *filepath, struct stat *st) {
Timing information for current process. Minimal implementation:
*/
clock_t _times(struct tms *buf) {
clock_t _times(struct tms* buf)
{
return -1;
}
@@ -225,7 +257,8 @@ clock_t _times(struct tms *buf) {
unlink
Remove a file's directory entry. Minimal implementation:
*/
int _unlink(char *name) {
int _unlink(char* name)
{
errno = ENOENT;
return -1;
}
@@ -234,7 +267,8 @@ int _unlink(char *name) {
wait
Wait for a child process. Minimal implementation:
*/
int _wait(int *status) {
int _wait(int* status)
{
errno = ECHILD;
return -1;
}
@@ -244,42 +278,61 @@ int _wait(int *status) {
Write a character to a file. `libc' subroutines will use this system routine for output to all files, including stdout
Returns -1 on error or number of bytes sent
*/
int _write(int file, char *ptr, int len) {
int _write(int file, char* ptr, int len)
{
int n;
switch (file) {
case STDOUT_FILENO: /*stdout*/
for (n = 0; n < len; n++) {
#if STDOUT_USART == 1
while ((USART1->SR & USART_FLAG_TC) == (uint16_t)RESET) {}
USART1->DR = (*ptr++ & (uint16_t)0x01FF);
#elif STDOUT_USART == 2
while ((USART2->SR & USART_FLAG_TC) == (uint16_t) RESET) {
}
USART2->DR = (*ptr++ & (uint16_t) 0x01FF);
#elif STDOUT_USART == 3
while ((USART3->SR & USART_FLAG_TC) == (uint16_t)RESET) {}
USART3->DR = (*ptr++ & (uint16_t)0x01FF);
#endif
}
break;
case STDERR_FILENO: /* stderr */
for (n = 0; n < len; n++) {
#if STDERR_USART == 1
while ((USART1->SR & USART_FLAG_TC) == (uint16_t)RESET) {}
USART1->DR = (*ptr++ & (uint16_t)0x01FF);
#elif STDERR_USART == 2
while ((USART2->SR & USART_FLAG_TC) == (uint16_t) RESET) {
}
USART2->DR = (*ptr++ & (uint16_t) 0x01FF);
#elif STDERR_USART == 3
while ((USART3->SR & USART_FLAG_TC) == (uint16_t)RESET) {}
USART3->DR = (*ptr++ & (uint16_t)0x01FF);
#endif
}
break;
default:
errno = EBADF;
return -1;
}
return len;
}