OpenCores
URL https://opencores.org/ocsvn/layer2/layer2/trunk

Subversion Repositories layer2

[/] [layer2/] [trunk/] [sw/] [lib/] [include/] [stdlib.h] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 idiolatrie
/******************************************************************************
2
 * Standard Library                                                           *
3
 ******************************************************************************
4
 * Copyright (C)2011  Mathias Hörtnagl <mathias.hoertnagl@gmail.com>          *
5
 *                                                                            *
6
 * This program is free software: you can redistribute it and/or modify       *
7
 * it under the terms of the GNU General Public License as published by       *
8
 * the Free Software Foundation, either version 3 of the License, or          *
9
 * (at your option) any later version.                                        *
10
 *                                                                            *
11
 * This program is distributed in the hope that it will be useful,            *
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
14
 * GNU General Public License for more details.                               *
15
 *                                                                            *
16
 * You should have received a copy of the GNU General Public License          *
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.      *
18
 ******************************************************************************/
19
#include "stddef.h"
20
 
21
#ifndef _STDLIB_H
22
#define _STDLIB_H
23
 
24
/******************************************************************************
25
 * Timer                                                                      *
26
 ******************************************************************************/
27
 /* Porgammable Intervall Timer control loaction. */
28
#define PIT_ADDRESS ((volatile uint *) 0xfffff000)
29
 
30
/* Time periods in seconds and milliseconds respectivly.
31
   NOTE: No hardware implementation of multiplication available! */
32
#define sec(x)    ( 50000000*x )
33
#define msec(x)   ( 50000*x )
34
 
35
 
36
/******************************************************************************
37
 * RS-232                                                                     *
38
 ******************************************************************************/
39
/* RS-232 Receiver Address. */
40
#define RS232_ADDRESS  ((volatile uint *) 0xffff4000)
41
 
42
/* Poll for valid received serial data. */
43
#define RS232_RCV_POLL ((ushort) 0x8000)
44
 
45
 
46
/* 10 times x. */
47
#define x10(x) ( (x << 3) + (x << 1) )
48
 
49
 
50
/******************************************************************************
51
 * Timer                                                                      *
52
 ******************************************************************************/
53
/* Resets the counter. If you call reset before the counter has finished, it
54
   returns the count progress. */
55
extern uint pit_reset();
56
 
57
/* Set the PIT limit and start counting. */
58
extern void pit_run(uint cycles);
59
 
60
 
61
/******************************************************************************
62
 * RS-232                                                                     *
63
 ******************************************************************************/
64
 /* Wait for one byte of data. Return n reception. */
65
extern uchar rs232_receive();
66
 
67
/* Send one byte of data. */
68
extern void rs232_transmit(uchar chr);
69
 
70
 
71
/******************************************************************************
72
 * Memory Operations                                                          *
73
 ******************************************************************************/
74
 
75
extern void memcpy(const void *src, void *dst, uint len);
76
 
77
extern void memset(const void *ptr, int val, uint len);
78
 
79
extern int memcmp(const void *src, void *dst, uint len);
80
 
81
 
82
/******************************************************************************
83
 * String Operations                                                          *
84
 ******************************************************************************/
85
/* Returns the length of a string */
86
extern uint strlen(const uchar *str);
87
 
88
/* Copys a string at location src to location dst. */
89
extern void strcpy(const uchar *src, uchar *dst);
90
 
91
// KMP algo
92
// char *strstr(const char *str, const char *pat);
93
 
94
/* Returns a pointer to the leftmost occurence of character chr in
95
   string str or NULL, if not found. */
96
extern uchar *strchr(const uchar *str, const uchar chr);
97
 
98
 
99
/******************************************************************************
100
 * Number/String Conversion                                                   *
101
 ******************************************************************************/
102
/* Convert a string containing a decimal number into a number. */
103
extern int atoi(const uchar *str);
104
 
105
//extern char* itoa(int num, char *str);
106
 
107
/* Returns a binary representation of an integer <num>. The buffer <str> must be
108
   at least 35 byte wide to hold the char sequence of the form '0bn...n\0'. */
109
extern uchar* itob(int num, uchar *str);
110
 
111
/* Returns a hexadecimal representation of an integer <num>. The buffer <str>
112
   must be at least 11 byte wide to hold the char sequence of the form
113
   '0xn...n\0'. */
114
extern uchar* itox(int num, uchar *str);
115
 
116
 
117
/******************************************************************************
118
 * Nathematics                                                                *
119
 ******************************************************************************/
120
/* Xorshift RNGs, George Marsaglia
121
   http://www.jstatsoft.org/v08/i14/paper */
122
extern uint rand();
123
 
124
/* Radix-4 Booth Multiplication Algorithm */
125
extern int mul(short a, short b);
126
 
127
extern short div(int a, int b);
128
 
129
 
130
// extern void *malloc(uint size);
131
// extern void *calloc(uint num, uint size);
132
// extern void free(void *ptr);
133
 
134
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.