1 |
13 |
serginhofr |
/* file: libc.c
|
2 |
|
|
* description: small C library prototypes
|
3 |
|
|
* date: 09/2015
|
4 |
|
|
* author: Sergio Johann Filho <sergio.filho@pucrs.br>
|
5 |
|
|
*/
|
6 |
|
|
|
7 |
|
|
/*
|
8 |
|
|
constants, tests and transformations
|
9 |
|
|
*/
|
10 |
|
|
#define NULL ((void *)0)
|
11 |
|
|
#define USED 1
|
12 |
|
|
#define TRUE 1
|
13 |
|
|
#define FALSE 0
|
14 |
|
|
#define isprint(c) (' '<=(c)&&(c)<='~')
|
15 |
|
|
#define isspace(c) ((c)==' '||(c)=='\t'||(c)=='\n'||(c)=='\r')
|
16 |
|
|
#define isdigit(c) ('0'<=(c)&&(c)<='9')
|
17 |
|
|
#define islower(c) ('a'<=(c)&&(c)<='z')
|
18 |
|
|
#define isupper(c) ('A'<=(c)&&(c)<='Z')
|
19 |
|
|
#define isalpha(c) (islower(c)||isupper(c))
|
20 |
|
|
#define isalnum(c) (isalpha(c)||isdigit(c))
|
21 |
|
|
#define min(a,b) ((a)<(b)?(a):(b))
|
22 |
|
|
#define ntohs(A) (((A)>>8) | (((A)&0xff)<<8))
|
23 |
|
|
#define ntohl(A) (((A)>>24) | (((A)&0xff0000)>>8) | (((A)&0xff00)<<8) | ((A)<<24))
|
24 |
|
|
|
25 |
|
|
/*
|
26 |
|
|
custom C library
|
27 |
|
|
*/
|
28 |
|
|
extern void putchar(int32_t value);
|
29 |
|
|
extern int32_t kbhit(void);
|
30 |
|
|
extern int32_t getchar(void);
|
31 |
|
|
extern int8_t *strcpy(int8_t *dst, const int8_t *src);
|
32 |
|
|
extern int8_t *strncpy(int8_t *s1, int8_t *s2, int32_t n);
|
33 |
|
|
extern int8_t *strcat(int8_t *dst, const int8_t *src);
|
34 |
|
|
extern int8_t *strncat(int8_t *s1, int8_t *s2, int32_t n);
|
35 |
|
|
extern int32_t strcmp(const int8_t *s1, const int8_t *s2);
|
36 |
|
|
extern int32_t strncmp(int8_t *s1, int8_t *s2, int32_t n);
|
37 |
|
|
extern int8_t *strstr(const int8_t *string, const int8_t *find);
|
38 |
|
|
extern int32_t strlen(const int8_t *s);
|
39 |
|
|
extern int8_t *strchr(const int8_t *s, int32_t c);
|
40 |
|
|
extern int8_t *strpbrk(int8_t *str, int8_t *set);
|
41 |
|
|
extern int8_t *strsep(int8_t **pp, int8_t *delim);
|
42 |
|
|
extern int8_t *strtok(int8_t *s, const int8_t *delim);
|
43 |
|
|
extern void *memcpy(void *dst, const void *src, uint32_t n);
|
44 |
|
|
extern void *memmove(void *dst, const void *src, uint32_t n);
|
45 |
|
|
extern int32_t memcmp(const void *cs, const void *ct, uint32_t n);
|
46 |
|
|
extern void *memset(void *s, int32_t c, uint32_t n);
|
47 |
|
|
extern int32_t strtol(const int8_t *s, int8_t **end, int32_t base);
|
48 |
|
|
extern int32_t atoi(const int8_t *s);
|
49 |
|
|
extern float atof(const int8_t *p);
|
50 |
|
|
extern int8_t *itoa(int32_t i, int8_t *s, int32_t base);
|
51 |
|
|
extern int32_t puts(const int8_t *str);
|
52 |
|
|
extern int8_t *gets(int8_t *s);
|
53 |
|
|
extern int32_t abs(int32_t n);
|
54 |
|
|
extern int32_t random(void);
|
55 |
|
|
extern void srand(uint32_t seed);
|
56 |
|
|
extern int32_t printf(const int8_t *fmt, ...);
|
57 |
|
|
extern int32_t sprintf(int8_t *out, const int8_t *fmt, ...);
|
58 |
|
|
|
59 |
|
|
/*
|
60 |
|
|
auxiliary routines / interrupt management
|
61 |
|
|
*/
|
62 |
|
|
extern void uart_init(uint32_t baud);
|
63 |
|
|
extern void delay_ms(uint32_t msec);
|
64 |
|
|
extern void delay_us(uint32_t usec);
|
65 |
|
|
void interrupt_handler(uint32_t cause, uint32_t *stack);
|
66 |
|
|
void interrupt_register(uint32_t mask, funcptr ptr);
|
67 |
|
|
|
68 |
|
|
|