diff options
| author | danicampora | 2015-02-06 15:35:48 +0100 |
|---|---|---|
| committer | Damien George | 2015-02-06 22:10:11 +0000 |
| commit | 8785645a952c03315dbf93667b5f7c7eec49762f (patch) | |
| tree | 267e2d572d87e92bfc0bfabf83859231152a2162 /cc3200/util | |
| parent | 97f14606f528180d1482cffbe3571163a1dd9273 (diff) | |
cc3200: Add cc3200 port of MicroPython.
The port currently implements support for GPIO, RTC, ExtInt and the WiFi
subsystem. A small file system is available in the serial flash. A
bootloader which makes OTA updates possible, is also part of this initial
implementation.
Diffstat (limited to 'cc3200/util')
| -rw-r--r-- | cc3200/util/fifo.c | 127 | ||||
| -rw-r--r-- | cc3200/util/fifo.h | 50 | ||||
| -rw-r--r-- | cc3200/util/gccollect.c | 66 | ||||
| -rw-r--r-- | cc3200/util/gccollect.h | 41 | ||||
| -rw-r--r-- | cc3200/util/gchelper.h | 34 | ||||
| -rw-r--r-- | cc3200/util/gchelper.s | 41 | ||||
| -rw-r--r-- | cc3200/util/hash.c | 72 | ||||
| -rw-r--r-- | cc3200/util/hash.h | 10 | ||||
| -rw-r--r-- | cc3200/util/random.c | 114 | ||||
| -rw-r--r-- | cc3200/util/random.h | 37 | ||||
| -rw-r--r-- | cc3200/util/socketfifo.c | 107 | ||||
| -rw-r--r-- | cc3200/util/socketfifo.h | 63 | ||||
| -rw-r--r-- | cc3200/util/std.h | 44 |
13 files changed, 806 insertions, 0 deletions
diff --git a/cc3200/util/fifo.c b/cc3200/util/fifo.c new file mode 100644 index 000000000..73b2b7161 --- /dev/null +++ b/cc3200/util/fifo.c @@ -0,0 +1,127 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2015 Daniel Campora + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include <stdint.h> +#include <stdbool.h> + +#include "std.h" +#include "fifo.h" + + +/****************************************************************************** + DEFINE PUBLIC FUNCTIONS + ******************************************************************************/ +void FIFO_Init (FIFO_t *fifo, unsigned int uiElementsMax, + void (*pfElmentPush)(void * const pvFifo, const void * const pvElement), + void (*pfElementPop)(void * const pvFifo, void * const pvElement)) { + if (fifo) { + fifo->uiFirst = 0; + fifo->uiLast = uiElementsMax - 1; + fifo->uiElementCount = 0; + fifo->uiElementsMax = uiElementsMax; + fifo->pfElementPush = pfElmentPush; + fifo->pfElementPop = pfElementPop; + } +} + +bool FIFO_bPushElement (FIFO_t *fifo, const void * const pvElement) { + if (!fifo) { + return false; + } + // Check if the queue is full + if (true == FIFO_IsFull (fifo)) { + return false; + } + + // Increment the element count + if (fifo->uiElementsMax > fifo->uiElementCount) { + fifo->uiElementCount++; + } + fifo->uiLast++; + if (fifo->uiLast == fifo->uiElementsMax) { + fifo->uiLast = 0; + } + // Insert the element into the queue + fifo->pfElementPush(fifo, pvElement); + return true; +} + +bool FIFO_bPopElement (FIFO_t *fifo, void * const pvElement) { + if (!fifo) { + return false; + } + // Check if the queue is empty + if (true == FIFO_IsEmpty (fifo)) { + return false; + } + + // Get the element from the queue + fifo->pfElementPop(fifo, pvElement); + // Decrement the element count + if (fifo->uiElementCount > 0) { + fifo->uiElementCount--; + } + fifo->uiFirst++; + if (fifo->uiFirst == fifo->uiElementsMax) { + fifo->uiFirst = 0; + } + return true; +} + +bool FIFO_bPeekElement (FIFO_t *fifo, void * const pvElement) { + if (!fifo) { + return false; + } + // Check if the queue is empty + if (true == FIFO_IsEmpty (fifo)) { + return false; + } + // Get the element from the queue + fifo->pfElementPop(fifo, pvElement); + return true; +} + +bool FIFO_IsEmpty (FIFO_t *fifo) { + if (fifo) { + return ((fifo->uiElementCount == 0) ? true : false); + } + return false; +} + +bool FIFO_IsFull (FIFO_t *fifo) { + if (fifo) { + return ((fifo->uiElementCount < fifo->uiElementsMax) ? false : true); + } + return false; +} + +void FIFO_Flush (FIFO_t *fifo) { + if (fifo) { + fifo->uiElementCount = 0; + fifo->uiFirst = 0; + fifo->uiLast = fifo->uiElementsMax - 1; + } +} diff --git a/cc3200/util/fifo.h b/cc3200/util/fifo.h new file mode 100644 index 000000000..c8590f5c2 --- /dev/null +++ b/cc3200/util/fifo.h @@ -0,0 +1,50 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2015 Daniel Campora + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef FIFO_H_ +#define FIFO_H_ + +typedef struct { + void *pvElements; + unsigned int uiElementCount; + unsigned int uiElementsMax; + unsigned int uiFirst; + unsigned int uiLast; + void (*pfElementPush)(void * const pvFifo, const void * const pvElement); + void (*pfElementPop)(void * const pvFifo, void * const pvElement); +}FIFO_t; + +extern void FIFO_Init (FIFO_t *fifo, unsigned int uiElementsMax, +void (*pfElmentPush)(void * const pvFifo, const void * const pvElement), +void (*pfElementPop)(void * const pvFifo, void * const pvElement)); +extern bool FIFO_bPushElement (FIFO_t *fifo, const void * const pvElement); +extern bool FIFO_bPopElement (FIFO_t *fifo, void * const pvElement); +extern bool FIFO_bPeekElement (FIFO_t *fifo, void * const pvElement); +extern bool FIFO_IsEmpty (FIFO_t *fifo); +extern bool FIFO_IsFull (FIFO_t *fifo); +extern void FIFO_Flush (FIFO_t *fifo); + +#endif /* FIFO_H_ */ diff --git a/cc3200/util/gccollect.c b/cc3200/util/gccollect.c new file mode 100644 index 000000000..9ab19d63d --- /dev/null +++ b/cc3200/util/gccollect.c @@ -0,0 +1,66 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2013, 2014 Damien P. George + * Copyright (c) 2015 Daniel Campora + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include <stdio.h> +#include <stdint.h> + +#include "mpconfig.h" +#include "misc.h" +#include "qstr.h" +#include "obj.h" +#include "gc.h" +#include "gccollect.h" +#include "gchelper.h" +#include MICROPY_HAL_H + +/****************************************************************************** +DECLARE PRIVATE DATA + ******************************************************************************/ +static uint32_t stackend; + + +/****************************************************************************** +DECLARE PUBLIC FUNCTIONS + ******************************************************************************/ +void gc_collect_init (uint32_t sp) { + stackend = sp; +} + +void gc_collect(void) { + // start the GC + gc_collect_start(); + + // get the registers and the sp + mp_uint_t regs[10]; + mp_uint_t sp = gc_helper_get_regs_and_sp(regs); + + // trace the stack, including the registers (since they live on the stack in this function) + gc_collect_root((void**)sp, (stackend - sp) / sizeof(uint32_t)); + + // end the GC + gc_collect_end(); +} diff --git a/cc3200/util/gccollect.h b/cc3200/util/gccollect.h new file mode 100644 index 000000000..8e4c8896b --- /dev/null +++ b/cc3200/util/gccollect.h @@ -0,0 +1,41 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2013, 2014 Damien P. George + * Copyright (c) 2015 Daniel Campora + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +// variables defining memory layout +extern uint32_t _etext; +extern uint32_t _sidata; +extern uint32_t _data; +extern uint32_t _edata; +extern uint32_t _bss; +extern uint32_t _ebss; +extern uint32_t _heap; +extern uint32_t _eheap; +extern uint32_t _stack; +extern uint32_t _estack; + +void gc_collect_init (uint32_t sp); +void gc_collect(void); diff --git a/cc3200/util/gchelper.h b/cc3200/util/gchelper.h new file mode 100644 index 000000000..1f7d2fece --- /dev/null +++ b/cc3200/util/gchelper.h @@ -0,0 +1,34 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2013, 2014 Damien P. George + * Copyright (c) 2015 Daniel Campora + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef GC_HELPER_H_ +#define GC_HELPER_H_ + +extern mp_uint_t gc_helper_get_sp(void); +extern mp_uint_t gc_helper_get_regs_and_sp(mp_uint_t *regs); + +#endif /* GC_HELPER_H_ */ diff --git a/cc3200/util/gchelper.s b/cc3200/util/gchelper.s new file mode 100644 index 000000000..aa8fb499e --- /dev/null +++ b/cc3200/util/gchelper.s @@ -0,0 +1,41 @@ + .syntax unified + .cpu cortex-m4 + .thumb + .text + .align 2 + + + +@ uint gc_helper_get_sp(void) + .global gc_helper_get_sp + .thumb + .thumb_func + .type gc_helper_get_sp, %function +gc_helper_get_sp: + @ return the sp + mov r0, sp + bx lr + + + +@ uint gc_helper_get_regs_and_sp(r0=uint regs[10]) + .global gc_helper_get_regs_and_sp + .thumb + .thumb_func + .type gc_helper_get_regs_and_sp, %function +gc_helper_get_regs_and_sp: + @ store registers into given array + str r4, [r0], #4 + str r5, [r0], #4 + str r6, [r0], #4 + str r7, [r0], #4 + str r8, [r0], #4 + str r9, [r0], #4 + str r10, [r0], #4 + str r11, [r0], #4 + str r12, [r0], #4 + str r13, [r0], #4 + + @ return the sp + mov r0, sp + bx lr diff --git a/cc3200/util/hash.c b/cc3200/util/hash.c new file mode 100644 index 000000000..a7afdf9f2 --- /dev/null +++ b/cc3200/util/hash.c @@ -0,0 +1,72 @@ +#include "std.h" +#include <stdint.h> +#include <stdbool.h> +#include "inc/hw_types.h" +#include "inc/hw_ints.h" +#include "inc/hw_nvic.h" +#include "inc/hw_shamd5.h" +#include "inc/hw_dthe.h" +#include "hw_memmap.h" +#include "rom_map.h" +#include "prcm.h" +#include "shamd5.h" +#include "hash.h" + +#ifdef USE_FREERTOS +#include "FreeRTOS.h" +#include "task.h" +#include "semphr.h" +#endif + + +#ifdef USE_FREERTOS +static SemaphoreHandle_t xShamd5Semaphore = NULL; +#endif + +void HASH_Init (void) { + // Enable the Data Hashing and Transform Engine + MAP_PRCMPeripheralClkEnable(PRCM_DTHE, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK); +#ifdef USE_FREERTOS + vSemaphoreCreateBinary(xShamd5Semaphore); +#endif +} + + + +void HASH_SHAMD5Start (uint32_t algo, uint32_t blocklen) { + +#ifdef USE_FREERTOS + xSemaphoreTake (xShamd5Semaphore, portMAX_DELAY); +#endif + + MAP_PRCMPeripheralReset(PRCM_DTHE); + + // wait until the context is ready + while ((HWREG(SHAMD5_BASE + SHAMD5_O_IRQSTATUS) & SHAMD5_INT_CONTEXT_READY) == 0); + + // Configure the SHA/MD5 module algorithm + MAP_SHAMD5ConfigSet(SHAMD5_BASE, algo); + + // if not a multiple of 64 bytes, close the hash + if (blocklen % 64) { + HWREG(SHAMD5_BASE + SHAMD5_O_MODE) |= SHAMD5_MODE_CLOSE_HASH; + } + + // set the lenght + HWREG(SHAMD5_BASE + SHAMD5_O_LENGTH) = blocklen; +} + +void HASH_SHAMD5Update (uint8_t *data, uint32_t datalen) { + // write the data + SHAMD5DataWriteMultiple(data, datalen); +} + +void HASH_SHAMD5Read (uint8_t *hash) { + // wait for the output to be ready. + while((HWREG(SHAMD5_BASE + SHAMD5_O_IRQSTATUS) & SHAMD5_INT_OUTPUT_READY) == 0); + // read the result. + MAP_SHAMD5ResultRead(SHAMD5_BASE, hash); +#ifdef USE_FREERTOS + xSemaphoreGive (xShamd5Semaphore); +#endif +} diff --git a/cc3200/util/hash.h b/cc3200/util/hash.h new file mode 100644 index 000000000..d13158461 --- /dev/null +++ b/cc3200/util/hash.h @@ -0,0 +1,10 @@ +#ifndef HASH_H_ +#define HASH_H_ + +extern void HASH_Init (void); +extern void HASH_SHAMD5Start (uint32_t algo, uint32_t blocklen); +extern void HASH_SHAMD5Update (uint8_t *data, uint32_t datalen); +extern void HASH_SHAMD5Read (uint8_t *hash); + + +#endif /* HASH_H_ */ diff --git a/cc3200/util/random.c b/cc3200/util/random.c new file mode 100644 index 000000000..be6400def --- /dev/null +++ b/cc3200/util/random.c @@ -0,0 +1,114 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2015 Daniel Campora + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include <stdint.h> +#include <stdbool.h> + +#include "inc/hw_types.h" +#include "inc/hw_ints.h" +#include "inc/hw_memmap.h" +#include "rom_map.h" +#include "prcm.h" +#include "simplelink.h" +#include "modwlan.h" +#include "py/obj.h" +#include "random.h" + + +/****************************************************************************** +* LOCAL TYPES +******************************************************************************/ +typedef union Id_t { + uint32_t id32; + uint16_t id16[3]; + uint8_t id8[6]; +} Id_t; + +/****************************************************************************** +* LOCAL VARIABLES +******************************************************************************/ +static uint32_t s_seed; + +/****************************************************************************** +* LOCAL FUNCTION DECLARATIONS +******************************************************************************/ +static uint32_t lfsr (uint32_t input); + +/****************************************************************************** +* PRIVATE FUNCTIONS +******************************************************************************/ +static uint32_t lfsr (uint32_t input) { + assert( input != 0 ); + + /*lint -save -e501*/ + return (input >> 1) ^ (-(input & 0x01) & 0x00E10000); + /*lint -restore*/ +} + +#if MICROPY_HW_ENABLE_RNG +/// \moduleref rng + +/// \function rng() +/// Return a 24-bit hardware generated random number. +STATIC mp_obj_t pyb_rng_get(void) { + return mp_obj_new_int(rng_get()); +} + +MP_DEFINE_CONST_FUN_OBJ_0(pyb_rng_get_obj, pyb_rng_get); +#endif + +/****************************************************************************** +* PUBLIC FUNCTIONS +******************************************************************************/ +void rng_init0 (void) { + Id_t juggler; + uint32_t seconds; + uint16_t mseconds; + + // get the seconds and the milliseconds from the RTC + MAP_PRCMRTCGet(&seconds, &mseconds); + + wlan_get_mac (juggler.id8); + + // Flatten the 48-bit board identification to 24 bits + juggler.id16[0] ^= juggler.id16[2]; + + juggler.id8[0] ^= juggler.id8[3]; + juggler.id8[1] ^= juggler.id8[4]; + juggler.id8[2] ^= juggler.id8[5]; + + s_seed = juggler.id32 & 0x00FFFFFF; + s_seed += (seconds & 0x000FFFFF) + mseconds; + // The seed must not be zero + if (s_seed == 0) { + s_seed = 1; + } +} + +uint32_t rng_get (void) { + s_seed = lfsr( s_seed ); + return s_seed; +} diff --git a/cc3200/util/random.h b/cc3200/util/random.h new file mode 100644 index 000000000..78ca57893 --- /dev/null +++ b/cc3200/util/random.h @@ -0,0 +1,37 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2015 Daniel Campora + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef __RANDOM_H +#define __RANDOM_H + +void rng_init0 (void); +uint32_t rng_get (void); + +#if MICROPY_HW_ENABLE_RNG + MP_DECLARE_CONST_FUN_OBJ(pyb_rng_get_obj); +#endif + +#endif // __RANDOM_H diff --git a/cc3200/util/socketfifo.c b/cc3200/util/socketfifo.c new file mode 100644 index 000000000..cfe92a82b --- /dev/null +++ b/cc3200/util/socketfifo.c @@ -0,0 +1,107 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2015 Daniel Campora + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include <stdint.h> +#include <stdbool.h> +#include <string.h> + +#include <std.h> +#include "osi.h" +#include "fifo.h" +#include "socketfifo.h" + + +/*---------------------------------------------------------------------------- + ** Declare private functions + */ +static void socketfifo_Push (void * const pvFifo, const void * const pvElement); +static void socketfifo_Pop (void * const pvFifo, void * const pvElement); + +/*---------------------------------------------------------------------------- + ** Declare private data + */ +static FIFO_t *socketfifo; + +/*---------------------------------------------------------------------------- + ** Define public functions + */ +void SOCKETFIFO_Init (FIFO_t *fifo, void *elements, uint32_t maxcount) { + // Initialize global data + socketfifo = fifo; + socketfifo->pvElements = elements; + FIFO_Init (socketfifo, maxcount, socketfifo_Push, socketfifo_Pop); +} + +bool SOCKETFIFO_Push (const void * const element) { + return FIFO_bPushElement (socketfifo, element); +} + +bool SOCKETFIFO_Pop (void * const element) { + return FIFO_bPopElement (socketfifo, element); +} + +bool SOCKETFIFO_Peek (void * const element) { + return FIFO_bPeekElement (socketfifo, element); +} + +bool SOCKETFIFO_IsEmpty (void) { + return FIFO_IsEmpty (socketfifo); +} + +bool SOCKETFIFO_IsFull (void) { + return FIFO_IsFull (socketfifo); +} + +void SOCKETFIFO_Flush (void) { + SocketFifoElement_t element; + while (SOCKETFIFO_Pop(&element)) { + if (element.freedata) { + mem_Free(element.data); + } + } +} + +unsigned int SOCKETFIFO_Count (void) { + return socketfifo->uiElementCount; +} + +/*---------------------------------------------------------------------------- + ** Define private functions + */ +static void socketfifo_Push (void * const pvFifo, const void * const pvElement) { + if ((pvFifo != NULL) && (NULL != pvElement)) { + unsigned int uiLast = ((FIFO_t *)pvFifo)->uiLast; + memcpy (&((SocketFifoElement_t *)((FIFO_t *)pvFifo)->pvElements)[uiLast], pvElement, sizeof(SocketFifoElement_t)); + } +} + +static void socketfifo_Pop (void * const pvFifo, void * const pvElement) { + if ((pvFifo != NULL) && (NULL != pvElement)) { + unsigned int uiFirst = ((FIFO_t *)pvFifo)->uiFirst; + memcpy (pvElement, &((SocketFifoElement_t *)((FIFO_t *)pvFifo)->pvElements)[uiFirst], sizeof(SocketFifoElement_t)); + } +} + diff --git a/cc3200/util/socketfifo.h b/cc3200/util/socketfifo.h new file mode 100644 index 000000000..69b17658f --- /dev/null +++ b/cc3200/util/socketfifo.h @@ -0,0 +1,63 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2015 Daniel Campora + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef SOCKETFIFO_H_ +#define SOCKETFIFO_H_ + +/*---------------------------------------------------------------------------- + ** Imports + */ + +/*---------------------------------------------------------------------------- + ** Define constants + */ + +/*---------------------------------------------------------------------------- + ** Define types + */ + +typedef struct { + void *data; + signed short *sd; + unsigned short datasize; + unsigned char closesockets; + bool freedata; + +}SocketFifoElement_t; + +/*---------------------------------------------------------------------------- + ** Declare public functions + */ +extern void SOCKETFIFO_Init (FIFO_t *fifo, void *elements, uint32_t maxcount); +extern bool SOCKETFIFO_Push (const void * const element); +extern bool SOCKETFIFO_Pop (void * const element); +extern bool SOCKETFIFO_Peek (void * const element); +extern bool SOCKETFIFO_IsEmpty (void); +extern bool SOCKETFIFO_IsFull (void); +extern void SOCKETFIFO_Flush (void); +extern unsigned int SOCKETFIFO_Count (void); + +#endif /* SOCKETFIFO_H_ */ diff --git a/cc3200/util/std.h b/cc3200/util/std.h new file mode 100644 index 000000000..8368432b9 --- /dev/null +++ b/cc3200/util/std.h @@ -0,0 +1,44 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2013, 2014 Damien P. George + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +typedef unsigned int size_t; + +void *memcpy(void *dest, const void *src, size_t n); +void *memmove(void *dest, const void *src, size_t n); +void *memset(void *s, int c, size_t n); + +size_t strlen(const char *str); +int strcmp(const char *s1, const char *s2); +int strncmp(const char *s1, const char *s2, size_t n); +char *strcpy(char *dest, const char *src); +char *strcat(char *dest, const char *src); +char *strchr(const char *s, int c); +char *strstr(const char *haystack, const char *needle); + +int printf(const char *fmt, ...); +int snprintf(char *str, size_t size, const char *fmt, ...); + +void stoupper (char *str); |
