blob: 6d508fdeb17a3ad684665cf01d3f554cd44bb71d [file] [log] [blame]
Paul Sokolovskydc2c8f02016-04-27 13:45:44 +03001/*
2 * This file is part of the MicroPython project, http://micropython.org/
3 *
4 * The MIT License (MIT)
5 *
6 * Copyright (c) 2016 Paul Sokolovsky
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
25 */
26
27#include <stdint.h>
28#include <stdio.h>
29#include "py/mphal.h"
30#include "py/gc.h"
31
32// Functions for axTLS
33
34void *malloc(size_t size) {
35 return gc_alloc(size, false);
36}
37void free(void *ptr) {
38 gc_free(ptr);
39}
40void *calloc(size_t nmemb, size_t size) {
41 return m_malloc0(nmemb * size);
42}
43void *realloc(void *ptr, size_t size) {
44 return gc_realloc(ptr, size, true);
45}
Paul Sokolovskydc2c8f02016-04-27 13:45:44 +030046
47#define PLATFORM_HTONL(_n) ((uint32_t)( (((_n) & 0xff) << 24) | (((_n) & 0xff00) << 8) | (((_n) >> 8) & 0xff00) | (((_n) >> 24) & 0xff) ))
48#undef htonl
49#undef ntohl
50uint32_t ntohl(uint32_t netlong) {
51 return PLATFORM_HTONL(netlong);
52}
53uint32_t htonl(uint32_t netlong) {
54 return PLATFORM_HTONL(netlong);
55}
56
57time_t time(time_t *t) {
58 return mp_hal_ticks_ms() / 1000;
59}
60
61time_t mktime(void *tm) {
62 return 0;
63}