summaryrefslogtreecommitdiff
path: root/cc3200
diff options
context:
space:
mode:
Diffstat (limited to 'cc3200')
-rw-r--r--cc3200/Makefile3
-rw-r--r--cc3200/README.md2
-rw-r--r--cc3200/application.mk20
-rw-r--r--cc3200/bootmgr/main.c3
-rw-r--r--cc3200/fatfs/src/diskio.c209
-rw-r--r--cc3200/fatfs/src/drivers/sd_diskio.c3
-rw-r--r--cc3200/fatfs/src/drivers/sflash_diskio.c5
-rw-r--r--cc3200/fatfs/src/ffconf.c93
-rw-r--r--cc3200/fatfs/src/option/syscall.c150
-rw-r--r--cc3200/fatfs_port.c74
-rw-r--r--cc3200/ftp/ftp.c161
-rw-r--r--cc3200/hal/cc3200_hal.c14
-rw-r--r--cc3200/hal/cc3200_hal.h6
-rw-r--r--cc3200/main.c7
-rw-r--r--cc3200/misc/help.c19
-rw-r--r--cc3200/misc/mpexception.c3
-rw-r--r--cc3200/misc/mpexception.h3
-rw-r--r--cc3200/misc/mpirq.c2
-rw-r--r--cc3200/misc/mpsystick.c71
-rw-r--r--cc3200/mods/modmachine.c6
-rw-r--r--cc3200/mods/modnetwork.c5
-rw-r--r--cc3200/mods/moduhashlib.c4
-rw-r--r--cc3200/mods/moduos.c472
-rw-r--r--cc3200/mods/moduos.h16
-rw-r--r--cc3200/mods/modusocket.c298
-rw-r--r--cc3200/mods/modussl.c1
-rw-r--r--cc3200/mods/modutime.c63
-rw-r--r--cc3200/mods/modwlan.c299
-rw-r--r--cc3200/mods/modwlan.h15
-rw-r--r--cc3200/mods/pybadc.c9
-rw-r--r--cc3200/mods/pybflash.c109
-rw-r--r--cc3200/mods/pybflash.h (renamed from cc3200/misc/mpsystick.h)18
-rw-r--r--cc3200/mods/pybi2c.c93
-rw-r--r--cc3200/mods/pybpin.c8
-rw-r--r--cc3200/mods/pybrtc.c15
-rw-r--r--cc3200/mods/pybsd.c51
-rw-r--r--cc3200/mods/pybspi.c5
-rw-r--r--cc3200/mods/pybtimer.c5
-rw-r--r--cc3200/mods/pybuart.c27
-rw-r--r--cc3200/mods/pybwdt.c5
-rw-r--r--cc3200/mpconfigport.h36
-rw-r--r--cc3200/mptask.c65
-rw-r--r--cc3200/simplelink/user.h2
-rw-r--r--cc3200/telnet/telnet.c14
-rw-r--r--cc3200/util/std.h36
45 files changed, 887 insertions, 1638 deletions
diff --git a/cc3200/Makefile b/cc3200/Makefile
index 1798ac927..663496435 100644
--- a/cc3200/Makefile
+++ b/cc3200/Makefile
@@ -20,9 +20,10 @@ include ../py/mkenv.mk
CROSS_COMPILE ?= arm-none-eabi-
CFLAGS_CORTEX_M4 = -mthumb -mtune=cortex-m4 -march=armv7e-m -mabi=aapcs -mcpu=cortex-m4 -msoft-float -mfloat-abi=soft -fsingle-precision-constant -Wdouble-promotion
-CFLAGS = -Wall -Wpointer-arith -Werror -ansi -std=gnu99 -nostdlib $(CFLAGS_CORTEX_M4) -Os
+CFLAGS = -Wall -Wpointer-arith -Werror -std=gnu99 -nostdlib $(CFLAGS_CORTEX_M4) -Os
CFLAGS += -g -ffunction-sections -fdata-sections -fno-common -fsigned-char -mno-unaligned-access
CFLAGS += -Iboards/$(BOARD)
+CFLAGS += $(CFLAGS_MOD)
LDFLAGS = -Wl,-nostdlib -Wl,--gc-sections -Wl,-Map=$@.map
diff --git a/cc3200/README.md b/cc3200/README.md
index 753fd450a..53cad3ba0 100644
--- a/cc3200/README.md
+++ b/cc3200/README.md
@@ -138,7 +138,7 @@ If `WIPY_IP`, `WIPY_USER` or `WIPY_PWD` are omitted the default values (the ones
## Regarding old revisions of the CC3200-LAUNCHXL
First silicon (pre-release) revisions of the CC3200 had issues with the ram blocks, and MicroPython cannot run
-there. Make sure to use a **v4.1 (or higer) LAUNCHXL board** when trying this port, otherwise it won't work.
+there. Make sure to use a **v4.1 (or higher) LAUNCHXL board** when trying this port, otherwise it won't work.
### Note regarding FileZilla
diff --git a/cc3200/application.mk b/cc3200/application.mk
index f2801c337..1f54b764b 100644
--- a/cc3200/application.mk
+++ b/cc3200/application.mk
@@ -18,10 +18,6 @@ APP_INC += -Iutil
APP_INC += -Ibootmgr
APP_INC += -I$(BUILD)
APP_INC += -I$(BUILD)/genhdr
-APP_INC += -I../lib/fatfs
-APP_INC += -I../lib/mp-readline
-APP_INC += -I../lib/netutils
-APP_INC += -I../lib/timeutils
APP_INC += -I../stmhal
APP_CPPDEFINES = -Dgcc -DTARGET_IS_CC3200 -DSL_FULL -DUSE_FREERTOS
@@ -29,9 +25,6 @@ APP_CPPDEFINES = -Dgcc -DTARGET_IS_CC3200 -DSL_FULL -DUSE_FREERTOS
APP_FATFS_SRC_C = $(addprefix fatfs/src/,\
drivers/sflash_diskio.c \
drivers/sd_diskio.c \
- option/syscall.c \
- diskio.c \
- ffconf.c \
)
APP_RTOS_SRC_C = $(addprefix FreeRTOS/Source/,\
@@ -81,7 +74,6 @@ APP_MISC_SRC_C = $(addprefix misc/,\
mpirq.c \
mperror.c \
mpexception.c \
- mpsystick.c \
)
APP_MODS_SRC_C = $(addprefix mods/,\
@@ -98,6 +90,7 @@ APP_MODS_SRC_C = $(addprefix mods/,\
pybpin.c \
pybi2c.c \
pybrtc.c \
+ pybflash.c \
pybsd.c \
pybsleep.c \
pybspi.c \
@@ -143,24 +136,21 @@ APP_MAIN_SRC_C = \
main.c \
mptask.c \
mpthreadport.c \
- serverstask.c
+ serverstask.c \
+ fatfs_port.c \
APP_LIB_SRC_C = $(addprefix lib/,\
- fatfs/ff.c \
- fatfs/option/ccsbcs.c \
+ oofatfs/ff.c \
+ oofatfs/option/unicode.c \
libc/string0.c \
mp-readline/readline.c \
netutils/netutils.c \
timeutils/timeutils.c \
utils/pyexec.c \
- utils/pyhelp.c \
)
APP_STM_SRC_C = $(addprefix stmhal/,\
bufhelper.c \
- builtin_open.c \
- import.c \
- input.c \
irq.c \
pybstdio.c \
)
diff --git a/cc3200/bootmgr/main.c b/cc3200/bootmgr/main.c
index 97c8b36af..0d9ab35f8 100644
--- a/cc3200/bootmgr/main.c
+++ b/cc3200/bootmgr/main.c
@@ -26,8 +26,7 @@
#include <stdint.h>
#include <stdbool.h>
-
-#include "std.h"
+#include <stdio.h>
#include "py/mpconfig.h"
#include "hw_ints.h"
diff --git a/cc3200/fatfs/src/diskio.c b/cc3200/fatfs/src/diskio.c
deleted file mode 100644
index 74bc6a0d5..000000000
--- a/cc3200/fatfs/src/diskio.c
+++ /dev/null
@@ -1,209 +0,0 @@
-/*-----------------------------------------------------------------------*/
-/* Low level disk I/O module skeleton for FatFs (C)ChaN, 2014 */
-/*-----------------------------------------------------------------------*/
-/* If a working storage control module is available, it should be */
-/* attached to the FatFs via a glue function rather than modifying it. */
-/* This is an example of glue functions to attach various exsisting */
-/* storage control modules to the FatFs module with a defined API. */
-/*-----------------------------------------------------------------------*/
-#include <stdint.h>
-#include <stdbool.h>
-
-#include "py/mpconfig.h"
-#include "py/runtime.h"
-#include "py/obj.h"
-#include "lib/fatfs/ff.h"
-#include "lib/fatfs/diskio.h" /* FatFs lower layer API */
-#include "sflash_diskio.h" /* Serial flash disk IO API */
-#include "sd_diskio.h" /* SDCARD disk IO API */
-#include "inc/hw_types.h"
-#include "inc/hw_ints.h"
-#include "inc/hw_memmap.h"
-#include "rom_map.h"
-#include "prcm.h"
-#include "pybrtc.h"
-#include "timeutils.h"
-#include "pybsd.h"
-#include "moduos.h"
-
-
-/*-----------------------------------------------------------------------*/
-/* Get Drive Status */
-/*-----------------------------------------------------------------------*/
-
-DSTATUS disk_status (
- BYTE pdrv /* Physical drive nmuber to identify the drive */
-)
-{
- if (pdrv == PD_FLASH) {
- return sflash_disk_status();
- } else {
- os_fs_mount_t *mount_obj;
- if ((mount_obj = osmount_find_by_volume(pdrv))) {
- if (mount_obj->writeblocks[0] == MP_OBJ_NULL) {
- return STA_PROTECT;
- }
- return 0;
- }
- }
- return STA_NODISK;
-}
-
-/*-----------------------------------------------------------------------*/
-/* Inidialize a Drive */
-/*-----------------------------------------------------------------------*/
-
-DSTATUS disk_initialize (
- BYTE pdrv /* Physical drive nmuber to identify the drive */
-)
-{
- if (pdrv == PD_FLASH) {
- if (RES_OK != sflash_disk_init()) {
- return STA_NOINIT;
- }
- } else {
- os_fs_mount_t *mount_obj;
- if ((mount_obj = osmount_find_by_volume(pdrv))) {
- if (mount_obj->writeblocks[0] == MP_OBJ_NULL) {
- return STA_PROTECT;
- }
- return 0;
- }
- }
- return STA_NODISK;
-}
-
-/*-----------------------------------------------------------------------*/
-/* Read Sector(s) */
-/*-----------------------------------------------------------------------*/
-
-DRESULT disk_read (
- BYTE pdrv, /* Physical drive nmuber to identify the drive */
- BYTE *buff, /* Data buffer to store read data */
- DWORD sector, /* Sector address in LBA */
- UINT count /* Number of sectors to read */
-)
-{
- if (pdrv == PD_FLASH) {
- return sflash_disk_read(buff, sector, count);
- } else {
- os_fs_mount_t *mount_obj;
- if ((mount_obj = osmount_find_by_volume(pdrv))) {
- // optimization for the built-in sd card device
- if (mount_obj->device == (mp_obj_t)&pybsd_obj) {
- return sd_disk_read(buff, sector, count);
- }
- mount_obj->readblocks[2] = MP_OBJ_NEW_SMALL_INT(sector);
- mount_obj->readblocks[3] = mp_obj_new_bytearray_by_ref(count * 512, buff);
- return mp_obj_get_int(mp_call_method_n_kw(2, 0, mount_obj->readblocks));
- }
- // nothing mounted
- return RES_ERROR;
- }
- return RES_PARERR;
-}
-
-/*-----------------------------------------------------------------------*/
-/* Write Sector(s) */
-/*-----------------------------------------------------------------------*/
-
-#if _USE_WRITE
-DRESULT disk_write (
- BYTE pdrv, /* Physical drive nmuber to identify the drive */
- const BYTE *buff, /* Data to be written */
- DWORD sector, /* Sector address in LBA */
- UINT count /* Number of sectors to write */
-)
-{
- if (pdrv == PD_FLASH) {
- return sflash_disk_write(buff, sector, count);
- } else {
- os_fs_mount_t *mount_obj;
- if ((mount_obj = osmount_find_by_volume(pdrv))) {
- // optimization for the built-in sd card device
- if (mount_obj->device == (mp_obj_t)&pybsd_obj) {
- return sd_disk_write(buff, sector, count);
- }
- mount_obj->writeblocks[2] = MP_OBJ_NEW_SMALL_INT(sector);
- mount_obj->writeblocks[3] = mp_obj_new_bytearray_by_ref(count * 512, (void *)buff);
- return mp_obj_get_int(mp_call_method_n_kw(2, 0, mount_obj->writeblocks));
- }
- // nothing mounted
- return RES_ERROR;
- }
- return RES_PARERR;
-}
-#endif
-
-
-/*-----------------------------------------------------------------------*/
-/* Miscellaneous Functions */
-/*-----------------------------------------------------------------------*/
-
-#if _USE_IOCTL
-DRESULT disk_ioctl (
- BYTE pdrv, /* Physical drive nmuber (0..) */
- BYTE cmd, /* Control code */
- void *buff /* Buffer to send/receive control data */
-)
-{
- if (pdrv == PD_FLASH) {
- switch (cmd) {
- case CTRL_SYNC:
- return sflash_disk_flush();
- case GET_SECTOR_COUNT:
- *((DWORD*)buff) = SFLASH_SECTOR_COUNT;
- return RES_OK;
- case GET_SECTOR_SIZE:
- *((DWORD*)buff) = SFLASH_SECTOR_SIZE;
- return RES_OK;
- case GET_BLOCK_SIZE:
- *((DWORD*)buff) = 1; // high-level sector erase size in units of the block size
- return RES_OK;
- }
- } else {
- os_fs_mount_t *mount_obj;
- if ((mount_obj = osmount_find_by_volume(pdrv))) {
- switch (cmd) {
- case CTRL_SYNC:
- if (mount_obj->sync[0] != MP_OBJ_NULL) {
- mp_call_method_n_kw(0, 0, mount_obj->sync);
- }
- return RES_OK;
- case GET_SECTOR_COUNT:
- // optimization for the built-in sd card device
- if (mount_obj->device == (mp_obj_t)&pybsd_obj) {
- *((DWORD*)buff) = sd_disk_info.ulNofBlock * (sd_disk_info.ulBlockSize / 512);
- } else {
- *((DWORD*)buff) = mp_obj_get_int(mp_call_method_n_kw(0, 0, mount_obj->count));
- }
- return RES_OK;
- case GET_SECTOR_SIZE:
- *((DWORD*)buff) = SD_SECTOR_SIZE; // Sector size is fixed to 512 bytes, as with SD cards
- return RES_OK;
- case GET_BLOCK_SIZE:
- *((DWORD*)buff) = 1; // high-level sector erase size in units of the block size
- return RES_OK;
- }
- }
- // nothing mounted
- return RES_ERROR;
- }
- return RES_PARERR;
-}
-#endif
-
-#if !_FS_READONLY && !_FS_NORTC
-DWORD get_fattime (
- void
-)
-{
- timeutils_struct_time_t tm;
- timeutils_seconds_since_2000_to_struct_time(pyb_rtc_get_seconds(), &tm);
-
- return ((tm.tm_year - 1980) << 25) | ((tm.tm_mon) << 21) |
- ((tm.tm_mday) << 16) | ((tm.tm_hour) << 11) |
- ((tm.tm_min) << 5) | (tm.tm_sec >> 1);
-}
-#endif
-
diff --git a/cc3200/fatfs/src/drivers/sd_diskio.c b/cc3200/fatfs/src/drivers/sd_diskio.c
index c20969bfb..0a1379181 100644
--- a/cc3200/fatfs/src/drivers/sd_diskio.c
+++ b/cc3200/fatfs/src/drivers/sd_diskio.c
@@ -39,11 +39,12 @@
#include "py/mpconfig.h"
#include "py/mphal.h"
+#include "lib/oofatfs/ff.h"
+#include "lib/oofatfs/diskio.h"
#include "hw_types.h"
#include "hw_memmap.h"
#include "hw_ints.h"
#include "rom_map.h"
-#include "diskio.h"
#include "sd_diskio.h"
#include "sdhost.h"
#include "pin.h"
diff --git a/cc3200/fatfs/src/drivers/sflash_diskio.c b/cc3200/fatfs/src/drivers/sflash_diskio.c
index 7fb2c97a7..6a1fc4068 100644
--- a/cc3200/fatfs/src/drivers/sflash_diskio.c
+++ b/cc3200/fatfs/src/drivers/sflash_diskio.c
@@ -1,11 +1,12 @@
#include <stdint.h>
#include <stdbool.h>
-#include "std.h"
+#include <stdio.h>
#include "py/mpconfig.h"
#include "py/obj.h"
+#include "lib/oofatfs/ff.h"
+#include "lib/oofatfs/diskio.h"
#include "simplelink.h"
-#include "diskio.h"
#include "sflash_diskio.h"
#include "debug.h"
#include "modnetwork.h"
diff --git a/cc3200/fatfs/src/ffconf.c b/cc3200/fatfs/src/ffconf.c
deleted file mode 100644
index 71ef6a40b..000000000
--- a/cc3200/fatfs/src/ffconf.c
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * 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.
- */
-
-#include <string.h>
-
-#include "py/mpstate.h"
-#include "lib/fatfs/ff.h"
-#include "lib/fatfs/ffconf.h"
-#include "lib/fatfs/diskio.h"
-#include "moduos.h"
-
-#if _FS_RPATH
-extern BYTE ff_CurrVol;
-#endif
-
-STATIC bool check_path(const TCHAR **path, const char *mount_point_str, mp_uint_t mount_point_len) {
- if (strncmp(*path, mount_point_str, mount_point_len) == 0) {
- if ((*path)[mount_point_len] == '/') {
- *path += mount_point_len;
- return true;
- } else if ((*path)[mount_point_len] == '\0') {
- *path = "/";
- return true;
- }
- }
- return false;
-}
-
-// "path" is the path to lookup; will advance this pointer beyond the volume name.
-// Returns logical drive number (-1 means invalid path).
-int ff_get_ldnumber (const TCHAR **path) {
- if (!(*path)) {
- return -1;
- }
-
- if (**path != '/') {
- #if _FS_RPATH
- return ff_CurrVol;
- #else
- return -1;
- #endif
- }
-
- if (check_path(path, "/flash", 6)) {
- return PD_FLASH;
- }
- else {
- for (mp_uint_t i = 0; i < MP_STATE_PORT(mount_obj_list).len; i++) {
- os_fs_mount_t *mount_obj = ((os_fs_mount_t *)(MP_STATE_PORT(mount_obj_list).items[i]));
- if (check_path(path, mount_obj->path, mount_obj->pathlen)) {
- return mount_obj->vol;
- }
- }
- }
-
- return -1;
-}
-
-void ff_get_volname(BYTE vol, TCHAR **dest) {
- if (vol == PD_FLASH) {
- memcpy(*dest, "/flash", 6);
- *dest += 6;
- } else {
- os_fs_mount_t *mount_obj;
- if ((mount_obj = osmount_find_by_volume(vol))) {
- memcpy(*dest, mount_obj->path, mount_obj->pathlen);
- *dest += mount_obj->pathlen;
- }
- }
-}
diff --git a/cc3200/fatfs/src/option/syscall.c b/cc3200/fatfs/src/option/syscall.c
deleted file mode 100644
index 1ada97bd4..000000000
--- a/cc3200/fatfs/src/option/syscall.c
+++ /dev/null
@@ -1,150 +0,0 @@
-/*------------------------------------------------------------------------*/
-/* Sample code of OS dependent controls for FatFs */
-/* (C)ChaN, 2014 */
-/*------------------------------------------------------------------------*/
-
-#include "ff.h"
-
-
-#if _FS_REENTRANT
-/*------------------------------------------------------------------------*/
-/* Create a Synchronization Object */
-/*------------------------------------------------------------------------*/
-/* This function is called in f_mount() function to create a new
-/ synchronization object, such as semaphore and mutex. When a 0 is returned,
-/ the f_mount() function fails with FR_INT_ERR.
-*/
-
-int ff_cre_syncobj ( /* !=0:Function succeeded, ==0:Could not create due to any error */
- BYTE vol, /* Corresponding logical drive being processed */
- _SYNC_t *sobj /* Pointer to return the created sync object */
-)
-{
- int ret;
-
-//
-// *sobj = CreateMutex(NULL, FALSE, NULL); /* Win32 */
-// ret = (int)(*sobj != INVALID_HANDLE_VALUE);
-
-// *sobj = SyncObjects[vol]; /* uITRON (give a static created sync object) */
-// ret = 1; /* The initial value of the semaphore must be 1. */
-
-// *sobj = OSMutexCreate(0, &err); /* uC/OS-II */
-// ret = (int)(err == OS_NO_ERR);
-
- vSemaphoreCreateBinary( (*sobj) ); /* FreeRTOS */
- ret = (int)(*sobj != NULL);
-
- return ret;
-}
-
-
-
-/*------------------------------------------------------------------------*/
-/* Delete a Synchronization Object */
-/*------------------------------------------------------------------------*/
-/* This function is called in f_mount() function to delete a synchronization
-/ object that created with ff_cre_syncobj function. When a 0 is returned,
-/ the f_mount() function fails with FR_INT_ERR.
-*/
-
-int ff_del_syncobj ( /* !=0:Function succeeded, ==0:Could not delete due to any error */
- _SYNC_t sobj /* Sync object tied to the logical drive to be deleted */
-)
-{
- int ret;
-
-
-// ret = CloseHandle(sobj); /* Win32 */
-
-// ret = 1; /* uITRON (nothing to do) */
-
-// OSMutexDel(sobj, OS_DEL_ALWAYS, &err); /* uC/OS-II */
-// ret = (int)(err == OS_NO_ERR);
-
- vSemaphoreDelete(sobj); /* FreeRTOS */
- ret = 1;
-
- return ret;
-}
-
-
-
-/*------------------------------------------------------------------------*/
-/* Request Grant to Access the Volume */
-/*------------------------------------------------------------------------*/
-/* This function is called on entering file functions to lock the volume.
-/ When a 0 is returned, the file function fails with FR_TIMEOUT.
-*/
-
-int ff_req_grant ( /* 1:Got a grant to access the volume, 0:Could not get a grant */
- _SYNC_t sobj /* Sync object to wait */
-)
-{
- int ret;
-
-// ret = (int)(WaitForSingleObject(sobj, _FS_TIMEOUT) == WAIT_OBJECT_0); /* Win32 */
-
-// ret = (int)(wai_sem(sobj) == E_OK); /* uITRON */
-
-// OSMutexPend(sobj, _FS_TIMEOUT, &err)); /* uC/OS-II */
-// ret = (int)(err == OS_NO_ERR);
-
- ret = (int)(xSemaphoreTake(sobj, _FS_TIMEOUT) == pdTRUE); /* FreeRTOS */
-
- return ret;
-}
-
-
-
-/*------------------------------------------------------------------------*/
-/* Release Grant to Access the Volume */
-/*------------------------------------------------------------------------*/
-/* This function is called on leaving file functions to unlock the volume.
-*/
-
-void ff_rel_grant (
- _SYNC_t sobj /* Sync object to be signaled */
-)
-{
-// ReleaseMutex(sobj); /* Win32 */
-
-// sig_sem(sobj); /* uITRON */
-
-// OSMutexPost(sobj); /* uC/OS-II */
-
- xSemaphoreGive(sobj); /* FreeRTOS */
-}
-
-#endif
-
-
-
-
-#if _USE_LFN == 3 /* LFN with a working buffer on the heap */
-/*------------------------------------------------------------------------*/
-/* Allocate a memory block */
-/*------------------------------------------------------------------------*/
-/* If a NULL is returned, the file function fails with FR_NOT_ENOUGH_CORE.
-*/
-
-void* ff_memalloc ( /* Returns pointer to the allocated memory block */
- UINT msize /* Number of bytes to allocate */
-)
-{
- return pvPortMalloc(msize); /* Allocate a new memory block with POSIX API */
-}
-
-
-/*------------------------------------------------------------------------*/
-/* Free a memory block */
-/*------------------------------------------------------------------------*/
-
-void ff_memfree (
- void* mblock /* Pointer to the memory block to free */
-)
-{
- vPortFree(mblock); /* Discard the memory block with POSIX API */
-}
-
-#endif
diff --git a/cc3200/fatfs_port.c b/cc3200/fatfs_port.c
new file mode 100644
index 000000000..658c94e88
--- /dev/null
+++ b/cc3200/fatfs_port.c
@@ -0,0 +1,74 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2013-2017 Damien P. George
+ * Parts of this file are (C)ChaN, 2014, from FatFs option/syscall.c
+ *
+ * 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 "py/runtime.h"
+#include "lib/oofatfs/ff.h"
+#include "lib/timeutils/timeutils.h"
+#include "mods/pybrtc.h"
+
+#if _FS_REENTRANT
+// Create a Synchronization Object
+// This function is called in f_mount() function to create a new
+// synchronization object, such as semaphore and mutex.
+// A return of 0 indicates failure, and then f_mount() fails with FR_INT_ERR.
+int ff_cre_syncobj(FATFS *fatfs, _SYNC_t *sobj) {
+ vSemaphoreCreateBinary((*sobj));
+ return (int)(*sobj != NULL);
+}
+
+// Delete a Synchronization Object
+// This function is called in f_mount() function to delete a synchronization
+// object that created with ff_cre_syncobj function.
+// A return of 0 indicates failure, and then f_mount() fails with FR_INT_ERR.
+int ff_del_syncobj(_SYNC_t sobj) {
+ vSemaphoreDelete(sobj);
+ return 1;
+}
+
+// Request Grant to Access the Volume
+// This function is called on entering file functions to lock the volume.
+// When a 0 is returned, the file function fails with FR_TIMEOUT.
+int ff_req_grant(_SYNC_t sobj) {
+ return (int)(xSemaphoreTake(sobj, _FS_TIMEOUT) == pdTRUE);
+}
+
+// Release Grant to Access the Volume
+// This function is called on leaving file functions to unlock the volume.
+void ff_rel_grant(_SYNC_t sobj) {
+ xSemaphoreGive(sobj);
+}
+
+#endif
+
+DWORD get_fattime(void) {
+ timeutils_struct_time_t tm;
+ timeutils_seconds_since_2000_to_struct_time(pyb_rtc_get_seconds(), &tm);
+
+ return ((tm.tm_year - 1980) << 25) | ((tm.tm_mon) << 21) |
+ ((tm.tm_mday) << 16) | ((tm.tm_hour) << 11) |
+ ((tm.tm_min) << 5) | (tm.tm_sec >> 1);
+}
diff --git a/cc3200/ftp/ftp.c b/cc3200/ftp/ftp.c
index 252a3d756..1febe291f 100644
--- a/cc3200/ftp/ftp.c
+++ b/cc3200/ftp/ftp.c
@@ -25,11 +25,14 @@
*/
#include <stdint.h>
-#include <ctype.h>
-#include "std.h"
+#include <stdio.h>
#include "py/mpstate.h"
#include "py/obj.h"
+#include "lib/timeutils/timeutils.h"
+#include "lib/oofatfs/ff.h"
+#include "extmod/vfs.h"
+#include "extmod/vfs_fat.h"
#include "inc/hw_types.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
@@ -43,11 +46,9 @@
#include "modusocket.h"
#include "debug.h"
#include "serverstask.h"
-#include "ff.h"
#include "fifo.h"
#include "socketfifo.h"
#include "updater.h"
-#include "timeutils.h"
#include "moduos.h"
/******************************************************************************
@@ -115,7 +116,7 @@ typedef struct {
uint8_t *dBuffer;
uint32_t ctimeout;
union {
- DIR dp;
+ FF_DIR dp;
FIL fp;
};
int16_t lc_sd;
@@ -193,6 +194,80 @@ static SocketFifoElement_t ftp_fifoelements[FTP_SOCKETFIFO_ELEMENTS_MAX];
static FIFO_t ftp_socketfifo;
/******************************************************************************
+ DEFINE VFS WRAPPER FUNCTIONS
+ ******************************************************************************/
+
+// These wrapper functions are used so that the FTP server can access the
+// mounted FATFS devices directly without going through the costly mp_vfs_XXX
+// functions. The latter may raise exceptions and we would then need to wrap
+// all calls in an nlr handler. The wrapper functions below assume that there
+// are only FATFS filesystems mounted.
+
+STATIC FATFS *lookup_path(const TCHAR **path) {
+ mp_vfs_mount_t *fs = mp_vfs_lookup_path(*path, path);
+ if (fs == MP_VFS_NONE || fs == MP_VFS_ROOT) {
+ return NULL;
+ }
+ // here we assume that the mounted device is FATFS
+ return &((fs_user_mount_t*)MP_OBJ_TO_PTR(fs->obj))->fatfs;
+}
+
+STATIC FRESULT f_open_helper(FIL *fp, const TCHAR *path, BYTE mode) {
+ FATFS *fs = lookup_path(&path);
+ if (fs == NULL) {
+ return FR_NO_PATH;
+ }
+ return f_open(fs, fp, path, mode);
+}
+
+STATIC FRESULT f_opendir_helper(FF_DIR *dp, const TCHAR *path) {
+ FATFS *fs = lookup_path(&path);
+ if (fs == NULL) {
+ return FR_NO_PATH;
+ }
+ return f_opendir(fs, dp, path);
+}
+
+STATIC FRESULT f_stat_helper(const TCHAR *path, FILINFO *fno) {
+ FATFS *fs = lookup_path(&path);
+ if (fs == NULL) {
+ return FR_NO_PATH;
+ }
+ return f_stat(fs, path, fno);
+}
+
+STATIC FRESULT f_mkdir_helper(const TCHAR *path) {
+ FATFS *fs = lookup_path(&path);
+ if (fs == NULL) {
+ return FR_NO_PATH;
+ }
+ return f_mkdir(fs, path);
+}
+
+STATIC FRESULT f_unlink_helper(const TCHAR *path) {
+ FATFS *fs = lookup_path(&path);
+ if (fs == NULL) {
+ return FR_NO_PATH;
+ }
+ return f_unlink(fs, path);
+}
+
+STATIC FRESULT f_rename_helper(const TCHAR *path_old, const TCHAR *path_new) {
+ FATFS *fs_old = lookup_path(&path_old);
+ if (fs_old == NULL) {
+ return FR_NO_PATH;
+ }
+ FATFS *fs_new = lookup_path(&path_new);
+ if (fs_new == NULL) {
+ return FR_NO_PATH;
+ }
+ if (fs_old != fs_new) {
+ return FR_NO_PATH;
+ }
+ return f_rename(fs_new, path_old, path_new);
+}
+
+/******************************************************************************
DECLARE PRIVATE FUNCTIONS
******************************************************************************/
static void ftp_wait_for_enabled (void);
@@ -210,7 +285,7 @@ static void ftp_close_cmd_data (void);
static ftp_cmd_index_t ftp_pop_command (char **str);
static void ftp_pop_param (char **str, char *param);
static int ftp_print_eplf_item (char *dest, uint32_t destsize, FILINFO *fno);
-static int ftp_print_eplf_drive (char *dest, uint32_t destsize, char *name);
+static int ftp_print_eplf_drive (char *dest, uint32_t destsize, const char *name);
static bool ftp_open_file (const char *path, int mode);
static ftp_result_t ftp_read_file (char *filebuf, uint32_t desiredsize, uint32_t *actualsize);
static ftp_result_t ftp_write_file (char *filebuf, uint32_t size);
@@ -424,12 +499,12 @@ static void ftp_wait_for_enabled (void) {
static bool ftp_create_listening_socket (_i16 *sd, _u16 port, _u8 backlog) {
SlSockNonblocking_t nonBlockingOption;
- sockaddr_in sServerAddress;
+ SlSockAddrIn_t sServerAddress;
_i16 _sd;
_i16 result;
// Open a socket for ftp data listen
- ASSERT ((*sd = sl_Socket(AF_INET, SOCK_STREAM, IPPROTO_IP)) > 0);
+ ASSERT ((*sd = sl_Socket(SL_AF_INET, SL_SOCK_STREAM, SL_IPPROTO_IP)) > 0);
_sd = *sd;
if (_sd > 0) {
@@ -438,12 +513,12 @@ static bool ftp_create_listening_socket (_i16 *sd, _u16 port, _u8 backlog) {
// Enable non-blocking mode
nonBlockingOption.NonblockingEnabled = 1;
- ASSERT ((result = sl_SetSockOpt(_sd, SOL_SOCKET, SL_SO_NONBLOCKING, &nonBlockingOption, sizeof(nonBlockingOption))) == SL_SOC_OK);
+ ASSERT ((result = sl_SetSockOpt(_sd, SL_SOL_SOCKET, SL_SO_NONBLOCKING, &nonBlockingOption, sizeof(nonBlockingOption))) == SL_SOC_OK);
// Bind the socket to a port number
- sServerAddress.sin_family = AF_INET;
- sServerAddress.sin_addr.s_addr = INADDR_ANY;
- sServerAddress.sin_port = htons(port);
+ sServerAddress.sin_family = SL_AF_INET;
+ sServerAddress.sin_addr.s_addr = SL_INADDR_ANY;
+ sServerAddress.sin_port = sl_Htons(port);
ASSERT ((result |= sl_Bind(_sd, (const SlSockAddr_t *)&sServerAddress, sizeof(sServerAddress))) == SL_SOC_OK);
@@ -459,7 +534,7 @@ static bool ftp_create_listening_socket (_i16 *sd, _u16 port, _u8 backlog) {
}
static ftp_result_t ftp_wait_for_connection (_i16 l_sd, _i16 *n_sd) {
- sockaddr_in sClientAddress;
+ SlSockAddrIn_t sClientAddress;
SlSocklen_t in_addrSize;
// accepts a connection from a TCP client, if there is any, otherwise returns SL_EAGAIN
@@ -604,10 +679,6 @@ static void ftp_process_cmd (void) {
ftp_result_t result;
FRESULT fres;
FILINFO fno;
-#if _USE_LFN
- fno.lfname = NULL;
- fno.lfsize = 0;
-#endif
ftp_data.closechild = false;
// also use the reply buffer to receive new commands
@@ -634,7 +705,7 @@ static void ftp_process_cmd (void) {
fres = FR_NO_PATH;
ftp_pop_param (&bufptr, ftp_scratch_buffer);
ftp_open_child (ftp_path, ftp_scratch_buffer);
- if ((ftp_path[0] == '/' && ftp_path[1] == '\0') || ((fres = f_opendir (&ftp_data.dp, ftp_path)) == FR_OK)) {
+ if ((ftp_path[0] == '/' && ftp_path[1] == '\0') || ((fres = f_opendir_helper (&ftp_data.dp, ftp_path)) == FR_OK)) {
if (fres == FR_OK) {
f_closedir(&ftp_data.dp);
}
@@ -653,7 +724,7 @@ static void ftp_process_cmd (void) {
case E_FTP_CMD_SIZE:
{
ftp_get_param_and_open_child (&bufptr);
- if (FR_OK == f_stat (ftp_path, &fno)) {
+ if (FR_OK == f_stat_helper(ftp_path, &fno)) {
// send the size
snprintf((char *)ftp_data.dBuffer, FTP_BUFFER_SIZE, "%u", (_u32)fno.fsize);
ftp_send_reply(213, (char *)ftp_data.dBuffer);
@@ -665,7 +736,7 @@ static void ftp_process_cmd (void) {
break;
case E_FTP_CMD_MDTM:
ftp_get_param_and_open_child (&bufptr);
- if (FR_OK == f_stat (ftp_path, &fno)) {
+ if (FR_OK == f_stat_helper(ftp_path, &fno)) {
// send the last modified time
snprintf((char *)ftp_data.dBuffer, FTP_BUFFER_SIZE, "%u%02u%02u%02u%02u%02u",
1980 + ((fno.fdate >> 9) & 0x7f), (fno.fdate >> 5) & 0x0f,
@@ -773,7 +844,7 @@ static void ftp_process_cmd (void) {
case E_FTP_CMD_DELE:
case E_FTP_CMD_RMD:
ftp_get_param_and_open_child (&bufptr);
- if (FR_OK == f_unlink(ftp_path)) {
+ if (FR_OK == f_unlink_helper(ftp_path)) {
ftp_send_reply(250, NULL);
}
else {
@@ -782,7 +853,7 @@ static void ftp_process_cmd (void) {
break;
case E_FTP_CMD_MKD:
ftp_get_param_and_open_child (&bufptr);
- if (FR_OK == f_mkdir(ftp_path)) {
+ if (FR_OK == f_mkdir_helper(ftp_path)) {
ftp_send_reply(250, NULL);
}
else {
@@ -791,7 +862,7 @@ static void ftp_process_cmd (void) {
break;
case E_FTP_CMD_RNFR:
ftp_get_param_and_open_child (&bufptr);
- if (FR_OK == f_stat (ftp_path, &fno)) {
+ if (FR_OK == f_stat_helper(ftp_path, &fno)) {
ftp_send_reply(350, NULL);
// save the current path
strcpy ((char *)ftp_data.dBuffer, ftp_path);
@@ -803,7 +874,7 @@ static void ftp_process_cmd (void) {
case E_FTP_CMD_RNTO:
ftp_get_param_and_open_child (&bufptr);
// old path was saved in the data buffer
- if (FR_OK == (fres = f_rename ((char *)ftp_data.dBuffer, ftp_path))) {
+ if (FR_OK == (fres = f_rename_helper((char *)ftp_data.dBuffer, ftp_path))) {
ftp_send_reply(250, NULL);
}
else {
@@ -860,6 +931,13 @@ static void ftp_close_cmd_data (void) {
ftp_close_filesystem_on_error ();
}
+static void stoupper (char *str) {
+ while (str && *str != '\0') {
+ *str = (char)unichar_toupper((int)(*str));
+ str++;
+ }
+}
+
static ftp_cmd_index_t ftp_pop_command (char **str) {
char _cmd[FTP_CMD_SIZE_MAX];
ftp_pop_param (str, _cmd);
@@ -898,24 +976,16 @@ static int ftp_print_eplf_item (char *dest, uint32_t destsize, FILINFO *fno) {
if (FTP_UNIX_SECONDS_180_DAYS < tseconds - fseconds) {
return snprintf(dest, destsize, "%srw-rw-r-- 1 root root %9u %s %2u %5u %s\r\n",
type, (_u32)fno->fsize, ftp_month[mindex].month, day,
- #if _USE_LFN
- 1980 + ((fno->fdate >> 9) & 0x7f), *fno->lfname ? fno->lfname : fno->fname);
- #else
1980 + ((fno->fdate >> 9) & 0x7f), fno->fname);
- #endif
}
else {
return snprintf(dest, destsize, "%srw-rw-r-- 1 root root %9u %s %2u %02u:%02u %s\r\n",
type, (_u32)fno->fsize, ftp_month[mindex].month, day,
- #if _USE_LFN
- (fno->ftime >> 11) & 0x1f, (fno->ftime >> 5) & 0x3f, *fno->lfname ? fno->lfname : fno->fname);
- #else
(fno->ftime >> 11) & 0x1f, (fno->ftime >> 5) & 0x3f, fno->fname);
- #endif
}
}
-static int ftp_print_eplf_drive (char *dest, uint32_t destsize, char *name) {
+static int ftp_print_eplf_drive (char *dest, uint32_t destsize, const char *name) {
timeutils_struct_time_t tm;
uint32_t tseconds;
char *type = "d";
@@ -934,7 +1004,7 @@ static int ftp_print_eplf_drive (char *dest, uint32_t destsize, char *name) {
}
static bool ftp_open_file (const char *path, int mode) {
- FRESULT res = f_open(&ftp_data.fp, path, mode);
+ FRESULT res = f_open_helper(&ftp_data.fp, path, mode);
if (res != FR_OK) {
return false;
}
@@ -976,7 +1046,7 @@ static ftp_result_t ftp_open_dir_for_listing (const char *path) {
ftp_data.listroot = true;
} else {
FRESULT res;
- res = f_opendir(&ftp_data.dp, path); /* Open the directory */
+ res = f_opendir_helper(&ftp_data.dp, path); /* Open the directory */
if (res != FR_OK) {
return E_FTP_RESULT_FAILED;
}
@@ -993,9 +1063,6 @@ static ftp_result_t ftp_list_dir (char *list, uint32_t maxlistsize, uint32_t *li
ftp_result_t result = E_FTP_RESULT_CONTINUE;
FILINFO fno;
#if _USE_LFN
- fno.lfname = mem_Malloc(_MAX_LFN);
- fno.lfsize = _MAX_LFN;
-
// read up to 2 directory items
while (listcount < 2) {
#else
@@ -1004,17 +1071,20 @@ static ftp_result_t ftp_list_dir (char *list, uint32_t maxlistsize, uint32_t *li
#endif
if (ftp_data.listroot) {
// root directory "hack"
- if (0 == ftp_data.volcount) {
- next += ftp_print_eplf_drive((list + next), (maxlistsize - next), "flash");
- } else if (ftp_data.volcount <= MP_STATE_PORT(mount_obj_list).len) {
- os_fs_mount_t *mount_obj = ((os_fs_mount_t *)(MP_STATE_PORT(mount_obj_list).items[(ftp_data.volcount - 1)]));
- next += ftp_print_eplf_drive((list + next), (maxlistsize - next), (char *)&mount_obj->path[1]);
- } else {
+ mp_vfs_mount_t *vfs = MP_STATE_VM(vfs_mount_table);
+ int i = ftp_data.volcount;
+ while (vfs != NULL && i != 0) {
+ vfs = vfs->next;
+ i -= 1;
+ }
+ if (vfs == NULL) {
if (!next) {
// no volume found this time, we are done
ftp_data.volcount = 0;
}
break;
+ } else {
+ next += ftp_print_eplf_drive((list + next), (maxlistsize - next), vfs->str + 1);
}
ftp_data.volcount++;
} else {
@@ -1036,9 +1106,6 @@ static ftp_result_t ftp_list_dir (char *list, uint32_t maxlistsize, uint32_t *li
ftp_close_files();
}
*listsize = next;
-#if _USE_LFN
- mem_Free(fno.lfname);
-#endif
return result;
}
diff --git a/cc3200/hal/cc3200_hal.c b/cc3200/hal/cc3200_hal.c
index 37026db14..5c0e9c30f 100644
--- a/cc3200/hal/cc3200_hal.c
+++ b/cc3200/hal/cc3200_hal.c
@@ -108,6 +108,19 @@ mp_uint_t mp_hal_ticks_ms(void) {
return HAL_tickCount;
}
+// The SysTick timer counts down at HAL_FCPU_HZ, so we can use that knowledge
+// to grab a microsecond counter.
+mp_uint_t mp_hal_ticks_us(void) {
+ mp_uint_t irq_state = disable_irq();
+ uint32_t counter = SysTickValueGet();
+ uint32_t milliseconds = mp_hal_ticks_ms();
+ enable_irq(irq_state);
+
+ uint32_t load = SysTickPeriodGet();
+ counter = load - counter; // Convert from decrementing to incrementing
+ return (milliseconds * 1000) + ((counter * 1000) / load);
+}
+
void mp_hal_delay_ms(mp_uint_t delay) {
// only if we are not within interrupt context and interrupts are enabled
if ((HAL_NVIC_INT_CTRL_REG & HAL_VECTACTIVE_MASK) == 0 && query_irq() == IRQ_STATE_ENABLED) {
@@ -211,4 +224,3 @@ static void hal_TickInit (void) {
MAP_SysTickEnable();
}
#endif
-
diff --git a/cc3200/hal/cc3200_hal.h b/cc3200/hal/cc3200_hal.h
index 9715096b6..fcb85b292 100644
--- a/cc3200/hal/cc3200_hal.h
+++ b/cc3200/hal/cc3200_hal.h
@@ -30,6 +30,9 @@
#include <stdint.h>
#include <stdbool.h>
+#include "hal/utils.h"
+#include "hal/systick.h"
+
/******************************************************************************
DEFINE CONSTANTS
******************************************************************************/
@@ -64,4 +67,7 @@ extern void HAL_SystemDeInit (void);
extern void HAL_IncrementTick(void);
extern void mp_hal_set_interrupt_char (int c);
+#define mp_hal_delay_us(usec) UtilsDelay(UTILS_DELAY_US_TO_COUNT(usec))
+#define mp_hal_ticks_cpu() (SysTickPeriodGet() - SysTickValueGet())
+
#endif /* CC3200_LAUNCHXL_HAL_CC3200_HAL_H_ */
diff --git a/cc3200/main.c b/cc3200/main.c
index 06b3604b6..7c6c4b545 100644
--- a/cc3200/main.c
+++ b/cc3200/main.c
@@ -98,13 +98,6 @@ int main (void) {
for ( ; ; );
}
-void stoupper (char *str) {
- while (str && *str != '\0') {
- *str = (char)toupper((int)(*str));
- str++;
- }
-}
-
// We need this when configSUPPORT_STATIC_ALLOCATION is enabled
void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer,
StackType_t **ppxIdleTaskStackBuffer,
diff --git a/cc3200/misc/help.c b/cc3200/misc/help.c
index 4601818bd..cce515898 100644
--- a/cc3200/misc/help.c
+++ b/cc3200/misc/help.c
@@ -25,23 +25,8 @@
* THE SOFTWARE.
*/
-#include <stdio.h>
+#include "py/builtin.h"
-#include "lib/utils/pyhelp.h"
-
-STATIC const char help_text[] = "Welcome to MicroPython!\n"
+const char *cc3200_help_text = "Welcome to MicroPython!\n"
"For online help please visit http://micropython.org/help/.\n"
"For further help on a specific object, type help(obj)\n";
-
-STATIC mp_obj_t pyb_help(uint n_args, const mp_obj_t *args) {
- if (n_args == 0) {
- // print a general help message
- printf("%s", help_text);
- }
- else {
- // try to print something sensible about the given object
- pyhelp_print_obj(args[0]);
- }
- return mp_const_none;
-}
-MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_help_obj, 0, 1, pyb_help);
diff --git a/cc3200/misc/mpexception.c b/cc3200/misc/mpexception.c
index c45f0244b..068adb70b 100644
--- a/cc3200/misc/mpexception.c
+++ b/cc3200/misc/mpexception.c
@@ -40,9 +40,6 @@ STATIC void mpexception_set_user_interrupt (int chr, void *data);
/******************************************************************************
DECLARE EXPORTED DATA
******************************************************************************/
-const char mpexception_os_resource_not_avaliable[] = "resource not available";
-const char mpexception_os_operation_failed[] = "the requested operation failed";
-const char mpexception_os_request_not_possible[] = "the requested operation is not possible";
const char mpexception_value_invalid_arguments[] = "invalid argument(s) value";
const char mpexception_num_type_invalid_arguments[] = "invalid argument(s) num/type";
const char mpexception_uncaught[] = "uncaught exception";
diff --git a/cc3200/misc/mpexception.h b/cc3200/misc/mpexception.h
index f55aa739e..2f9d1877c 100644
--- a/cc3200/misc/mpexception.h
+++ b/cc3200/misc/mpexception.h
@@ -28,9 +28,6 @@
#ifndef MPEXCEPTION_H_
#define MPEXCEPTION_H_
-extern const char mpexception_os_resource_not_avaliable[];
-extern const char mpexception_os_operation_failed[];
-extern const char mpexception_os_request_not_possible[];
extern const char mpexception_value_invalid_arguments[];
extern const char mpexception_num_type_invalid_arguments[];
extern const char mpexception_uncaught[];
diff --git a/cc3200/misc/mpirq.c b/cc3200/misc/mpirq.c
index be5746759..37149089f 100644
--- a/cc3200/misc/mpirq.c
+++ b/cc3200/misc/mpirq.c
@@ -24,7 +24,7 @@
* THE SOFTWARE.
*/
-#include "std.h"
+#include <stdio.h>
#include "py/mpconfig.h"
#include "py/obj.h"
diff --git a/cc3200/misc/mpsystick.c b/cc3200/misc/mpsystick.c
deleted file mode 100644
index 7c35354e1..000000000
--- a/cc3200/misc/mpsystick.c
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * 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 "py/mpconfig.h"
-#include "py/obj.h"
-#include "py/mphal.h"
-#include "mpsystick.h"
-#include "systick.h"
-#include "inc/hw_types.h"
-#include "inc/hw_nvic.h"
-
-#ifdef USE_FREERTOS
-#include "FreeRTOS.h"
-#include "task.h"
-#endif
-
-
-bool sys_tick_has_passed(uint32_t start_tick, uint32_t delay_ms) {
- return mp_hal_ticks_ms() - start_tick >= delay_ms;
-}
-
-// waits until at least delay_ms milliseconds have passed from the sampling of
-// startTick. Handles overflow properly. Assumes stc was taken from
-// mp_hal_ticks_ms() some time before calling this function.
-void sys_tick_wait_at_least(uint32_t start_tick, uint32_t delay_ms) {
-#ifdef USE_FREERTOS
- vTaskDelay (delay_ms / portTICK_PERIOD_MS);
-#else
- while (!sys_tick_has_passed(start_tick, delay_ms)) {
- __WFI(); // enter sleep mode, waiting for interrupt
- }
-#endif
-}
-
-// The SysTick timer counts down at HAL_FCPU_HZ, so we can use that knowledge
-// to grab a microsecond counter.
-// We assume that mp_hal_ticks_ms returns milliseconds.
-uint32_t sys_tick_get_microseconds(void) {
- mp_uint_t irq_state = disable_irq();
- uint32_t counter = SysTickValueGet();
- uint32_t milliseconds = mp_hal_ticks_ms();
- enable_irq(irq_state);
-
- uint32_t load = SysTickPeriodGet();
- counter = load - counter; // Convert from decrementing to incrementing
- return (milliseconds * 1000) + ((counter * 1000) / load);
-}
diff --git a/cc3200/mods/modmachine.c b/cc3200/mods/modmachine.c
index 8a57c2eb4..fd1485607 100644
--- a/cc3200/mods/modmachine.c
+++ b/cc3200/mods/modmachine.c
@@ -26,7 +26,6 @@
*/
#include <stdint.h>
-#include "std.h"
#include "py/mpstate.h"
#include "py/runtime.h"
@@ -112,10 +111,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_info_obj, 0, 1, machine_info)
#endif
STATIC mp_obj_t machine_freq(void) {
- mp_obj_t tuple[1] = {
- mp_obj_new_int(HAL_FCPU_HZ),
- };
- return mp_obj_new_tuple(1, tuple);
+ return mp_obj_new_int(HAL_FCPU_HZ);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_freq_obj, machine_freq);
diff --git a/cc3200/mods/modnetwork.c b/cc3200/mods/modnetwork.c
index 89d61e939..d44f75aca 100644
--- a/cc3200/mods/modnetwork.c
+++ b/cc3200/mods/modnetwork.c
@@ -25,12 +25,11 @@
* THE SOFTWARE.
*/
-#include <std.h>
-
#include "py/mpstate.h"
#include "py/obj.h"
#include "py/nlr.h"
#include "py/runtime.h"
+#include "py/mperrno.h"
#include "py/mphal.h"
#include "modnetwork.h"
#include "mpexception.h"
@@ -101,7 +100,7 @@ STATIC mp_obj_t network_server_make_new(const mp_obj_type_t *type, size_t n_args
// check the server id
if (args[0].u_obj != MP_OBJ_NULL) {
if (mp_obj_get_int(args[0].u_obj) != 0) {
- mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable);
+ mp_raise_OSError(MP_ENODEV);
}
}
diff --git a/cc3200/mods/moduhashlib.c b/cc3200/mods/moduhashlib.c
index c22cc8a06..e1145e4d8 100644
--- a/cc3200/mods/moduhashlib.c
+++ b/cc3200/mods/moduhashlib.c
@@ -93,7 +93,7 @@ STATIC void hash_update_internal(mp_obj_t self_in, mp_obj_t data, bool digest) {
self->digested = false;
}
} else {
- mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible);
+ mp_raise_OSError(MP_EPERM);
}
}
@@ -106,7 +106,7 @@ STATIC mp_obj_t hash_read (mp_obj_t self_in) {
}
} else if (self->c_size < self->b_size) {
// it's a fixed len block which is still incomplete
- mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible);
+ mp_raise_OSError(MP_EPERM);
}
if (!self->digested) {
diff --git a/cc3200/mods/moduos.c b/cc3200/mods/moduos.c
index ffe2b551a..ed8879bf3 100644
--- a/cc3200/mods/moduos.c
+++ b/cc3200/mods/moduos.c
@@ -33,15 +33,17 @@
#include "py/objtuple.h"
#include "py/objstr.h"
#include "py/runtime.h"
+#include "lib/timeutils/timeutils.h"
+#include "lib/oofatfs/ff.h"
+#include "lib/oofatfs/diskio.h"
#include "genhdr/mpversion.h"
#include "moduos.h"
-#include "diskio.h"
#include "sflash_diskio.h"
-#include "extmod/vfs_fat_file.h"
+#include "extmod/vfs.h"
+#include "extmod/vfs_fat.h"
#include "random.h"
#include "mpexception.h"
#include "version.h"
-#include "timeutils.h"
#include "pybsd.h"
#include "pybuart.h"
@@ -59,155 +61,20 @@
/******************************************************************************
DECLARE PRIVATE DATA
******************************************************************************/
-STATIC uint32_t os_num_mounted_devices;
STATIC os_term_dup_obj_t os_term_dup_obj;
/******************************************************************************
- DECLARE PRIVATE FUNCTIONS
- ******************************************************************************/
-STATIC void unmount (os_fs_mount_t *mount_obj);
-STATIC bool path_equal(const char *path, const char *path_canonical);
-STATIC void append_dir_item (mp_obj_t dirlist, const char *item, bool string);
-STATIC void mount (mp_obj_t device, const char *path, uint pathlen, bool readonly);
-
-/******************************************************************************
DEFINE PUBLIC FUNCTIONS
******************************************************************************/
-void moduos_init0 (void) {
- // initialize the mount objects list
- mp_obj_list_init(&MP_STATE_PORT(mount_obj_list), 0);
- os_num_mounted_devices = 0;
-}
-
-os_fs_mount_t *osmount_find_by_path (const char *path) {
- for (mp_uint_t i = 0; i < MP_STATE_PORT(mount_obj_list).len; i++) {
- os_fs_mount_t *mount_obj = ((os_fs_mount_t *)(MP_STATE_PORT(mount_obj_list).items[i]));
- if (!strcmp(path, mount_obj->path)) {
- return mount_obj;
- }
- }
- return NULL;
-}
-
-os_fs_mount_t *osmount_find_by_volume (uint8_t vol) {
- for (mp_uint_t i = 0; i < MP_STATE_PORT(mount_obj_list).len; i++) {
- os_fs_mount_t *mount_obj = ((os_fs_mount_t *)(MP_STATE_PORT(mount_obj_list).items[i]));
- if (vol == mount_obj->vol) {
- return mount_obj;
- }
- }
- return NULL;
-}
-
-os_fs_mount_t *osmount_find_by_device (mp_obj_t device) {
- for (mp_uint_t i = 0; i < MP_STATE_PORT(mount_obj_list).len; i++) {
- os_fs_mount_t *mount_obj = ((os_fs_mount_t *)(MP_STATE_PORT(mount_obj_list).items[i]));
- if (device == mount_obj->device) {
- return mount_obj;
- }
- }
- return NULL;
-}
-
void osmount_unmount_all (void) {
+ //TODO
+ /*
for (mp_uint_t i = 0; i < MP_STATE_PORT(mount_obj_list).len; i++) {
os_fs_mount_t *mount_obj = ((os_fs_mount_t *)(MP_STATE_PORT(mount_obj_list).items[i]));
unmount(mount_obj);
}
-}
-
-/******************************************************************************
- DEFINE PRIVATE FUNCTIONS
- ******************************************************************************/
-
-// Checks for path equality, ignoring trailing slashes:
-// path_equal(/, /) -> true
-// path_equal(/flash//, /flash) -> true
-// second argument must be in canonical form (meaning no trailing slash, unless it's just /)
-STATIC bool path_equal(const char *path, const char *path_canonical) {
- for (; *path_canonical != '\0' && *path == *path_canonical; ++path, ++path_canonical) {
- }
- if (*path_canonical != '\0') {
- return false;
- }
- for (; *path == '/'; ++path) {
- }
- return *path == '\0';
-}
-
-STATIC void append_dir_item (mp_obj_t dirlist, const char *item, bool string) {
- // make a string object for this entry
- mp_obj_t entry_o;
- if (string) {
- entry_o = mp_obj_new_str(item, strlen(item), false);
- } else {
- entry_o = mp_obj_new_bytes((const byte*)item, strlen(item));
- }
-
- // add the entry to the list
- mp_obj_list_append(dirlist, entry_o);
-}
-
-STATIC void mount (mp_obj_t device, const char *path, uint pathlen, bool readonly) {
- // is the mount point already in use?
- FILINFO fno;
-#if _USE_LFN
- fno.lfname = NULL;
- fno.lfsize = 0;
-#endif
- // cannot mount twice or on existing paths
- if (f_stat(path, &fno) == FR_OK || osmount_find_by_device(device)) {
- mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible);
- }
-
- // create a new object
- os_fs_mount_t *self = m_new_obj(os_fs_mount_t);
- self->device = device;
- self->path = path;
- self->pathlen = pathlen;
- self->vol = os_num_mounted_devices + 1; // '/flash' is volume 0
-
- if (device == (mp_obj_t)&pybsd_obj) {
- // need to make it different to NULL, otherwise it's read only by default
- self->writeblocks[0] = mp_const_none;
- self->sync[0] = MP_OBJ_NULL; // no need to sync the SD card
- self->count[0] = MP_OBJ_NULL;
- } else {
- // load block protocol methods
- mp_load_method(device, MP_QSTR_readblocks, self->readblocks);
- mp_load_method_maybe(device, MP_QSTR_writeblocks, self->writeblocks);
- mp_load_method_maybe(device, MP_QSTR_sync, self->sync);
- mp_load_method(device, MP_QSTR_count, self->count);
- }
-
- // Read-only device indicated by writeblocks[0] == MP_OBJ_NULL.
- // User can specify read-only device by:
- // 1. readonly=True keyword argument
- // 2. nonexistent writeblocks method (then writeblocks[0] == MP_OBJ_NULL already)
- if (readonly) {
- self->writeblocks[0] = MP_OBJ_NULL;
- }
-
- // we need to add it before doing the actual mount, so that the volume can be found
- mp_obj_list_append(&MP_STATE_PORT(mount_obj_list), self);
-
- // actually mount it
- if (f_mount(&self->fatfs, self->path, 1) != FR_OK) {
- // remove it and raise
- mp_obj_list_remove(&MP_STATE_PORT(mount_obj_list), self);
- mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed);
- }
-
- // mount succeeded, increment the count
- os_num_mounted_devices++;
-}
-
-STATIC void unmount (os_fs_mount_t *mount_obj) {
- // remove it from the list and then call FatFs
- f_mount (NULL, mount_obj->path, 1);
- mp_obj_list_remove(&MP_STATE_PORT(mount_obj_list), mount_obj);
- os_num_mounted_devices--;
+ */
}
/******************************************************************************/
@@ -239,193 +106,6 @@ STATIC mp_obj_t os_uname(void) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(os_uname_obj, os_uname);
-/// \function chdir(path)
-/// Change current directory.
-STATIC mp_obj_t os_chdir(mp_obj_t path_in) {
- const char *path;
- path = mp_obj_str_get_str(path_in);
-
- FRESULT res = f_chdrive(path);
-
- if (res == FR_OK) {
- res = f_chdir(path);
- }
-
- if (res != FR_OK) {
- mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed);
- }
-
- return mp_const_none;
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_chdir_obj, os_chdir);
-
-STATIC mp_obj_t os_getcwd(void) {
- char buf[MICROPY_ALLOC_PATH_MAX + 1];
- FRESULT res = f_getcwd(buf, sizeof buf);
- if (res != FR_OK) {
- mp_raise_OSError(fresult_to_errno_table[res]);
- }
- return mp_obj_new_str(buf, strlen(buf), false);
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_0(os_getcwd_obj, os_getcwd);
-
-STATIC mp_obj_t os_listdir(mp_uint_t n_args, const mp_obj_t *args) {
- bool is_str_type = true;
- const char *path;
- mp_obj_t dir_list = mp_obj_new_list(0, NULL);
-
- if (n_args == 1) {
- if (mp_obj_get_type(args[0]) == &mp_type_bytes) {
- is_str_type = false;
- }
- path = mp_obj_str_get_str(args[0]);
- } else {
- path = "";
- }
-
- // "hack" to list the root directory
- if (path[0] == '/' && path[1] == '\0') {
- // add 'flash' to the list
- append_dir_item (dir_list, "flash", is_str_type);
- for (mp_uint_t i = 0; i < MP_STATE_PORT(mount_obj_list).len; i++) {
- os_fs_mount_t *mount_obj = ((os_fs_mount_t *)(MP_STATE_PORT(mount_obj_list).items[i]));
- append_dir_item (dir_list, &mount_obj->path[1], is_str_type);
- }
- } else {
- FRESULT res;
- DIR dir;
- FILINFO fno;
- #if _USE_LFN
- char lfn_buf[_MAX_LFN + 1];
- fno.lfname = lfn_buf;
- fno.lfsize = sizeof(lfn_buf);
- #endif
-
- res = f_opendir(&dir, path); /* Open the directory */
- if (res != FR_OK) {
- mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed);
- }
-
- for ( ; ; ) {
- res = f_readdir(&dir, &fno); /* Read a directory item */
- if (res != FR_OK || fno.fname[0] == 0) break; /* Break on error or end of dir */
- if (fno.fname[0] == '.' && fno.fname[1] == 0) continue; /* Ignore . entry */
- if (fno.fname[0] == '.' && fno.fname[1] == '.' && fno.fname[2] == 0) continue; /* Ignore .. entry */
-
- #if _USE_LFN
- char *fn = *fno.lfname ? fno.lfname : fno.fname;
- #else
- char *fn = fno.fname;
- #endif
-
- // add the entry to the list
- append_dir_item (dir_list, fn, is_str_type);
- }
- f_closedir(&dir);
- }
-
- return dir_list;
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(os_listdir_obj, 0, 1, os_listdir);
-
-STATIC mp_obj_t os_mkdir(mp_obj_t path_o) {
- const char *path = mp_obj_str_get_str(path_o);
- FRESULT res = f_mkdir(path);
- switch (res) {
- case FR_OK:
- return mp_const_none;
- case FR_EXIST:
- mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible);
- break;
- default:
- mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed);
- }
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_mkdir_obj, os_mkdir);
-
-STATIC mp_obj_t os_rename(mp_obj_t path_in, mp_obj_t path_out) {
- const char *old_path = mp_obj_str_get_str(path_in);
- const char *new_path = mp_obj_str_get_str(path_out);
- FRESULT res = f_rename(old_path, new_path);
- switch (res) {
- case FR_OK:
- return mp_const_none;
- default:
- mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed);
- }
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_2(os_rename_obj, os_rename);
-
-STATIC mp_obj_t os_remove(mp_obj_t path_o) {
- const char *path = mp_obj_str_get_str(path_o);
- FRESULT res = f_unlink(path);
- switch (res) {
- case FR_OK:
- return mp_const_none;
- default:
- mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed);
- }
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_remove_obj, os_remove);
-
-STATIC mp_obj_t os_stat(mp_obj_t path_in) {
- const char *path = mp_obj_str_get_str(path_in);
- bool isbuilt_in = false;
- FILINFO fno;
- FRESULT res;
-#if _USE_LFN
- fno.lfname = NULL;
- fno.lfsize = 0;
-#endif
-
- // check on the user mounted devices
- for (mp_uint_t i = 0; i < MP_STATE_PORT(mount_obj_list).len; i++) {
- os_fs_mount_t *mount_obj = ((os_fs_mount_t *)(MP_STATE_PORT(mount_obj_list).items[i]));
- if (path_equal(path, mount_obj->path)) {
- isbuilt_in = true;
- break;
- }
- }
-
- if (path_equal(path, "/") || path_equal(path, "/flash") || isbuilt_in) {
- // stat built-in directory
- fno.fsize = 0;
- fno.fdate = 0;
- fno.ftime = 0;
- fno.fattrib = AM_DIR;
- } else if ((res = f_stat(path, &fno)) != FR_OK) {
- mp_raise_OSError(fresult_to_errno_table[res]);
- }
-
- mp_obj_tuple_t *t = mp_obj_new_tuple(10, NULL);
- mp_int_t mode = 0;
- if (fno.fattrib & AM_DIR) {
- mode |= 0x4000; // stat.S_IFDIR
- } else {
- mode |= 0x8000; // stat.S_IFREG
- }
- mp_int_t seconds = timeutils_seconds_since_2000(
- 1980 + ((fno.fdate >> 9) & 0x7f),
- (fno.fdate >> 5) & 0x0f,
- fno.fdate & 0x1f,
- (fno.ftime >> 11) & 0x1f,
- (fno.ftime >> 5) & 0x3f,
- 2 * (fno.ftime & 0x1f)
- );
- t->items[0] = mp_obj_new_int(mode); // st_mode
- t->items[1] = MP_OBJ_NEW_SMALL_INT(0); // st_ino
- t->items[2] = MP_OBJ_NEW_SMALL_INT(0); // st_dev
- t->items[3] = MP_OBJ_NEW_SMALL_INT(0); // st_nlink
- t->items[4] = MP_OBJ_NEW_SMALL_INT(0); // st_uid
- t->items[5] = MP_OBJ_NEW_SMALL_INT(0); // st_gid
- t->items[6] = mp_obj_new_int(fno.fsize); // st_size
- t->items[7] = mp_obj_new_int(seconds); // st_atime
- t->items[8] = t->items[7]; // st_mtime
- t->items[9] = t->items[7]; // st_ctime
- return t;
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_stat_obj, os_stat);
-
STATIC mp_obj_t os_sync(void) {
sflash_disk_flush();
return mp_const_none;
@@ -443,110 +123,6 @@ STATIC mp_obj_t os_urandom(mp_obj_t num) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_urandom_obj, os_urandom);
-STATIC mp_obj_t os_mount(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
- static const mp_arg_t mount_args[] = {
- { MP_QSTR_readonly, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
- };
-
- // parse args
- mp_obj_t device = pos_args[0];
- mp_obj_t mount_point = pos_args[1];
- mp_arg_val_t args[MP_ARRAY_SIZE(mount_args)];
- mp_arg_parse_all(n_args - 2, pos_args + 2, kw_args, MP_ARRAY_SIZE(mount_args), mount_args, args);
-
- // get the mount point
- mp_uint_t pathlen;
- const char *path_in = mp_obj_str_get_data(mount_point, &pathlen);
- if (pathlen == 0) {
- goto invalid_args;
- }
-
- char *path = m_new(char, pathlen + 1);
- memcpy(path, path_in, pathlen);
- path[pathlen] = '\0';
-
- // "remove" any extra slahes at the end
- while (path[(pathlen - 1)] == '/') {
- path[--pathlen] = '\0';
- }
-
- // is the mount point valid?
- if (pathlen < 2 || path[0] !='/' || strchr(&path[1], '/')) {
- goto invalid_args;
- }
-
- // now mount it
- mount(device, path, pathlen, args[0].u_bool);
-
- return mp_const_none;
-
-invalid_args:
- mp_raise_msg(&mp_type_OSError, mpexception_value_invalid_arguments);
-}
-MP_DEFINE_CONST_FUN_OBJ_KW(os_mount_obj, 2, os_mount);
-
-STATIC mp_obj_t os_unmount(mp_obj_t path_o) {
- const char *path = mp_obj_str_get_str(path_o);
-
- // '/flash' cannot be unmounted, also not the current working directory
- if (path_equal(path, "/flash")) {
- mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible);
- }
-
- // now unmount it
- os_fs_mount_t *mount_obj;
- if ((mount_obj = osmount_find_by_path(path))) {
- unmount (mount_obj);
- } else {
- mp_raise_ValueError(mpexception_value_invalid_arguments);
- }
-
- return mp_const_none;
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_unmount_obj, os_unmount);
-
-STATIC mp_obj_t os_mkfs(mp_obj_t device) {
- const char *path = "/__mkfs__mnt__";
- os_fs_mount_t *mount_obj = NULL;
- bool unmt = false;
- FRESULT res;
-
- if (MP_OBJ_IS_STR_OR_BYTES(device)) {
- path = mp_obj_str_get_str(device);
- // otherwise the relative path check will pass...
- if (path[0] != '/') {
- mp_raise_msg(&mp_type_OSError, mpexception_value_invalid_arguments);
- }
- } else {
- // mount it briefly
- mount(device, path, strlen(path), false);
- unmt = true;
- }
-
- byte sfd = 0;
- if (!memcmp(path, "/flash", strlen("/flash"))) {
- sfd = 1;
- } else if ((mount_obj = osmount_find_by_path(path))) {
- if (mount_obj->device != (mp_obj_t)&pybsd_obj &&
- mp_obj_get_int(mp_call_method_n_kw(0, 0, mount_obj->count)) < 2048) {
- sfd = 1;
- }
- }
-
- // now format the device
- res = f_mkfs(path, sfd, 0);
-
- if (unmt && mount_obj) {
- unmount (mount_obj);
- }
-
- if (res != FR_OK) {
- mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed);
- }
- return mp_const_none;
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_mkfs_obj, os_mkfs);
-
STATIC mp_obj_t os_dupterm(uint n_args, const mp_obj_t *args) {
if (n_args == 0) {
if (MP_STATE_PORT(os_term_dup_obj) == MP_OBJ_NULL) {
@@ -576,26 +152,28 @@ STATIC const mp_map_elem_t os_module_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_uos) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_uname), (mp_obj_t)&os_uname_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_chdir), (mp_obj_t)&os_chdir_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_getcwd), (mp_obj_t)&os_getcwd_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_listdir), (mp_obj_t)&os_listdir_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_mkdir), (mp_obj_t)&os_mkdir_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_rename), (mp_obj_t)&os_rename_obj},
- { MP_OBJ_NEW_QSTR(MP_QSTR_remove), (mp_obj_t)&os_remove_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_rmdir), (mp_obj_t)&os_remove_obj }, // rmdir aliases to remove
- { MP_OBJ_NEW_QSTR(MP_QSTR_stat), (mp_obj_t)&os_stat_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_unlink), (mp_obj_t)&os_remove_obj }, // unlink aliases to remove
+
+ { MP_OBJ_NEW_QSTR(MP_QSTR_chdir), (mp_obj_t)&mp_vfs_chdir_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_getcwd), (mp_obj_t)&mp_vfs_getcwd_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_ilistdir), (mp_obj_t)&mp_vfs_ilistdir_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_listdir), (mp_obj_t)&mp_vfs_listdir_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_mkdir), (mp_obj_t)&mp_vfs_mkdir_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_rename), (mp_obj_t)&mp_vfs_rename_obj},
+ { MP_OBJ_NEW_QSTR(MP_QSTR_remove), (mp_obj_t)&mp_vfs_remove_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_rmdir), (mp_obj_t)&mp_vfs_rmdir_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_stat), (mp_obj_t)&mp_vfs_stat_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_unlink), (mp_obj_t)&mp_vfs_remove_obj }, // unlink aliases to remove
+
{ MP_OBJ_NEW_QSTR(MP_QSTR_sync), (mp_obj_t)&os_sync_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_urandom), (mp_obj_t)&os_urandom_obj },
// MicroPython additions
- { MP_OBJ_NEW_QSTR(MP_QSTR_mount), (mp_obj_t)&os_mount_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_unmount), (mp_obj_t)&os_unmount_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_mkfs), (mp_obj_t)&os_mkfs_obj },
+ // removed: mkfs
+ // renamed: unmount -> umount
+ { MP_OBJ_NEW_QSTR(MP_QSTR_mount), (mp_obj_t)&mp_vfs_mount_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_umount), (mp_obj_t)&mp_vfs_umount_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_VfsFat), (mp_obj_t)&mp_fat_vfs_type },
{ MP_OBJ_NEW_QSTR(MP_QSTR_dupterm), (mp_obj_t)&os_dupterm_obj },
-
- /// \constant sep - separation character used in paths
- { MP_OBJ_NEW_QSTR(MP_QSTR_sep), MP_OBJ_NEW_QSTR(MP_QSTR__slash_) },
};
STATIC MP_DEFINE_CONST_DICT(os_module_globals, os_module_globals_table);
diff --git a/cc3200/mods/moduos.h b/cc3200/mods/moduos.h
index 1ebf16cdf..4c8bc9659 100644
--- a/cc3200/mods/moduos.h
+++ b/cc3200/mods/moduos.h
@@ -28,22 +28,11 @@
#ifndef MODUOS_H_
#define MODUOS_H_
-#include "ff.h"
+#include "py/obj.h"
/******************************************************************************
DEFINE PUBLIC TYPES
******************************************************************************/
-typedef struct _os_fs_mount_t {
- mp_obj_t device;
- const char *path;
- mp_uint_t pathlen;
- mp_obj_t readblocks[4];
- mp_obj_t writeblocks[4];
- mp_obj_t sync[2];
- mp_obj_t count[2];
- FATFS fatfs;
- uint8_t vol;
-} os_fs_mount_t;
typedef struct _os_term_dup_obj_t {
mp_obj_t stream_o;
@@ -54,9 +43,6 @@ typedef struct _os_term_dup_obj_t {
/******************************************************************************
DECLARE PUBLIC FUNCTIONS
******************************************************************************/
-void moduos_init0 (void);
-os_fs_mount_t *osmount_find_by_path (const char *path);
-os_fs_mount_t *osmount_find_by_volume (uint8_t vol);
void osmount_unmount_all (void);
#endif // MODUOS_H_
diff --git a/cc3200/mods/modusocket.c b/cc3200/mods/modusocket.c
index 9554c2608..ca28bf7ba 100644
--- a/cc3200/mods/modusocket.c
+++ b/cc3200/mods/modusocket.c
@@ -34,12 +34,254 @@
#include "py/objstr.h"
#include "py/runtime.h"
#include "py/stream.h"
-#include "netutils.h"
+#include "lib/netutils/netutils.h"
#include "modnetwork.h"
-#include "modwlan.h"
#include "modusocket.h"
#include "mpexception.h"
+/******************************************************************************/
+// The following set of macros and functions provide a glue between the CC3100
+// simplelink layer and the functions/methods provided by the usocket module.
+// They were historically in a separate file because usocket was designed to
+// work with multiple NICs, and the wlan_XXX functions just provided one
+// particular NIC implementation (that of the CC3100). But the CC3200 port only
+// supports a single NIC (being the CC3100) so it's unnecessary and inefficient
+// to provide an intermediate wrapper layer. Hence the wlan_XXX functions
+// are provided below as static functions so they can be inlined directly by
+// the corresponding usocket calls.
+
+#define WLAN_MAX_RX_SIZE 16000
+#define WLAN_MAX_TX_SIZE 1476
+
+#define MAKE_SOCKADDR(addr, ip, port) SlSockAddr_t addr; \
+ addr.sa_family = SL_AF_INET; \
+ addr.sa_data[0] = port >> 8; \
+ addr.sa_data[1] = port; \
+ addr.sa_data[2] = ip[3]; \
+ addr.sa_data[3] = ip[2]; \
+ addr.sa_data[4] = ip[1]; \
+ addr.sa_data[5] = ip[0];
+
+#define UNPACK_SOCKADDR(addr, ip, port) port = (addr.sa_data[0] << 8) | addr.sa_data[1]; \
+ ip[0] = addr.sa_data[5]; \
+ ip[1] = addr.sa_data[4]; \
+ ip[2] = addr.sa_data[3]; \
+ ip[3] = addr.sa_data[2];
+
+STATIC int wlan_gethostbyname(const char *name, mp_uint_t len, uint8_t *out_ip, uint8_t family) {
+ uint32_t ip;
+ int result = sl_NetAppDnsGetHostByName((_i8 *)name, (_u16)len, (_u32*)&ip, (_u8)family);
+ out_ip[0] = ip;
+ out_ip[1] = ip >> 8;
+ out_ip[2] = ip >> 16;
+ out_ip[3] = ip >> 24;
+ return result;
+}
+
+STATIC int wlan_socket_socket(mod_network_socket_obj_t *s, int *_errno) {
+ int16_t sd = sl_Socket(s->sock_base.u_param.domain, s->sock_base.u_param.type, s->sock_base.u_param.proto);
+ if (sd < 0) {
+ *_errno = sd;
+ return -1;
+ }
+ s->sock_base.sd = sd;
+ return 0;
+}
+
+STATIC void wlan_socket_close(mod_network_socket_obj_t *s) {
+ // this is to prevent the finalizer to close a socket that failed when being created
+ if (s->sock_base.sd >= 0) {
+ modusocket_socket_delete(s->sock_base.sd);
+ sl_Close(s->sock_base.sd);
+ s->sock_base.sd = -1;
+ }
+}
+
+STATIC int wlan_socket_bind(mod_network_socket_obj_t *s, byte *ip, mp_uint_t port, int *_errno) {
+ MAKE_SOCKADDR(addr, ip, port)
+ int ret = sl_Bind(s->sock_base.sd, &addr, sizeof(addr));
+ if (ret != 0) {
+ *_errno = ret;
+ return -1;
+ }
+ return 0;
+}
+
+STATIC int wlan_socket_listen(mod_network_socket_obj_t *s, mp_int_t backlog, int *_errno) {
+ int ret = sl_Listen(s->sock_base.sd, backlog);
+ if (ret != 0) {
+ *_errno = ret;
+ return -1;
+ }
+ return 0;
+}
+
+STATIC int wlan_socket_accept(mod_network_socket_obj_t *s, mod_network_socket_obj_t *s2, byte *ip, mp_uint_t *port, int *_errno) {
+ // accept incoming connection
+ int16_t sd;
+ SlSockAddr_t addr;
+ SlSocklen_t addr_len = sizeof(addr);
+
+ sd = sl_Accept(s->sock_base.sd, &addr, &addr_len);
+ // save the socket descriptor
+ s2->sock_base.sd = sd;
+ if (sd < 0) {
+ *_errno = sd;
+ return -1;
+ }
+
+ // return ip and port
+ UNPACK_SOCKADDR(addr, ip, *port);
+ return 0;
+}
+
+STATIC int wlan_socket_connect(mod_network_socket_obj_t *s, byte *ip, mp_uint_t port, int *_errno) {
+ MAKE_SOCKADDR(addr, ip, port)
+ int ret = sl_Connect(s->sock_base.sd, &addr, sizeof(addr));
+ if (ret != 0) {
+ *_errno = ret;
+ return -1;
+ }
+ return 0;
+}
+
+STATIC int wlan_socket_send(mod_network_socket_obj_t *s, const byte *buf, mp_uint_t len, int *_errno) {
+ mp_int_t bytes = 0;
+ if (len > 0) {
+ bytes = sl_Send(s->sock_base.sd, (const void *)buf, len, 0);
+ }
+ if (bytes <= 0) {
+ *_errno = bytes;
+ return -1;
+ }
+ return bytes;
+}
+
+STATIC int wlan_socket_recv(mod_network_socket_obj_t *s, byte *buf, mp_uint_t len, int *_errno) {
+ int ret = sl_Recv(s->sock_base.sd, buf, MIN(len, WLAN_MAX_RX_SIZE), 0);
+ if (ret < 0) {
+ *_errno = ret;
+ return -1;
+ }
+ return ret;
+}
+
+STATIC int wlan_socket_sendto( mod_network_socket_obj_t *s, const byte *buf, mp_uint_t len, byte *ip, mp_uint_t port, int *_errno) {
+ MAKE_SOCKADDR(addr, ip, port)
+ int ret = sl_SendTo(s->sock_base.sd, (byte*)buf, len, 0, (SlSockAddr_t*)&addr, sizeof(addr));
+ if (ret < 0) {
+ *_errno = ret;
+ return -1;
+ }
+ return ret;
+}
+
+STATIC int wlan_socket_recvfrom(mod_network_socket_obj_t *s, byte *buf, mp_uint_t len, byte *ip, mp_uint_t *port, int *_errno) {
+ SlSockAddr_t addr;
+ SlSocklen_t addr_len = sizeof(addr);
+ mp_int_t ret = sl_RecvFrom(s->sock_base.sd, buf, MIN(len, WLAN_MAX_RX_SIZE), 0, &addr, &addr_len);
+ if (ret < 0) {
+ *_errno = ret;
+ return -1;
+ }
+ UNPACK_SOCKADDR(addr, ip, *port);
+ return ret;
+}
+
+STATIC int wlan_socket_setsockopt(mod_network_socket_obj_t *s, mp_uint_t level, mp_uint_t opt, const void *optval, mp_uint_t optlen, int *_errno) {
+ int ret = sl_SetSockOpt(s->sock_base.sd, level, opt, optval, optlen);
+ if (ret < 0) {
+ *_errno = ret;
+ return -1;
+ }
+ return 0;
+}
+
+STATIC int wlan_socket_settimeout(mod_network_socket_obj_t *s, mp_uint_t timeout_s, int *_errno) {
+ int ret;
+ bool has_timeout;
+ if (timeout_s == 0 || timeout_s == -1) {
+ SlSockNonblocking_t option;
+ if (timeout_s == 0) {
+ // set non-blocking mode
+ option.NonblockingEnabled = 1;
+ } else {
+ // set blocking mode
+ option.NonblockingEnabled = 0;
+ }
+ ret = sl_SetSockOpt(s->sock_base.sd, SL_SOL_SOCKET, SL_SO_NONBLOCKING, &option, sizeof(option));
+ has_timeout = false;
+ } else {
+ // set timeout
+ struct SlTimeval_t timeVal;
+ timeVal.tv_sec = timeout_s; // seconds
+ timeVal.tv_usec = 0; // microseconds. 10000 microseconds resolution
+ ret = sl_SetSockOpt(s->sock_base.sd, SL_SOL_SOCKET, SL_SO_RCVTIMEO, &timeVal, sizeof(timeVal));
+ has_timeout = true;
+ }
+
+ if (ret != 0) {
+ *_errno = ret;
+ return -1;
+ }
+
+ s->sock_base.has_timeout = has_timeout;
+ return 0;
+}
+
+STATIC int wlan_socket_ioctl (mod_network_socket_obj_t *s, mp_uint_t request, mp_uint_t arg, int *_errno) {
+ mp_int_t ret;
+ if (request == MP_STREAM_POLL) {
+ mp_uint_t flags = arg;
+ ret = 0;
+ int32_t sd = s->sock_base.sd;
+
+ // init fds
+ SlFdSet_t rfds, wfds, xfds;
+ SL_FD_ZERO(&rfds);
+ SL_FD_ZERO(&wfds);
+ SL_FD_ZERO(&xfds);
+
+ // set fds if needed
+ if (flags & MP_STREAM_POLL_RD) {
+ SL_FD_SET(sd, &rfds);
+ }
+ if (flags & MP_STREAM_POLL_WR) {
+ SL_FD_SET(sd, &wfds);
+ }
+ if (flags & MP_STREAM_POLL_HUP) {
+ SL_FD_SET(sd, &xfds);
+ }
+
+ // call simplelink's select with minimum timeout
+ SlTimeval_t tv;
+ tv.tv_sec = 0;
+ tv.tv_usec = 1;
+ int32_t nfds = sl_Select(sd + 1, &rfds, &wfds, &xfds, &tv);
+
+ // check for errors
+ if (nfds == -1) {
+ *_errno = nfds;
+ return -1;
+ }
+
+ // check return of select
+ if (SL_FD_ISSET(sd, &rfds)) {
+ ret |= MP_STREAM_POLL_RD;
+ }
+ if (SL_FD_ISSET(sd, &wfds)) {
+ ret |= MP_STREAM_POLL_WR;
+ }
+ if (SL_FD_ISSET(sd, &xfds)) {
+ ret |= MP_STREAM_POLL_HUP;
+ }
+ } else {
+ *_errno = MP_EINVAL;
+ ret = MP_STREAM_ERROR;
+ }
+ return ret;
+}
+
/******************************************************************************
DEFINE PRIVATE CONSTANTS
******************************************************************************/
@@ -95,13 +337,13 @@ void modusocket_socket_delete (int16_t sd) {
}
void modusocket_enter_sleep (void) {
- fd_set socketset;
+ SlFdSet_t socketset;
int16_t maxfd = 0;
for (int i = 0; i < MOD_NETWORK_MAX_SOCKETS; i++) {
int16_t sd;
if ((sd = modusocket_sockets[i].sd) >= 0) {
- FD_SET(sd, &socketset);
+ SL_FD_SET(sd, &socketset);
maxfd = (maxfd > sd) ? maxfd : sd;
}
}
@@ -133,9 +375,9 @@ STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type, size_t n_args, size_t
// create socket object
mod_network_socket_obj_t *s = m_new_obj_with_finaliser(mod_network_socket_obj_t);
s->base.type = (mp_obj_t)&socket_type;
- s->sock_base.u_param.domain = AF_INET;
- s->sock_base.u_param.type = SOCK_STREAM;
- s->sock_base.u_param.proto = IPPROTO_TCP;
+ s->sock_base.u_param.domain = SL_AF_INET;
+ s->sock_base.u_param.type = SL_SOCK_STREAM;
+ s->sock_base.u_param.proto = SL_IPPROTO_TCP;
s->sock_base.u_param.fileno = -1;
s->sock_base.has_timeout = false;
s->sock_base.cert_req = false;
@@ -180,7 +422,7 @@ STATIC mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) {
mp_uint_t port = netutils_parse_inet_addr(addr_in, ip, NETUTILS_LITTLE);
// call the NIC to bind the socket
- int _errno;
+ int _errno = 0;
if (wlan_socket_bind(self, ip, port, &_errno) != 0) {
mp_raise_OSError(-_errno);
}
@@ -217,8 +459,8 @@ STATIC mp_obj_t socket_accept(mp_obj_t self_in) {
// accept the incoming connection
uint8_t ip[MOD_NETWORK_IPV4ADDR_BUF_SIZE];
- mp_uint_t port;
- int _errno;
+ mp_uint_t port = 0;
+ int _errno = 0;
if (wlan_socket_accept(self, socket2, ip, &port, &_errno) != 0) {
mp_raise_OSError(-_errno);
}
@@ -277,8 +519,8 @@ STATIC mp_obj_t socket_recv(mp_obj_t self_in, mp_obj_t len_in) {
int _errno;
mp_int_t ret = wlan_socket_recv(self, (byte*)vstr.buf, len, &_errno);
if (ret < 0) {
- if (_errno == EAGAIN && self->sock_base.has_timeout) {
- mp_raise_msg(&mp_type_TimeoutError, "timed out");
+ if (_errno == MP_EAGAIN && self->sock_base.has_timeout) {
+ mp_raise_OSError(MP_ETIMEDOUT);
}
mp_raise_OSError(-_errno);
}
@@ -304,7 +546,7 @@ STATIC mp_obj_t socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t addr_
mp_uint_t port = netutils_parse_inet_addr(addr_in, ip, NETUTILS_LITTLE);
// call the nic to sendto
- int _errno;
+ int _errno = 0;
mp_int_t ret = wlan_socket_sendto(self, bufinfo.buf, bufinfo.len, ip, port, &_errno);
if (ret < 0) {
mp_raise_OSError(-_errno);
@@ -319,12 +561,12 @@ STATIC mp_obj_t socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) {
vstr_t vstr;
vstr_init_len(&vstr, mp_obj_get_int(len_in));
byte ip[4];
- mp_uint_t port;
- int _errno;
+ mp_uint_t port = 0;
+ int _errno = 0;
mp_int_t ret = wlan_socket_recvfrom(self, (byte*)vstr.buf, vstr.len, ip, &port, &_errno);
if (ret < 0) {
- if (_errno == EAGAIN && self->sock_base.has_timeout) {
- mp_raise_msg(&mp_type_TimeoutError, "timed out");
+ if (_errno == MP_EAGAIN && self->sock_base.has_timeout) {
+ mp_raise_OSError(MP_ETIMEDOUT);
}
mp_raise_OSError(-_errno);
}
@@ -495,19 +737,19 @@ STATIC const mp_obj_type_t socket_type = {
// function usocket.getaddrinfo(host, port)
/// \function getaddrinfo(host, port)
STATIC mp_obj_t mod_usocket_getaddrinfo(mp_obj_t host_in, mp_obj_t port_in) {
- mp_uint_t hlen;
+ size_t hlen;
const char *host = mp_obj_str_get_data(host_in, &hlen);
mp_int_t port = mp_obj_get_int(port_in);
// ipv4 only
uint8_t out_ip[MOD_NETWORK_IPV4ADDR_BUF_SIZE];
- int32_t result = wlan_gethostbyname(host, hlen, out_ip, AF_INET);
+ int32_t result = wlan_gethostbyname(host, hlen, out_ip, SL_AF_INET);
if (result < 0) {
mp_raise_OSError(-result);
}
mp_obj_tuple_t *tuple = mp_obj_new_tuple(5, NULL);
- tuple->items[0] = MP_OBJ_NEW_SMALL_INT(AF_INET);
- tuple->items[1] = MP_OBJ_NEW_SMALL_INT(SOCK_STREAM);
+ tuple->items[0] = MP_OBJ_NEW_SMALL_INT(SL_AF_INET);
+ tuple->items[1] = MP_OBJ_NEW_SMALL_INT(SL_SOCK_STREAM);
tuple->items[2] = MP_OBJ_NEW_SMALL_INT(0);
tuple->items[3] = MP_OBJ_NEW_QSTR(MP_QSTR_);
tuple->items[4] = netutils_format_inet_addr(out_ip, port, NETUTILS_LITTLE);
@@ -521,19 +763,15 @@ STATIC const mp_map_elem_t mp_module_usocket_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_socket), (mp_obj_t)&socket_type },
{ MP_OBJ_NEW_QSTR(MP_QSTR_getaddrinfo), (mp_obj_t)&mod_usocket_getaddrinfo_obj },
- // class exceptions
- { MP_OBJ_NEW_QSTR(MP_QSTR_error), (mp_obj_t)&mp_type_OSError },
- { MP_OBJ_NEW_QSTR(MP_QSTR_timeout), (mp_obj_t)&mp_type_TimeoutError },
-
// class constants
- { MP_OBJ_NEW_QSTR(MP_QSTR_AF_INET), MP_OBJ_NEW_SMALL_INT(AF_INET) },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_AF_INET), MP_OBJ_NEW_SMALL_INT(SL_AF_INET) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_SOCK_STREAM), MP_OBJ_NEW_SMALL_INT(SOCK_STREAM) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_SOCK_DGRAM), MP_OBJ_NEW_SMALL_INT(SOCK_DGRAM) },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_SOCK_STREAM), MP_OBJ_NEW_SMALL_INT(SL_SOCK_STREAM) },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_SOCK_DGRAM), MP_OBJ_NEW_SMALL_INT(SL_SOCK_DGRAM) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_IPPROTO_SEC), MP_OBJ_NEW_SMALL_INT(SL_SEC_SOCKET) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_IPPROTO_TCP), MP_OBJ_NEW_SMALL_INT(IPPROTO_TCP) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_IPPROTO_UDP), MP_OBJ_NEW_SMALL_INT(IPPROTO_UDP) },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_IPPROTO_TCP), MP_OBJ_NEW_SMALL_INT(SL_IPPROTO_TCP) },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_IPPROTO_UDP), MP_OBJ_NEW_SMALL_INT(SL_IPPROTO_UDP) },
};
STATIC MP_DEFINE_CONST_DICT(mp_module_usocket_globals, mp_module_usocket_globals_table);
diff --git a/cc3200/mods/modussl.c b/cc3200/mods/modussl.c
index 7a4787b6b..95ecdbce7 100644
--- a/cc3200/mods/modussl.c
+++ b/cc3200/mods/modussl.c
@@ -25,7 +25,6 @@
*/
#include <stdint.h>
-#include <std.h>
#include "simplelink.h"
#include "py/mpconfig.h"
diff --git a/cc3200/mods/modutime.c b/cc3200/mods/modutime.c
index 7ea8df1ef..48fde67e7 100644
--- a/cc3200/mods/modutime.c
+++ b/cc3200/mods/modutime.c
@@ -33,7 +33,8 @@
#include "py/obj.h"
#include "py/smallint.h"
#include "py/mphal.h"
-#include "timeutils.h"
+#include "lib/timeutils/timeutils.h"
+#include "extmod/utime_mphal.h"
#include "inc/hw_types.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
@@ -41,7 +42,6 @@
#include "prcm.h"
#include "systick.h"
#include "pybrtc.h"
-#include "mpsystick.h"
#include "mpexception.h"
#include "utils.h"
@@ -102,7 +102,7 @@ STATIC mp_obj_t time_localtime(mp_uint_t n_args, const mp_obj_t *args) {
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(time_localtime_obj, 0, 1, time_localtime);
STATIC mp_obj_t time_mktime(mp_obj_t tuple) {
- mp_uint_t len;
+ size_t len;
mp_obj_t *elem;
mp_obj_get_array(tuple, &len, &elem);
@@ -131,50 +131,6 @@ STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) {
}
MP_DEFINE_CONST_FUN_OBJ_1(time_sleep_obj, time_sleep);
-STATIC mp_obj_t time_sleep_ms (mp_obj_t ms_in) {
- mp_int_t ms = mp_obj_get_int(ms_in);
- if (ms > 0) {
- mp_hal_delay_ms(ms);
- }
- return mp_const_none;
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(time_sleep_ms_obj, time_sleep_ms);
-
-STATIC mp_obj_t time_sleep_us (mp_obj_t usec_in) {
- mp_int_t usec = mp_obj_get_int(usec_in);
- if (usec > 0) {
- UtilsDelay(UTILS_DELAY_US_TO_COUNT(usec));
- }
- return mp_const_none;
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(time_sleep_us_obj, time_sleep_us);
-
-STATIC mp_obj_t time_ticks_ms(void) {
- // We want to "cast" the 32 bit unsigned into a 30-bit small-int
- return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_ms() & MP_SMALL_INT_POSITIVE_MASK);
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_0(time_ticks_ms_obj, time_ticks_ms);
-
-STATIC mp_obj_t time_ticks_us(void) {
- // We want to "cast" the 32 bit unsigned into a 30-bit small-int
- return MP_OBJ_NEW_SMALL_INT(sys_tick_get_microseconds() & MP_SMALL_INT_POSITIVE_MASK);
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_0(time_ticks_us_obj, time_ticks_us);
-
-STATIC mp_obj_t time_ticks_cpu(void) {
- // We want to "cast" the 32 bit unsigned into a 30-bit small-int
- return MP_OBJ_NEW_SMALL_INT((SysTickPeriodGet() - SysTickValueGet()) & MP_SMALL_INT_POSITIVE_MASK);
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_0(time_ticks_cpu_obj, time_ticks_cpu);
-
-STATIC mp_obj_t time_ticks_diff(mp_obj_t t0, mp_obj_t t1) {
- // We want to "cast" the 32 bit unsigned into a 30-bit small-int
- uint32_t start = mp_obj_get_int(t0);
- uint32_t end = mp_obj_get_int(t1);
- return MP_OBJ_NEW_SMALL_INT((end - start) & MP_SMALL_INT_POSITIVE_MASK);
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_2(time_ticks_diff_obj, time_ticks_diff);
-
STATIC const mp_map_elem_t time_module_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_utime) },
@@ -184,12 +140,13 @@ STATIC const mp_map_elem_t time_module_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_sleep), (mp_obj_t)&time_sleep_obj },
// MicroPython additions
- { MP_OBJ_NEW_QSTR(MP_QSTR_sleep_ms), (mp_obj_t)&time_sleep_ms_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_sleep_us), (mp_obj_t)&time_sleep_us_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_ms), (mp_obj_t)&time_ticks_ms_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_us), (mp_obj_t)&time_ticks_us_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_cpu), (mp_obj_t)&time_ticks_cpu_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_diff), (mp_obj_t)&time_ticks_diff_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_sleep_ms), (mp_obj_t)&mp_utime_sleep_ms_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_sleep_us), (mp_obj_t)&mp_utime_sleep_us_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_ms), (mp_obj_t)&mp_utime_ticks_ms_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_us), (mp_obj_t)&mp_utime_ticks_us_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_cpu), (mp_obj_t)&mp_utime_ticks_cpu_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_add), (mp_obj_t)&mp_utime_ticks_add_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_diff), (mp_obj_t)&mp_utime_ticks_diff_obj },
};
STATIC MP_DEFINE_CONST_DICT(time_module_globals, time_module_globals_table);
diff --git a/cc3200/mods/modwlan.c b/cc3200/mods/modwlan.c
index a85921cc5..dacf59a7c 100644
--- a/cc3200/mods/modwlan.c
+++ b/cc3200/mods/modwlan.c
@@ -26,7 +26,7 @@
#include <stdint.h>
#include <stdbool.h>
-#include "std.h"
+#include <stdio.h>
#include "simplelink.h"
#include "py/ioctl.h"
@@ -36,13 +36,8 @@
#include "py/runtime.h"
#include "py/stream.h"
#include "py/mphal.h"
-#include "inc/hw_types.h"
-#include "inc/hw_ints.h"
-#include "inc/hw_memmap.h"
-#include "rom_map.h"
-#include "prcm.h"
-#include "timeutils.h"
-#include "netutils.h"
+#include "lib/timeutils/timeutils.h"
+#include "lib/netutils/netutils.h"
#include "modnetwork.h"
#include "modusocket.h"
#include "modwlan.h"
@@ -118,26 +113,6 @@ typedef enum{
#define ASSERT_ON_ERROR(x) ASSERT((x) >= 0)
-#define IPV4_ADDR_STR_LEN_MAX (16)
-
-#define WLAN_MAX_RX_SIZE 16000
-#define WLAN_MAX_TX_SIZE 1476
-
-#define MAKE_SOCKADDR(addr, ip, port) sockaddr addr; \
- addr.sa_family = AF_INET; \
- addr.sa_data[0] = port >> 8; \
- addr.sa_data[1] = port; \
- addr.sa_data[2] = ip[3]; \
- addr.sa_data[3] = ip[2]; \
- addr.sa_data[4] = ip[1]; \
- addr.sa_data[5] = ip[0];
-
-#define UNPACK_SOCKADDR(addr, ip, port) port = (addr.sa_data[0] << 8) | addr.sa_data[1]; \
- ip[0] = addr.sa_data[5]; \
- ip[1] = addr.sa_data[4]; \
- ip[2] = addr.sa_data[3]; \
- ip[3] = addr.sa_data[2];
-
/******************************************************************************
DECLARE PRIVATE DATA
******************************************************************************/
@@ -162,7 +137,9 @@ STATIC const mp_irq_methods_t wlan_irq_methods;
/******************************************************************************
DECLARE PUBLIC DATA
******************************************************************************/
+#ifdef SL_PLATFORM_MULTI_THREADED
OsiLockObj_t wlan_LockObj;
+#endif
/******************************************************************************
DECLARE PRIVATE FUNCTIONS
@@ -397,14 +374,18 @@ void SimpleLinkSockEventHandler(SlSockEvent_t *pSock) {
__attribute__ ((section (".boot")))
void wlan_pre_init (void) {
// create the wlan lock
+ #ifdef SL_PLATFORM_MULTI_THREADED
ASSERT(OSI_OK == sl_LockObjCreate(&wlan_LockObj, "WlanLock"));
+ #endif
}
void wlan_first_start (void) {
if (wlan_obj.mode < 0) {
CLR_STATUS_BIT_ALL(wlan_obj.status);
wlan_obj.mode = sl_Start(0, 0, 0);
+ #ifdef SL_PLATFORM_MULTI_THREADED
sl_LockObjUnlock (&wlan_LockObj);
+ #endif
}
// get the mac address
@@ -513,7 +494,9 @@ void wlan_update(void) {
void wlan_stop (uint32_t timeout) {
wlan_servers_stop();
+ #ifdef SL_PLATFORM_MULTI_THREADED
sl_LockObjLock (&wlan_LockObj, SL_OS_WAIT_FOREVER);
+ #endif
sl_Stop(timeout);
wlan_clear_data();
wlan_obj.mode = -1;
@@ -569,11 +552,15 @@ STATIC void wlan_clear_data (void) {
STATIC void wlan_reenable (SlWlanMode_t mode) {
// stop and start again
+ #ifdef SL_PLATFORM_MULTI_THREADED
sl_LockObjLock (&wlan_LockObj, SL_OS_WAIT_FOREVER);
+ #endif
sl_Stop(SL_STOP_TIMEOUT);
wlan_clear_data();
wlan_obj.mode = sl_Start(0, 0, 0);
+ #ifdef SL_PLATFORM_MULTI_THREADED
sl_LockObjUnlock (&wlan_LockObj);
+ #endif
ASSERT (wlan_obj.mode == mode);
}
@@ -787,7 +774,7 @@ STATIC mp_obj_t wlan_init_helper(wlan_obj_t *self, const mp_arg_val_t *args) {
wlan_validate_mode(mode);
// get the ssid
- mp_uint_t ssid_len = 0;
+ size_t ssid_len = 0;
const char *ssid = NULL;
if (args[1].u_obj != NULL) {
ssid = mp_obj_str_get_data(args[1].u_obj, &ssid_len);
@@ -796,7 +783,7 @@ STATIC mp_obj_t wlan_init_helper(wlan_obj_t *self, const mp_arg_val_t *args) {
// get the auth config
uint8_t auth = SL_SEC_TYPE_OPEN;
- mp_uint_t key_len = 0;
+ size_t key_len = 0;
const char *key = NULL;
if (args[2].u_obj != mp_const_none) {
mp_obj_t *sec;
@@ -811,8 +798,9 @@ STATIC mp_obj_t wlan_init_helper(wlan_obj_t *self, const mp_arg_val_t *args) {
wlan_validate_channel(channel);
// get the antenna type
- uint8_t antenna = args[4].u_int;
+ uint8_t antenna = 0;
#if MICROPY_HW_ANTENNA_DIVERSITY
+ antenna = args[4].u_int;
wlan_validate_antenna(antenna);
#endif
@@ -828,7 +816,9 @@ STATIC const mp_arg_t wlan_init_args[] = {
{ MP_QSTR_ssid, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
{ MP_QSTR_auth, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
{ MP_QSTR_channel, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} },
+ #if MICROPY_HW_ANTENNA_DIVERSITY
{ MP_QSTR_antenna, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = ANTENNA_TYPE_INTERNAL} },
+ #endif
};
STATIC mp_obj_t wlan_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
// parse args
@@ -847,7 +837,7 @@ STATIC mp_obj_t wlan_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
if (n_args > 1 || n_kw > 0) {
// check the peripheral id
if (args[0].u_int != 0) {
- mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable);
+ mp_raise_OSError(MP_ENODEV);
}
// start the peripheral
wlan_init_helper(self, &args[1]);
@@ -871,7 +861,7 @@ STATIC mp_obj_t wlan_scan(mp_obj_t self_in) {
// check for correct wlan mode
if (wlan_obj.mode == ROLE_AP) {
- mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible);
+ mp_raise_OSError(MP_EPERM);
}
Sl_WlanNetworkEntry_t wlanEntry;
@@ -925,7 +915,7 @@ STATIC mp_obj_t wlan_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_
// check for the correct wlan mode
if (wlan_obj.mode == ROLE_AP) {
- mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible);
+ mp_raise_OSError(MP_EPERM);
}
// parse args
@@ -933,13 +923,13 @@ STATIC mp_obj_t wlan_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
// get the ssid
- mp_uint_t ssid_len;
+ size_t ssid_len;
const char *ssid = mp_obj_str_get_data(args[0].u_obj, &ssid_len);
wlan_validate_ssid_len(ssid_len);
// get the auth config
uint8_t auth = SL_SEC_TYPE_OPEN;
- mp_uint_t key_len = 0;
+ size_t key_len = 0;
const char *key = NULL;
if (args[1].u_obj != mp_const_none) {
mp_obj_t *sec;
@@ -973,7 +963,7 @@ STATIC mp_obj_t wlan_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_
modwlan_Status_t status;
status = wlan_do_connect (ssid, ssid_len, bssid, auth, key, key_len, timeout);
if (status == MODWLAN_ERROR_TIMEOUT) {
- mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed);
+ mp_raise_OSError(MP_ETIMEDOUT);
} else if (status == MODWLAN_ERROR_INVALID_PARAMS) {
mp_raise_ValueError(mpexception_value_invalid_arguments);
}
@@ -1004,7 +994,7 @@ STATIC mp_obj_t wlan_ifconfig (mp_uint_t n_args, const mp_obj_t *pos_args, mp_ma
// check the interface id
if (args[0].u_int != 0) {
- mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable);
+ mp_raise_OSError(MP_EPERM);
}
// get the configuration
@@ -1088,7 +1078,7 @@ STATIC mp_obj_t wlan_ssid (mp_uint_t n_args, const mp_obj_t *args) {
if (n_args == 1) {
return mp_obj_new_str((const char *)self->ssid, strlen((const char *)self->ssid), false);
} else {
- mp_uint_t len;
+ size_t len;
const char *ssid = mp_obj_str_get_data(args[1], &len);
wlan_validate_ssid_len(len);
wlan_set_ssid(ssid, len, false);
@@ -1112,7 +1102,7 @@ STATIC mp_obj_t wlan_auth (mp_uint_t n_args, const mp_obj_t *args) {
} else {
// get the auth config
uint8_t auth = SL_SEC_TYPE_OPEN;
- mp_uint_t key_len = 0;
+ size_t key_len = 0;
const char *key = NULL;
if (args[1] != mp_const_none) {
mp_obj_t *sec;
@@ -1235,13 +1225,13 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wlan_irq_obj, 1, wlan_irq);
// strcpy(urn, p);
//
// if (sl_NetAppSet(SL_NET_APP_DEVICE_CONFIG_ID, NETAPP_SET_GET_DEV_CONF_OPT_DEVICE_URN, len, (unsigned char *)urn) < 0) {
-// mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed);
+// mp_raise_OSError(MP_EIO);
// }
// }
// else {
// // get the URN
// if (sl_NetAppGet(SL_NET_APP_DEVICE_CONFIG_ID, NETAPP_SET_GET_DEV_CONF_OPT_DEVICE_URN, &len, (uint8_t *)urn) < 0) {
-// mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed);
+// mp_raise_OSError(MP_EIO);
// }
// return mp_obj_new_str(urn, (len - 1), false);
// }
@@ -1255,9 +1245,9 @@ STATIC mp_obj_t wlan_print_ver(void) {
byte config_opt = SL_DEVICE_GENERAL_VERSION;
byte config_len = sizeof(ver);
sl_DevGet(SL_DEVICE_GENERAL_CONFIGURATION, &config_opt, &config_len, (byte*)&ver);
- printf("NWP: %d.%d.%d.%d\n", ver.NwpVersion[0], ver.NwpVersion[1], ver.NwpVersion[2], ver.NwpVersion[3]);
- printf("MAC: %d.%d.%d.%d\n", ver.ChipFwAndPhyVersion.FwVersion[0], ver.ChipFwAndPhyVersion.FwVersion[1],
- ver.ChipFwAndPhyVersion.FwVersion[2], ver.ChipFwAndPhyVersion.FwVersion[3]);
+ printf("NWP: %d.%d.%d.%d\n", (int)ver.NwpVersion[0], (int)ver.NwpVersion[1], (int)ver.NwpVersion[2], (int)ver.NwpVersion[3]);
+ printf("MAC: %d.%d.%d.%d\n", (int)ver.ChipFwAndPhyVersion.FwVersion[0], (int)ver.ChipFwAndPhyVersion.FwVersion[1],
+ (int)ver.ChipFwAndPhyVersion.FwVersion[2], (int)ver.ChipFwAndPhyVersion.FwVersion[3]);
printf("PHY: %d.%d.%d.%d\n", ver.ChipFwAndPhyVersion.PhyVersion[0], ver.ChipFwAndPhyVersion.PhyVersion[1],
ver.ChipFwAndPhyVersion.PhyVersion[2], ver.ChipFwAndPhyVersion.PhyVersion[3]);
return mp_const_none;
@@ -1289,8 +1279,10 @@ STATIC const mp_map_elem_t wlan_locals_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_WEP), MP_OBJ_NEW_SMALL_INT(SL_SEC_TYPE_WEP) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_WPA), MP_OBJ_NEW_SMALL_INT(SL_SEC_TYPE_WPA_WPA2) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_WPA2), MP_OBJ_NEW_SMALL_INT(SL_SEC_TYPE_WPA_WPA2) },
+ #if MICROPY_HW_ANTENNA_DIVERSITY
{ MP_OBJ_NEW_QSTR(MP_QSTR_INT_ANT), MP_OBJ_NEW_SMALL_INT(ANTENNA_TYPE_INTERNAL) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_EXT_ANT), MP_OBJ_NEW_SMALL_INT(ANTENNA_TYPE_EXTERNAL) },
+ #endif
{ MP_OBJ_NEW_QSTR(MP_QSTR_ANY_EVENT), MP_OBJ_NEW_SMALL_INT(MODWLAN_WIFI_EVENT_ANY) },
};
STATIC MP_DEFINE_CONST_DICT(wlan_locals_dict, wlan_locals_dict_table);
@@ -1310,220 +1302,3 @@ STATIC const mp_irq_methods_t wlan_irq_methods = {
.disable = wlan_lpds_irq_disable,
.flags = wlan_irq_flags,
};
-
-/******************************************************************************/
-// Micro Python bindings; WLAN socket
-
-int wlan_gethostbyname(const char *name, mp_uint_t len, uint8_t *out_ip, uint8_t family) {
- uint32_t ip;
- int result = sl_NetAppDnsGetHostByName((_i8 *)name, (_u16)len, (_u32*)&ip, (_u8)family);
- out_ip[0] = ip;
- out_ip[1] = ip >> 8;
- out_ip[2] = ip >> 16;
- out_ip[3] = ip >> 24;
- return result;
-}
-
-int wlan_socket_socket(mod_network_socket_obj_t *s, int *_errno) {
- int16_t sd = sl_Socket(s->sock_base.u_param.domain, s->sock_base.u_param.type, s->sock_base.u_param.proto);
- if (sd < 0) {
- *_errno = sd;
- return -1;
- }
- s->sock_base.sd = sd;
- return 0;
-}
-
-void wlan_socket_close(mod_network_socket_obj_t *s) {
- // this is to prevent the finalizer to close a socket that failed when being created
- if (s->sock_base.sd >= 0) {
- modusocket_socket_delete(s->sock_base.sd);
- sl_Close(s->sock_base.sd);
- s->sock_base.sd = -1;
- }
-}
-
-int wlan_socket_bind(mod_network_socket_obj_t *s, byte *ip, mp_uint_t port, int *_errno) {
- MAKE_SOCKADDR(addr, ip, port)
- int ret = sl_Bind(s->sock_base.sd, &addr, sizeof(addr));
- if (ret != 0) {
- *_errno = ret;
- return -1;
- }
- return 0;
-}
-
-int wlan_socket_listen(mod_network_socket_obj_t *s, mp_int_t backlog, int *_errno) {
- int ret = sl_Listen(s->sock_base.sd, backlog);
- if (ret != 0) {
- *_errno = ret;
- return -1;
- }
- return 0;
-}
-
-int wlan_socket_accept(mod_network_socket_obj_t *s, mod_network_socket_obj_t *s2, byte *ip, mp_uint_t *port, int *_errno) {
- // accept incoming connection
- int16_t sd;
- sockaddr addr;
- socklen_t addr_len = sizeof(addr);
-
- sd = sl_Accept(s->sock_base.sd, &addr, &addr_len);
- // save the socket descriptor
- s2->sock_base.sd = sd;
- if (sd < 0) {
- *_errno = sd;
- return -1;
- }
-
- // return ip and port
- UNPACK_SOCKADDR(addr, ip, *port);
- return 0;
-}
-
-int wlan_socket_connect(mod_network_socket_obj_t *s, byte *ip, mp_uint_t port, int *_errno) {
- MAKE_SOCKADDR(addr, ip, port)
- int ret = sl_Connect(s->sock_base.sd, &addr, sizeof(addr));
- if (ret != 0) {
- *_errno = ret;
- return -1;
- }
- return 0;
-}
-
-int wlan_socket_send(mod_network_socket_obj_t *s, const byte *buf, mp_uint_t len, int *_errno) {
- mp_int_t bytes = 0;
- if (len > 0) {
- bytes = sl_Send(s->sock_base.sd, (const void *)buf, len, 0);
- }
- if (bytes <= 0) {
- *_errno = bytes;
- return -1;
- }
- return bytes;
-}
-
-int wlan_socket_recv(mod_network_socket_obj_t *s, byte *buf, mp_uint_t len, int *_errno) {
- int ret = sl_Recv(s->sock_base.sd, buf, MIN(len, WLAN_MAX_RX_SIZE), 0);
- if (ret < 0) {
- *_errno = ret;
- return -1;
- }
- return ret;
-}
-
-int wlan_socket_sendto( mod_network_socket_obj_t *s, const byte *buf, mp_uint_t len, byte *ip, mp_uint_t port, int *_errno) {
- MAKE_SOCKADDR(addr, ip, port)
- int ret = sl_SendTo(s->sock_base.sd, (byte*)buf, len, 0, (sockaddr*)&addr, sizeof(addr));
- if (ret < 0) {
- *_errno = ret;
- return -1;
- }
- return ret;
-}
-
-int wlan_socket_recvfrom(mod_network_socket_obj_t *s, byte *buf, mp_uint_t len, byte *ip, mp_uint_t *port, int *_errno) {
- sockaddr addr;
- socklen_t addr_len = sizeof(addr);
- mp_int_t ret = sl_RecvFrom(s->sock_base.sd, buf, MIN(len, WLAN_MAX_RX_SIZE), 0, &addr, &addr_len);
- if (ret < 0) {
- *_errno = ret;
- return -1;
- }
- UNPACK_SOCKADDR(addr, ip, *port);
- return ret;
-}
-
-int wlan_socket_setsockopt(mod_network_socket_obj_t *s, mp_uint_t level, mp_uint_t opt, const void *optval, mp_uint_t optlen, int *_errno) {
- int ret = sl_SetSockOpt(s->sock_base.sd, level, opt, optval, optlen);
- if (ret < 0) {
- *_errno = ret;
- return -1;
- }
- return 0;
-}
-
-int wlan_socket_settimeout(mod_network_socket_obj_t *s, mp_uint_t timeout_s, int *_errno) {
- int ret;
- bool has_timeout;
- if (timeout_s == 0 || timeout_s == -1) {
- SlSockNonblocking_t option;
- if (timeout_s == 0) {
- // set non-blocking mode
- option.NonblockingEnabled = 1;
- } else {
- // set blocking mode
- option.NonblockingEnabled = 0;
- }
- ret = sl_SetSockOpt(s->sock_base.sd, SOL_SOCKET, SO_NONBLOCKING, &option, sizeof(option));
- has_timeout = false;
- } else {
- // set timeout
- struct SlTimeval_t timeVal;
- timeVal.tv_sec = timeout_s; // seconds
- timeVal.tv_usec = 0; // microseconds. 10000 microseconds resolution
- ret = sl_SetSockOpt(s->sock_base.sd, SOL_SOCKET, SO_RCVTIMEO, &timeVal, sizeof(timeVal));
- has_timeout = true;
- }
-
- if (ret != 0) {
- *_errno = ret;
- return -1;
- }
-
- s->sock_base.has_timeout = has_timeout;
- return 0;
-}
-
-int wlan_socket_ioctl (mod_network_socket_obj_t *s, mp_uint_t request, mp_uint_t arg, int *_errno) {
- mp_int_t ret;
- if (request == MP_STREAM_POLL) {
- mp_uint_t flags = arg;
- ret = 0;
- int32_t sd = s->sock_base.sd;
-
- // init fds
- fd_set rfds, wfds, xfds;
- FD_ZERO(&rfds);
- FD_ZERO(&wfds);
- FD_ZERO(&xfds);
-
- // set fds if needed
- if (flags & MP_STREAM_POLL_RD) {
- FD_SET(sd, &rfds);
- }
- if (flags & MP_STREAM_POLL_WR) {
- FD_SET(sd, &wfds);
- }
- if (flags & MP_STREAM_POLL_HUP) {
- FD_SET(sd, &xfds);
- }
-
- // call simplelink's select with minimum timeout
- SlTimeval_t tv;
- tv.tv_sec = 0;
- tv.tv_usec = 1;
- int32_t nfds = sl_Select(sd + 1, &rfds, &wfds, &xfds, &tv);
-
- // check for errors
- if (nfds == -1) {
- *_errno = nfds;
- return -1;
- }
-
- // check return of select
- if (FD_ISSET(sd, &rfds)) {
- ret |= MP_STREAM_POLL_RD;
- }
- if (FD_ISSET(sd, &wfds)) {
- ret |= MP_STREAM_POLL_WR;
- }
- if (FD_ISSET(sd, &xfds)) {
- ret |= MP_STREAM_POLL_HUP;
- }
- } else {
- *_errno = EINVAL;
- ret = MP_STREAM_ERROR;
- }
- return ret;
-}
diff --git a/cc3200/mods/modwlan.h b/cc3200/mods/modwlan.h
index 5899f87b2..3bfd1fbbf 100644
--- a/cc3200/mods/modwlan.h
+++ b/cc3200/mods/modwlan.h
@@ -97,19 +97,4 @@ extern bool wlan_is_connected (void);
extern void wlan_set_current_time (uint32_t seconds_since_2000);
extern void wlan_off_on (void);
-extern int wlan_gethostbyname(const char *name, mp_uint_t len, uint8_t *out_ip, uint8_t family);
-extern int wlan_socket_socket(mod_network_socket_obj_t *s, int *_errno);
-extern void wlan_socket_close(mod_network_socket_obj_t *s);
-extern int wlan_socket_bind(mod_network_socket_obj_t *s, byte *ip, mp_uint_t port, int *_errno);
-extern int wlan_socket_listen(mod_network_socket_obj_t *s, mp_int_t backlog, int *_errno);
-extern int wlan_socket_accept(mod_network_socket_obj_t *s, mod_network_socket_obj_t *s2, byte *ip, mp_uint_t *port, int *_errno);
-extern int wlan_socket_connect(mod_network_socket_obj_t *s, byte *ip, mp_uint_t port, int *_errno);
-extern int wlan_socket_send(mod_network_socket_obj_t *s, const byte *buf, mp_uint_t len, int *_errno);
-extern int wlan_socket_recv(mod_network_socket_obj_t *s, byte *buf, mp_uint_t len, int *_errno);
-extern int wlan_socket_sendto( mod_network_socket_obj_t *s, const byte *buf, mp_uint_t len, byte *ip, mp_uint_t port, int *_errno);
-extern int wlan_socket_recvfrom(mod_network_socket_obj_t *s, byte *buf, mp_uint_t len, byte *ip, mp_uint_t *port, int *_errno);
-extern int wlan_socket_setsockopt(mod_network_socket_obj_t *s, mp_uint_t level, mp_uint_t opt, const void *optval, mp_uint_t optlen, int *_errno);
-extern int wlan_socket_settimeout(mod_network_socket_obj_t *s, mp_uint_t timeout_s, int *_errno);
-extern int wlan_socket_ioctl (mod_network_socket_obj_t *s, mp_uint_t request, mp_uint_t arg, int *_errno);
-
#endif /* MODWLAN_H_ */
diff --git a/cc3200/mods/pybadc.c b/cc3200/mods/pybadc.c
index e63bebbd0..696e7650b 100644
--- a/cc3200/mods/pybadc.c
+++ b/cc3200/mods/pybadc.c
@@ -33,6 +33,7 @@
#include "py/runtime.h"
#include "py/binary.h"
#include "py/gc.h"
+#include "py/mperrno.h"
#include "bufhelper.h"
#include "inc/hw_types.h"
#include "inc/hw_adc.h"
@@ -104,7 +105,7 @@ STATIC void pyb_adc_init (pyb_adc_obj_t *self) {
STATIC void pyb_adc_check_init(void) {
// not initialized
if (!pyb_adc_obj.enabled) {
- mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible);
+ mp_raise_OSError(MP_EPERM);
}
}
@@ -149,7 +150,7 @@ STATIC mp_obj_t adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_
// check the peripheral id
if (args[0].u_int != 0) {
- mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable);
+ mp_raise_OSError(MP_ENODEV);
}
// check the number of bits
@@ -206,7 +207,7 @@ STATIC mp_obj_t adc_channel(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t
if (args[0].u_obj != MP_OBJ_NULL) {
ch_id = mp_obj_get_int(args[0].u_obj);
if (ch_id >= PYB_ADC_NUM_CHANNELS) {
- mp_raise_ValueError(mpexception_os_resource_not_avaliable);
+ mp_raise_ValueError(mpexception_value_invalid_arguments);
} else if (args[1].u_obj != mp_const_none) {
uint pin_ch_id = pin_find_peripheral_type (args[1].u_obj, PIN_FN_ADC, 0);
if (ch_id != pin_ch_id) {
@@ -277,7 +278,7 @@ STATIC mp_obj_t adc_channel_value(mp_obj_t self_in) {
// the channel must be enabled
if (!self->enabled) {
- mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible);
+ mp_raise_OSError(MP_EPERM);
}
// wait until a new value is available
diff --git a/cc3200/mods/pybflash.c b/cc3200/mods/pybflash.c
new file mode 100644
index 000000000..f5af79dbf
--- /dev/null
+++ b/cc3200/mods/pybflash.c
@@ -0,0 +1,109 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2013-2017 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.
+ */
+
+//#include <stdint.h>
+//#include <string.h>
+
+#include "py/runtime.h"
+#include "lib/oofatfs/ff.h"
+#include "lib/oofatfs/diskio.h"
+#include "extmod/vfs_fat.h"
+
+#include "fatfs/src/drivers/sflash_diskio.h"
+#include "mods/pybflash.h"
+
+/******************************************************************************/
+// MicroPython bindings to expose the internal flash as an object with the
+// block protocol.
+
+// there is a singleton Flash object
+STATIC const mp_obj_base_t pyb_flash_obj = {&pyb_flash_type};
+
+STATIC mp_obj_t pyb_flash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
+ // check arguments
+ mp_arg_check_num(n_args, n_kw, 0, 0, false);
+
+ // return singleton object
+ return (mp_obj_t)&pyb_flash_obj;
+}
+
+STATIC mp_obj_t pyb_flash_readblocks(mp_obj_t self, mp_obj_t block_num, mp_obj_t buf) {
+ mp_buffer_info_t bufinfo;
+ mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_WRITE);
+ DRESULT res = sflash_disk_read(bufinfo.buf, mp_obj_get_int(block_num), bufinfo.len / SFLASH_SECTOR_SIZE);
+ return MP_OBJ_NEW_SMALL_INT(res != RES_OK); // return of 0 means success
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_flash_readblocks_obj, pyb_flash_readblocks);
+
+STATIC mp_obj_t pyb_flash_writeblocks(mp_obj_t self, mp_obj_t block_num, mp_obj_t buf) {
+ mp_buffer_info_t bufinfo;
+ mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ);
+ DRESULT res = sflash_disk_write(bufinfo.buf, mp_obj_get_int(block_num), bufinfo.len / SFLASH_SECTOR_SIZE);
+ return MP_OBJ_NEW_SMALL_INT(res != RES_OK); // return of 0 means success
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_flash_writeblocks_obj, pyb_flash_writeblocks);
+
+STATIC mp_obj_t pyb_flash_ioctl(mp_obj_t self, mp_obj_t cmd_in, mp_obj_t arg_in) {
+ mp_int_t cmd = mp_obj_get_int(cmd_in);
+ switch (cmd) {
+ case BP_IOCTL_INIT: return MP_OBJ_NEW_SMALL_INT(sflash_disk_init() != RES_OK);
+ case BP_IOCTL_DEINIT: sflash_disk_flush(); return MP_OBJ_NEW_SMALL_INT(0);
+ case BP_IOCTL_SYNC: sflash_disk_flush(); return MP_OBJ_NEW_SMALL_INT(0);
+ case BP_IOCTL_SEC_COUNT: return MP_OBJ_NEW_SMALL_INT(SFLASH_SECTOR_COUNT);
+ case BP_IOCTL_SEC_SIZE: return MP_OBJ_NEW_SMALL_INT(SFLASH_SECTOR_SIZE);
+ default: return mp_const_none;
+ }
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_flash_ioctl_obj, pyb_flash_ioctl);
+
+STATIC const mp_map_elem_t pyb_flash_locals_dict_table[] = {
+ { MP_OBJ_NEW_QSTR(MP_QSTR_readblocks), (mp_obj_t)&pyb_flash_readblocks_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_writeblocks), (mp_obj_t)&pyb_flash_writeblocks_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_ioctl), (mp_obj_t)&pyb_flash_ioctl_obj },
+};
+
+STATIC MP_DEFINE_CONST_DICT(pyb_flash_locals_dict, pyb_flash_locals_dict_table);
+
+const mp_obj_type_t pyb_flash_type = {
+ { &mp_type_type },
+ .name = MP_QSTR_Flash,
+ .make_new = pyb_flash_make_new,
+ .locals_dict = (mp_obj_t)&pyb_flash_locals_dict,
+};
+
+void pyb_flash_init_vfs(fs_user_mount_t *vfs) {
+ vfs->base.type = &mp_fat_vfs_type;
+ vfs->flags |= FSUSER_NATIVE | FSUSER_HAVE_IOCTL;
+ vfs->fatfs.drv = vfs;
+ vfs->readblocks[0] = (mp_obj_t)&pyb_flash_readblocks_obj;
+ vfs->readblocks[1] = (mp_obj_t)&pyb_flash_obj;
+ vfs->readblocks[2] = (mp_obj_t)sflash_disk_read; // native version
+ vfs->writeblocks[0] = (mp_obj_t)&pyb_flash_writeblocks_obj;
+ vfs->writeblocks[1] = (mp_obj_t)&pyb_flash_obj;
+ vfs->writeblocks[2] = (mp_obj_t)sflash_disk_write; // native version
+ vfs->u.ioctl[0] = (mp_obj_t)&pyb_flash_ioctl_obj;
+ vfs->u.ioctl[1] = (mp_obj_t)&pyb_flash_obj;
+}
diff --git a/cc3200/misc/mpsystick.h b/cc3200/mods/pybflash.h
index d7ad59461..6f8ddf291 100644
--- a/cc3200/misc/mpsystick.h
+++ b/cc3200/mods/pybflash.h
@@ -1,10 +1,9 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
- * Copyright (c) 2013, 2014 Damien P. George
- * Copyright (c) 2015 Daniel Campora
+ * Copyright (c) 2017 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
@@ -24,12 +23,13 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
+#ifndef MICROPY_INCLUDED_CC3200_MODS_PYBFLASH_H
+#define MICROPY_INCLUDED_CC3200_MODS_PYBFLASH_H
-#ifndef MPSYSTICK_H
-#define MPSYSTICK_H
+#include "py/obj.h"
-void sys_tick_wait_at_least(uint32_t stc, uint32_t delay_ms);
-bool sys_tick_has_passed(uint32_t stc, uint32_t delay_ms);
-uint32_t sys_tick_get_microseconds(void);
+extern const mp_obj_type_t pyb_flash_type;
-#endif // MPSYSTICK_H
+void pyb_flash_init_vfs(fs_user_mount_t *vfs);
+
+#endif // MICROPY_INCLUDED_CC3200_MODS_PYBFLASH_H
diff --git a/cc3200/mods/pybi2c.c b/cc3200/mods/pybi2c.c
index 32451802d..9fc97d914 100644
--- a/cc3200/mods/pybi2c.c
+++ b/cc3200/mods/pybi2c.c
@@ -30,6 +30,7 @@
#include "py/mpstate.h"
#include "py/runtime.h"
+#include "py/mperrno.h"
#include "py/mphal.h"
#include "bufhelper.h"
#include "inc/hw_types.h"
@@ -58,8 +59,6 @@ typedef struct _pyb_i2c_obj_t {
/******************************************************************************
DEFINE CONSTANTS
******************************************************************************/
-#define PYBI2C_MASTER (0)
-
#define PYBI2C_MIN_BAUD_RATE_HZ (50000)
#define PYBI2C_MAX_BAUD_RATE_HZ (400000)
@@ -78,7 +77,6 @@ typedef struct _pyb_i2c_obj_t {
DECLARE PRIVATE DATA
******************************************************************************/
STATIC pyb_i2c_obj_t pyb_i2c_obj = {.baudrate = 0};
-STATIC const mp_obj_t pyb_i2c_def_pin[2] = {&pin_GP13, &pin_GP23};
/******************************************************************************
DECLARE PRIVATE FUNCTIONS
@@ -144,7 +142,7 @@ STATIC bool pyb_i2c_transaction(uint cmd) {
STATIC void pyb_i2c_check_init(pyb_i2c_obj_t *self) {
// not initialized
if (!self->baudrate) {
- mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible);
+ mp_raise_OSError(MP_EPERM);
}
}
@@ -256,7 +254,7 @@ STATIC void pyb_i2c_read_into (mp_arg_val_t *args, vstr_t *vstr) {
// receive the data
if (!pyb_i2c_read(args[0].u_int, (byte *)vstr->buf, vstr->len)) {
- mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed);
+ mp_raise_OSError(MP_EIO);
}
}
@@ -275,8 +273,10 @@ STATIC void pyb_i2c_readmem_into (mp_arg_val_t *args, vstr_t *vstr) {
if (pyb_i2c_mem_addr_write (i2c_addr, (byte *)&mem_addr, mem_addr_size)) {
// Read the specified length of data
if (!pyb_i2c_read (i2c_addr, (byte *)vstr->buf, vstr->len)) {
- mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed);
+ mp_raise_OSError(MP_EIO);
}
+ } else {
+ mp_raise_OSError(MP_EIO);
}
}
@@ -286,33 +286,34 @@ STATIC void pyb_i2c_readmem_into (mp_arg_val_t *args, vstr_t *vstr) {
STATIC void pyb_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
pyb_i2c_obj_t *self = self_in;
if (self->baudrate > 0) {
- mp_printf(print, "I2C(0, I2C.MASTER, baudrate=%u)", self->baudrate);
+ mp_printf(print, "I2C(0, baudrate=%u)", self->baudrate);
} else {
mp_print_str(print, "I2C(0)");
}
}
-STATIC mp_obj_t pyb_i2c_init_helper(pyb_i2c_obj_t *self, const mp_arg_val_t *args) {
- // verify that mode is master
- if (args[0].u_int != PYBI2C_MASTER) {
- goto invalid_args;
- }
+STATIC mp_obj_t pyb_i2c_init_helper(pyb_i2c_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+ enum { ARG_scl, ARG_sda, ARG_freq };
+ static const mp_arg_t allowed_args[] = {
+ { MP_QSTR_scl, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
+ { MP_QSTR_sda, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
+ { MP_QSTR_freq, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 100000} },
+ };
+ mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
+ mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
// make sure the baudrate is between the valid range
- self->baudrate = MIN(MAX(args[1].u_int, PYBI2C_MIN_BAUD_RATE_HZ), PYBI2C_MAX_BAUD_RATE_HZ);
+ self->baudrate = MIN(MAX(args[ARG_freq].u_int, PYBI2C_MIN_BAUD_RATE_HZ), PYBI2C_MAX_BAUD_RATE_HZ);
// assign the pins
- mp_obj_t pins_o = args[2].u_obj;
- if (pins_o != mp_const_none) {
- mp_obj_t *pins;
- if (pins_o == MP_OBJ_NULL) {
- // use the default pins
- pins = (mp_obj_t *)pyb_i2c_def_pin;
- } else {
- mp_obj_get_array_fixed_n(pins_o, 2, &pins);
- }
- pin_assign_pins_af (pins, 2, PIN_TYPE_STD_PU, PIN_FN_I2C, 0);
+ mp_obj_t pins[2] = {&pin_GP13, &pin_GP23}; // default (SDA, SCL) pins
+ if (args[ARG_scl].u_obj != MP_OBJ_NULL) {
+ pins[1] = args[ARG_scl].u_obj;
+ }
+ if (args[ARG_sda].u_obj != MP_OBJ_NULL) {
+ pins[0] = args[ARG_sda].u_obj;
}
+ pin_assign_pins_af(pins, 2, PIN_TYPE_STD_PU, PIN_FN_I2C, 0);
// init the I2C bus
i2c_init(self);
@@ -321,44 +322,34 @@ STATIC mp_obj_t pyb_i2c_init_helper(pyb_i2c_obj_t *self, const mp_arg_val_t *arg
pyb_sleep_add ((const mp_obj_t)self, (WakeUpCB_t)i2c_init);
return mp_const_none;
-
-invalid_args:
- mp_raise_ValueError(mpexception_value_invalid_arguments);
}
-STATIC const mp_arg_t pyb_i2c_init_args[] = {
- { MP_QSTR_id, MP_ARG_INT, {.u_int = 0} },
- { MP_QSTR_mode, MP_ARG_INT, {.u_int = PYBI2C_MASTER} },
- { MP_QSTR_baudrate, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 100000} },
- { MP_QSTR_pins, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
-};
STATIC mp_obj_t pyb_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
+ // check the id argument, if given
+ if (n_args > 0) {
+ if (all_args[0] != MP_OBJ_NEW_SMALL_INT(0)) {
+ mp_raise_OSError(MP_ENODEV);
+ }
+ --n_args;
+ ++all_args;
+ }
+
// parse args
mp_map_t kw_args;
mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args);
- mp_arg_val_t args[MP_ARRAY_SIZE(pyb_i2c_init_args)];
- mp_arg_parse_all(n_args, all_args, &kw_args, MP_ARRAY_SIZE(args), pyb_i2c_init_args, args);
-
- // check the peripheral id
- if (args[0].u_int != 0) {
- mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable);
- }
// setup the object
pyb_i2c_obj_t *self = &pyb_i2c_obj;
self->base.type = &pyb_i2c_type;
// start the peripheral
- pyb_i2c_init_helper(self, &args[1]);
+ pyb_i2c_init_helper(self, n_args, all_args, &kw_args);
return (mp_obj_t)self;
}
-STATIC mp_obj_t pyb_i2c_init(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
- // parse args
- mp_arg_val_t args[MP_ARRAY_SIZE(pyb_i2c_init_args) - 1];
- mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(args), &pyb_i2c_init_args[1], args);
- return pyb_i2c_init_helper(pos_args[0], args);
+STATIC mp_obj_t pyb_i2c_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+ return pyb_i2c_init_helper(pos_args[0], n_args - 1, pos_args + 1, kw_args);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_init_obj, 1, pyb_i2c_init);
@@ -445,7 +436,7 @@ STATIC mp_obj_t pyb_i2c_writeto(mp_uint_t n_args, const mp_obj_t *pos_args, mp_m
// send the data
if (!pyb_i2c_write(args[0].u_int, bufinfo.buf, bufinfo.len, args[2].u_bool)) {
- mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed);
+ mp_raise_OSError(MP_EIO);
}
// return the number of bytes written
@@ -486,7 +477,7 @@ STATIC mp_obj_t pyb_i2c_readfrom_mem_into(mp_uint_t n_args, const mp_obj_t *pos_
// get the buffer to read into
vstr_t vstr;
pyb_i2c_readmem_into (args, &vstr);
- return mp_obj_new_int(vstr.len);
+ return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_readfrom_mem_into_obj, 1, pyb_i2c_readfrom_mem_into);
@@ -510,11 +501,10 @@ STATIC mp_obj_t pyb_i2c_writeto_mem(mp_uint_t n_args, const mp_obj_t *pos_args,
// write the register address to write to.
if (pyb_i2c_mem_write (i2c_addr, (byte *)&mem_addr, mem_addr_size, bufinfo.buf, bufinfo.len)) {
- // return the number of bytes written
- return mp_obj_new_int(bufinfo.len);
+ return mp_const_none;
}
- mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed);
+ mp_raise_OSError(MP_EIO);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_writeto_mem_obj, 1, pyb_i2c_writeto_mem);
@@ -529,9 +519,6 @@ STATIC const mp_map_elem_t pyb_i2c_locals_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_readfrom_mem), (mp_obj_t)&pyb_i2c_readfrom_mem_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_readfrom_mem_into), (mp_obj_t)&pyb_i2c_readfrom_mem_into_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_writeto_mem), (mp_obj_t)&pyb_i2c_writeto_mem_obj },
-
- // class constants
- { MP_OBJ_NEW_QSTR(MP_QSTR_MASTER), MP_OBJ_NEW_SMALL_INT(PYBI2C_MASTER) },
};
STATIC MP_DEFINE_CONST_DICT(pyb_i2c_locals_dict, pyb_i2c_locals_dict_table);
diff --git a/cc3200/mods/pybpin.c b/cc3200/mods/pybpin.c
index ac0ecef25..c2a469117 100644
--- a/cc3200/mods/pybpin.c
+++ b/cc3200/mods/pybpin.c
@@ -684,13 +684,6 @@ STATIC mp_obj_t pin_value(mp_uint_t n_args, const mp_obj_t *args) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_value_obj, 1, 2, pin_value);
-STATIC mp_obj_t pin_toggle(mp_obj_t self_in) {
- pin_obj_t *self = self_in;
- MAP_GPIOPinWrite(self->port, self->bit, ~MAP_GPIOPinRead(self->port, self->bit));
- return mp_const_none;
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_toggle_obj, pin_toggle);
-
STATIC mp_obj_t pin_id(mp_obj_t self_in) {
pin_obj_t *self = self_in;
return MP_OBJ_NEW_QSTR(self->name);
@@ -913,7 +906,6 @@ STATIC const mp_map_elem_t pin_locals_dict_table[] = {
// instance methods
{ MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&pin_init_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_value), (mp_obj_t)&pin_value_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_toggle), (mp_obj_t)&pin_toggle_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_id), (mp_obj_t)&pin_id_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_mode), (mp_obj_t)&pin_mode_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_pull), (mp_obj_t)&pin_pull_obj },
diff --git a/cc3200/mods/pybrtc.c b/cc3200/mods/pybrtc.c
index db00f4939..134bd440e 100644
--- a/cc3200/mods/pybrtc.c
+++ b/cc3200/mods/pybrtc.c
@@ -25,11 +25,11 @@
* THE SOFTWARE.
*/
-#include <std.h>
-
#include "py/mpconfig.h"
#include "py/obj.h"
#include "py/runtime.h"
+#include "py/mperrno.h"
+#include "lib/timeutils/timeutils.h"
#include "inc/hw_types.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
@@ -38,7 +38,6 @@
#include "pybrtc.h"
#include "mpirq.h"
#include "pybsleep.h"
-#include "timeutils.h"
#include "simplelink.h"
#include "modnetwork.h"
#include "modwlan.h"
@@ -197,7 +196,7 @@ STATIC uint pyb_rtc_datetime_s_us(const mp_obj_t datetime, uint32_t *seconds) {
// set date and time
mp_obj_t *items;
- uint len;
+ size_t len;
mp_obj_get_array(datetime, &len, &items);
// verify the tuple
@@ -294,7 +293,7 @@ STATIC mp_obj_t pyb_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_
// check the peripheral id
if (args[0].u_int != 0) {
- mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable);
+ mp_raise_OSError(MP_ENODEV);
}
// setup the object
@@ -362,7 +361,7 @@ STATIC mp_obj_t pyb_rtc_alarm (mp_uint_t n_args, const mp_obj_t *pos_args, mp_ma
// check the alarm id
if (args[0].u_int != 0) {
- mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable);
+ mp_raise_OSError(MP_ENODEV);
}
uint32_t f_seconds;
@@ -397,7 +396,7 @@ STATIC mp_obj_t pyb_rtc_alarm_left (mp_uint_t n_args, const mp_obj_t *args) {
// only alarm id 0 is available
if (n_args > 1 && mp_obj_get_int(args[1]) != 0) {
- mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable);
+ mp_raise_OSError(MP_ENODEV);
}
// get the current time
@@ -415,7 +414,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_rtc_alarm_left_obj, 1, 2, pyb_rtc
STATIC mp_obj_t pyb_rtc_alarm_cancel (mp_uint_t n_args, const mp_obj_t *args) {
// only alarm id 0 is available
if (n_args > 1 && mp_obj_get_int(args[1]) != 0) {
- mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable);
+ mp_raise_OSError(MP_ENODEV);
}
// disable the alarm
pyb_rtc_disable_alarm();
diff --git a/cc3200/mods/pybsd.c b/cc3200/mods/pybsd.c
index b8d5b4cc1..306baea8b 100644
--- a/cc3200/mods/pybsd.c
+++ b/cc3200/mods/pybsd.c
@@ -27,6 +27,10 @@
#include "py/mpconfig.h"
#include "py/obj.h"
#include "py/runtime.h"
+#include "py/mperrno.h"
+#include "lib/oofatfs/ff.h"
+#include "lib/oofatfs/diskio.h"
+#include "extmod/vfs_fat.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "inc/hw_ints.h"
@@ -36,8 +40,6 @@
#include "prcm.h"
#include "gpio.h"
#include "sdhost.h"
-#include "ff.h"
-#include "diskio.h"
#include "sd_diskio.h"
#include "pybsd.h"
#include "mpexception.h"
@@ -107,7 +109,7 @@ STATIC mp_obj_t pyb_sd_init_helper (pybsd_obj_t *self, const mp_arg_val_t *args)
pyb_sd_hw_init (self);
if (sd_disk_init() != 0) {
- mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed);
+ mp_raise_OSError(MP_EIO);
}
// register it with the sleep module
@@ -132,7 +134,7 @@ STATIC mp_obj_t pyb_sd_make_new(const mp_obj_type_t *type, size_t n_args, size_t
// check the peripheral id
if (args[0].u_int != 0) {
- mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable);
+ mp_raise_OSError(MP_ENODEV);
}
// setup and initialize the object
@@ -163,9 +165,50 @@ STATIC mp_obj_t pyb_sd_deinit (mp_obj_t self_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_sd_deinit_obj, pyb_sd_deinit);
+STATIC mp_obj_t pyb_sd_readblocks(mp_obj_t self, mp_obj_t block_num, mp_obj_t buf) {
+ mp_buffer_info_t bufinfo;
+ mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_WRITE);
+ DRESULT res = sd_disk_read(bufinfo.buf, mp_obj_get_int(block_num), bufinfo.len / SD_SECTOR_SIZE);
+ return MP_OBJ_NEW_SMALL_INT(res != RES_OK); // return of 0 means success
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_sd_readblocks_obj, pyb_sd_readblocks);
+
+STATIC mp_obj_t pyb_sd_writeblocks(mp_obj_t self, mp_obj_t block_num, mp_obj_t buf) {
+ mp_buffer_info_t bufinfo;
+ mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ);
+ DRESULT res = sd_disk_write(bufinfo.buf, mp_obj_get_int(block_num), bufinfo.len / SD_SECTOR_SIZE);
+ return MP_OBJ_NEW_SMALL_INT(res != RES_OK); // return of 0 means success
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_sd_writeblocks_obj, pyb_sd_writeblocks);
+
+STATIC mp_obj_t pyb_sd_ioctl(mp_obj_t self, mp_obj_t cmd_in, mp_obj_t arg_in) {
+ mp_int_t cmd = mp_obj_get_int(cmd_in);
+ switch (cmd) {
+ case BP_IOCTL_INIT:
+ case BP_IOCTL_DEINIT:
+ case BP_IOCTL_SYNC:
+ // nothing to do
+ return MP_OBJ_NEW_SMALL_INT(0); // success
+
+ case BP_IOCTL_SEC_COUNT:
+ return MP_OBJ_NEW_SMALL_INT(sd_disk_info.ulNofBlock * (sd_disk_info.ulBlockSize / 512));
+
+ case BP_IOCTL_SEC_SIZE:
+ return MP_OBJ_NEW_SMALL_INT(SD_SECTOR_SIZE);
+
+ default: // unknown command
+ return MP_OBJ_NEW_SMALL_INT(-1); // error
+ }
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_sd_ioctl_obj, pyb_sd_ioctl);
+
STATIC const mp_map_elem_t pyb_sd_locals_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&pyb_sd_init_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_deinit), (mp_obj_t)&pyb_sd_deinit_obj },
+ // block device protocol
+ { MP_OBJ_NEW_QSTR(MP_QSTR_readblocks), (mp_obj_t)&pyb_sd_readblocks_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_writeblocks), (mp_obj_t)&pyb_sd_writeblocks_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_ioctl), (mp_obj_t)&pyb_sd_ioctl_obj },
};
STATIC MP_DEFINE_CONST_DICT(pyb_sd_locals_dict, pyb_sd_locals_dict_table);
diff --git a/cc3200/mods/pybspi.c b/cc3200/mods/pybspi.c
index 6fc7ee62d..3cd384266 100644
--- a/cc3200/mods/pybspi.c
+++ b/cc3200/mods/pybspi.c
@@ -30,6 +30,7 @@
#include "py/mpstate.h"
#include "py/runtime.h"
+#include "py/mperrno.h"
#include "bufhelper.h"
#include "inc/hw_types.h"
#include "inc/hw_mcspi.h"
@@ -131,7 +132,7 @@ STATIC void pybspi_rx (pyb_spi_obj_t *self, void *data) {
STATIC void pybspi_transfer (pyb_spi_obj_t *self, const char *txdata, char *rxdata, uint32_t len, uint32_t *txchar) {
if (!self->baudrate) {
- mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible);
+ mp_raise_OSError(MP_EPERM);
}
// send and receive the data
MAP_SPICSEnable(GSPI_BASE);
@@ -234,7 +235,7 @@ STATIC mp_obj_t pyb_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_
// check the peripheral id
if (args[0].u_int != 0) {
- mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable);
+ mp_raise_OSError(MP_ENODEV);
}
// setup the object
diff --git a/cc3200/mods/pybtimer.c b/cc3200/mods/pybtimer.c
index 0eeb6eefd..d25ac6c2b 100644
--- a/cc3200/mods/pybtimer.c
+++ b/cc3200/mods/pybtimer.c
@@ -34,6 +34,7 @@
#include "py/nlr.h"
#include "py/runtime.h"
#include "py/gc.h"
+#include "py/mperrno.h"
#include "py/mphal.h"
#include "inc/hw_types.h"
#include "inc/hw_ints.h"
@@ -329,7 +330,7 @@ STATIC mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, size_t n_args, siz
// create a new Timer object
int32_t timer_idx = mp_obj_get_int(args[0]);
if (timer_idx < 0 || timer_idx > (PYBTIMER_NUM_TIMERS - 1)) {
- mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable);
+ mp_raise_OSError(MP_ENODEV);
}
pyb_timer_obj_t *tim = &pyb_timer_obj[timer_idx];
@@ -370,7 +371,7 @@ STATIC mp_obj_t pyb_timer_channel(mp_uint_t n_args, const mp_obj_t *pos_args, mp
// verify that the timer has been already initialized
if (!tim->config) {
- mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible);
+ mp_raise_OSError(MP_EPERM);
}
if (channel_n != TIMER_A && channel_n != TIMER_B && channel_n != (TIMER_A | TIMER_B)) {
// invalid channel
diff --git a/cc3200/mods/pybuart.c b/cc3200/mods/pybuart.c
index fe710be92..92bb3e46e 100644
--- a/cc3200/mods/pybuart.c
+++ b/cc3200/mods/pybuart.c
@@ -279,7 +279,7 @@ STATIC void UARTGenericIntHandler(uint32_t uart_id) {
STATIC void uart_check_init(pyb_uart_obj_t *self) {
// not initialized
if (!self->baudrate) {
- mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible);
+ mp_raise_OSError(MP_EPERM);
}
}
@@ -375,10 +375,13 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, const mp_arg_val_t *a
config |= UART_CONFIG_PAR_NONE;
} else {
uint parity = mp_obj_get_int(args[2].u_obj);
- if (parity != UART_CONFIG_PAR_ODD && parity != UART_CONFIG_PAR_EVEN) {
+ if (parity == 0) {
+ config |= UART_CONFIG_PAR_EVEN;
+ } else if (parity == 1) {
+ config |= UART_CONFIG_PAR_ODD;
+ } else {
goto error;
}
- config |= parity;
}
// stop bits
config |= (args[3].u_int == 1 ? UART_CONFIG_STOP_ONE : UART_CONFIG_STOP_TWO);
@@ -388,7 +391,7 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, const mp_arg_val_t *a
uint flowcontrol = UART_FLOWCONTROL_NONE;
if (pins_o != mp_const_none) {
mp_obj_t *pins;
- mp_uint_t n_pins = 2;
+ size_t n_pins = 2;
if (pins_o == MP_OBJ_NULL) {
// use the default pins
pins = (mp_obj_t *)pyb_uart_def_pin[self->uart_id];
@@ -454,7 +457,7 @@ STATIC mp_obj_t pyb_uart_make_new(const mp_obj_type_t *type, size_t n_args, size
if (args[0].u_obj == MP_OBJ_NULL) {
if (args[5].u_obj != MP_OBJ_NULL) {
mp_obj_t *pins;
- mp_uint_t n_pins = 2;
+ size_t n_pins = 2;
mp_obj_get_array(args[5].u_obj, &n_pins, &pins);
// check the Tx pin (or the Rx if Tx is None)
if (pins[0] == mp_const_none) {
@@ -471,7 +474,7 @@ STATIC mp_obj_t pyb_uart_make_new(const mp_obj_type_t *type, size_t n_args, size
}
if (uart_id > PYB_UART_1) {
- mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable);
+ mp_raise_OSError(MP_ENODEV);
}
// get the correct uart instance
@@ -577,8 +580,6 @@ STATIC const mp_map_elem_t pyb_uart_locals_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&mp_stream_write_obj },
// class constants
- { MP_OBJ_NEW_QSTR(MP_QSTR_EVEN), MP_OBJ_NEW_SMALL_INT(UART_CONFIG_PAR_EVEN) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_ODD), MP_OBJ_NEW_SMALL_INT(UART_CONFIG_PAR_ODD) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_RX_ANY), MP_OBJ_NEW_SMALL_INT(UART_TRIGGER_RX_ANY) },
};
@@ -596,8 +597,8 @@ STATIC mp_uint_t pyb_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, i
// wait for first char to become available
if (!uart_rx_wait(self)) {
- // return EAGAIN error to indicate non-blocking (then read() method returns None)
- *errcode = EAGAIN;
+ // return MP_EAGAIN error to indicate non-blocking (then read() method returns None)
+ *errcode = MP_EAGAIN;
return MP_STREAM_ERROR;
}
@@ -619,7 +620,7 @@ STATIC mp_uint_t pyb_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t
// write the data
if (!uart_tx_strn(self, buf, size)) {
- mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed);
+ mp_raise_OSError(MP_EIO);
}
return size;
}
@@ -639,7 +640,7 @@ STATIC mp_uint_t pyb_uart_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t a
ret |= MP_STREAM_POLL_WR;
}
} else {
- *errcode = EINVAL;
+ *errcode = MP_EINVAL;
ret = MP_STREAM_ERROR;
}
return ret;
@@ -664,7 +665,7 @@ const mp_obj_type_t pyb_uart_type = {
.name = MP_QSTR_UART,
.print = pyb_uart_print,
.make_new = pyb_uart_make_new,
- .getiter = mp_identity,
+ .getiter = mp_identity_getiter,
.iternext = mp_stream_unbuffered_iter,
.protocol = &uart_stream_p,
.locals_dict = (mp_obj_t)&pyb_uart_locals_dict,
diff --git a/cc3200/mods/pybwdt.c b/cc3200/mods/pybwdt.c
index b4c847268..76c701ca0 100644
--- a/cc3200/mods/pybwdt.c
+++ b/cc3200/mods/pybwdt.c
@@ -29,6 +29,7 @@
#include "py/mpconfig.h"
#include "py/obj.h"
#include "py/runtime.h"
+#include "py/mperrno.h"
#include "py/mphal.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
@@ -100,14 +101,14 @@ STATIC mp_obj_t pyb_wdt_make_new(const mp_obj_type_t *type, size_t n_args, size_
mp_arg_parse_all(n_args, all_args, &kw_args, MP_ARRAY_SIZE(args), pyb_wdt_init_args, args);
if (args[0].u_obj != mp_const_none && mp_obj_get_int(args[0].u_obj) > 0) {
- mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable);
+ mp_raise_OSError(MP_ENODEV);
}
uint timeout_ms = args[1].u_int;
if (timeout_ms < PYBWDT_MIN_TIMEOUT_MS) {
mp_raise_ValueError(mpexception_value_invalid_arguments);
}
if (pyb_wdt_obj.running) {
- mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible);
+ mp_raise_OSError(MP_EPERM);
}
// Enable the WDT peripheral clock
diff --git a/cc3200/mpconfigport.h b/cc3200/mpconfigport.h
index 5b6a035d5..4bd583a4b 100644
--- a/cc3200/mpconfigport.h
+++ b/cc3200/mpconfigport.h
@@ -55,7 +55,7 @@
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_NONE)
#define MICROPY_OPT_COMPUTED_GOTO (0)
#define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE (0)
-#define MICROPY_READER_FATFS (1)
+#define MICROPY_READER_VFS (1)
#ifndef DEBUG // we need ram on the launchxl while debugging
#define MICROPY_CPYTHON_COMPAT (1)
#else
@@ -68,18 +68,21 @@
#define MICROPY_FATFS_MAX_LFN (MICROPY_ALLOC_PATH_MAX)
#define MICROPY_FATFS_LFN_CODE_PAGE (437) // 1=SFN/ANSI 437=LFN/U.S.(OEM)
#define MICROPY_FATFS_RPATH (2)
-#define MICROPY_FATFS_VOLUMES (2)
#define MICROPY_FATFS_REENTRANT (1)
#define MICROPY_FATFS_TIMEOUT (2500)
#define MICROPY_FATFS_SYNC_T SemaphoreHandle_t
-#define MICROPY_FSUSERMOUNT_ADHOC (1)
#define MICROPY_STREAMS_NON_BLOCK (1)
#define MICROPY_MODULE_WEAK_LINKS (1)
#define MICROPY_CAN_OVERRIDE_BUILTINS (1)
+#define MICROPY_USE_INTERNAL_ERRNO (1)
+#define MICROPY_VFS (1)
+#define MICROPY_VFS_FAT (1)
#define MICROPY_PY_ASYNC_AWAIT (0)
-#define MICROPY_PY_BUILTINS_TIMEOUTERROR (1)
#define MICROPY_PY_ALL_SPECIAL_METHODS (1)
+#define MICROPY_PY_BUILTINS_INPUT (1)
+#define MICROPY_PY_BUILTINS_HELP (1)
+#define MICROPY_PY_BUILTINS_HELP_TEXT cc3200_help_text
#ifndef DEBUG
#define MICROPY_PY_BUILTINS_STR_UNICODE (1)
#define MICROPY_PY_BUILTINS_STR_SPLITLINES (1)
@@ -104,6 +107,8 @@
#define MICROPY_PY_CMATH (0)
#define MICROPY_PY_IO (1)
#define MICROPY_PY_IO_FILEIO (1)
+#define MICROPY_PY_UERRNO (1)
+#define MICROPY_PY_UERRNO_ERRORCODE (0)
#define MICROPY_PY_THREAD (1)
#define MICROPY_PY_THREAD_GIL (1)
#define MICROPY_PY_UBINASCII (0)
@@ -114,14 +119,30 @@
#define MICROPY_PY_UHEAPQ (0)
#define MICROPY_PY_UHASHLIB (0)
#define MICROPY_PY_USELECT (1)
+#define MICROPY_PY_UTIME_MP_HAL (1)
#define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1)
#define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (0)
+// We define our own list of errno constants to include in uerrno module
+#define MICROPY_PY_UERRNO_LIST \
+ X(EPERM) \
+ X(EIO) \
+ X(ENODEV) \
+ X(EINVAL) \
+ X(ETIMEDOUT) \
+
+// TODO these should be generic, not bound to fatfs
+#define mp_type_fileio fatfs_type_fileio
+#define mp_type_textio fatfs_type_textio
+
+// use vfs's functions for import stat and builtin open
+#define mp_import_stat mp_vfs_import_stat
+#define mp_builtin_open mp_vfs_open
+#define mp_builtin_open_obj mp_vfs_open_obj
+
// extra built in names to add to the global namespace
#define MICROPY_PORT_BUILTINS \
- { MP_OBJ_NEW_QSTR(MP_QSTR_help), (mp_obj_t)&mp_builtin_help_obj }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_input), (mp_obj_t)&mp_builtin_input_obj }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj }, \
// extra built in modules to add to the list of known ones
@@ -149,6 +170,7 @@ extern const struct _mp_obj_module_t mp_module_ussl;
{ MP_OBJ_NEW_QSTR(MP_QSTR_ussl), (mp_obj_t)&mp_module_ussl }, \
#define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS \
+ { MP_OBJ_NEW_QSTR(MP_QSTR_errno), (mp_obj_t)&mp_module_uerrno }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_struct), (mp_obj_t)&mp_module_ustruct }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_re), (mp_obj_t)&mp_module_ure }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_json), (mp_obj_t)&mp_module_ujson }, \
@@ -173,13 +195,11 @@ extern const struct _mp_obj_module_t mp_module_ussl;
mp_obj_list_t pyb_sleep_obj_list; \
mp_obj_list_t mp_irq_obj_list; \
mp_obj_list_t pyb_timer_channel_obj_list; \
- mp_obj_list_t mount_obj_list; \
struct _pyb_uart_obj_t *pyb_uart_objs[2]; \
struct _os_term_dup_obj_t *os_term_dup_obj; \
// type definitions for the specific machine
-#define BYTES_PER_WORD (4)
#define MICROPY_MAKE_POINTER_CALLABLE(p) ((void*)((mp_uint_t)(p) | 1))
#define MP_SSIZE_MAX (0x7FFFFFFF)
diff --git a/cc3200/mptask.c b/cc3200/mptask.c
index 9c34e962c..1a74301ec 100644
--- a/cc3200/mptask.c
+++ b/cc3200/mptask.c
@@ -33,6 +33,11 @@
#include "py/runtime.h"
#include "py/gc.h"
#include "py/mphal.h"
+#include "lib/mp-readline/readline.h"
+#include "lib/oofatfs/ff.h"
+#include "lib/oofatfs/diskio.h"
+#include "extmod/vfs.h"
+#include "extmod/vfs_fat.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_ints.h"
@@ -47,7 +52,6 @@
#include "lib/utils/pyexec.h"
#include "gccollect.h"
#include "gchelper.h"
-#include "readline.h"
#include "mperror.h"
#include "simplelink.h"
#include "modnetwork.h"
@@ -56,13 +60,12 @@
#include "serverstask.h"
#include "telnet.h"
#include "debug.h"
-#include "ff.h"
-#include "diskio.h"
#include "sflash_diskio.h"
#include "mpexception.h"
#include "random.h"
#include "pybi2c.h"
#include "pins.h"
+#include "mods/pybflash.h"
#include "pybsleep.h"
#include "pybtimer.h"
#include "cryptohash.h"
@@ -94,7 +97,7 @@ OsiTaskHandle svTaskHandle;
/******************************************************************************
DECLARE PRIVATE DATA
******************************************************************************/
-static FATFS *sflash_fatfs;
+static fs_user_mount_t *sflash_vfs_fat;
static const char fresh_main_py[] = "# main.py -- put your code here!\r\n";
static const char fresh_boot_py[] = "# boot.py -- run on boot-up\r\n"
@@ -149,7 +152,6 @@ soft_reset:
timer_init0();
readline_init0();
mod_network_init0();
- moduos_init0();
rng_init0();
pybsleep_reset_cause_t rstcause = pyb_sleep_get_reset_cause();
@@ -270,7 +272,7 @@ STATIC void mptask_pre_init (void) {
ASSERT (OSI_OK == VStartSimpleLinkSpawnTask(SIMPLELINK_SPAWN_TASK_PRIORITY));
// Allocate memory for the flash file system
- ASSERT ((sflash_fatfs = mem_Malloc(sizeof(FATFS))) != NULL);
+ ASSERT ((sflash_vfs_fat = mem_Malloc(sizeof(*sflash_vfs_fat))) != NULL);
// this one allocates memory for the nvic vault
pyb_sleep_pre_init();
@@ -296,17 +298,19 @@ STATIC void mptask_pre_init (void) {
STATIC void mptask_init_sflash_filesystem (void) {
FILINFO fno;
-#if _USE_LFN
- fno.lfname = NULL;
- fno.lfsize = 0;
-#endif
// Initialise the local flash filesystem.
+ // init the vfs object
+ fs_user_mount_t *vfs_fat = sflash_vfs_fat;
+ vfs_fat->flags = 0;
+ pyb_flash_init_vfs(vfs_fat);
+
// Create it if needed, and mount in on /flash.
- FRESULT res = f_mount(sflash_fatfs, "/flash", 1);
+ FRESULT res = f_mount(&vfs_fat->fatfs);
if (res == FR_NO_FILESYSTEM) {
// no filesystem, so create a fresh one
- res = f_mkfs("/flash", 1, 0);
+ uint8_t working_buf[_MAX_SS];
+ res = f_mkfs(&vfs_fat->fatfs, FM_FAT | FM_SFD, 0, working_buf, sizeof(working_buf));
if (res == FR_OK) {
// success creating fresh LFS
} else {
@@ -316,33 +320,46 @@ STATIC void mptask_init_sflash_filesystem (void) {
mptask_create_main_py();
} else if (res == FR_OK) {
// mount sucessful
- if (FR_OK != f_stat("/flash/main.py", &fno)) {
+ if (FR_OK != f_stat(&vfs_fat->fatfs, "/main.py", &fno)) {
// create empty main.py
mptask_create_main_py();
}
} else {
+ fail:
__fatal_error("failed to create /flash");
}
+ // mount the flash device (there should be no other devices mounted at this point)
+ // we allocate this structure on the heap because vfs->next is a root pointer
+ mp_vfs_mount_t *vfs = m_new_obj_maybe(mp_vfs_mount_t);
+ if (vfs == NULL) {
+ goto fail;
+ }
+ vfs->str = "/flash";
+ vfs->len = 6;
+ vfs->obj = MP_OBJ_FROM_PTR(vfs_fat);
+ vfs->next = NULL;
+ MP_STATE_VM(vfs_mount_table) = vfs;
+
// The current directory is used as the boot up directory.
// It is set to the internal flash filesystem by default.
- f_chdrive("/flash");
+ MP_STATE_PORT(vfs_cur) = vfs;
// create /flash/sys, /flash/lib and /flash/cert if they don't exist
- if (FR_OK != f_chdir ("/flash/sys")) {
- f_mkdir("/flash/sys");
+ if (FR_OK != f_chdir(&vfs_fat->fatfs, "/sys")) {
+ f_mkdir(&vfs_fat->fatfs, "/sys");
}
- if (FR_OK != f_chdir ("/flash/lib")) {
- f_mkdir("/flash/lib");
+ if (FR_OK != f_chdir(&vfs_fat->fatfs, "/lib")) {
+ f_mkdir(&vfs_fat->fatfs, "/lib");
}
- if (FR_OK != f_chdir ("/flash/cert")) {
- f_mkdir("/flash/cert");
+ if (FR_OK != f_chdir(&vfs_fat->fatfs, "/cert")) {
+ f_mkdir(&vfs_fat->fatfs, "/cert");
}
- f_chdir ("/flash");
+ f_chdir(&vfs_fat->fatfs, "/");
// make sure we have a /flash/boot.py. Create it if needed.
- res = f_stat("/flash/boot.py", &fno);
+ res = f_stat(&vfs_fat->fatfs, "/boot.py", &fno);
if (res == FR_OK) {
if (fno.fattrib & AM_DIR) {
// exists as a directory
@@ -354,7 +371,7 @@ STATIC void mptask_init_sflash_filesystem (void) {
} else {
// doesn't exist, create fresh file
FIL fp;
- f_open(&fp, "/flash/boot.py", FA_WRITE | FA_CREATE_ALWAYS);
+ f_open(&vfs_fat->fatfs, &fp, "/boot.py", FA_WRITE | FA_CREATE_ALWAYS);
UINT n;
f_write(&fp, fresh_boot_py, sizeof(fresh_boot_py) - 1 /* don't count null terminator */, &n);
// TODO check we could write n bytes
@@ -374,7 +391,7 @@ STATIC void mptask_enter_ap_mode (void) {
STATIC void mptask_create_main_py (void) {
// create empty main.py
FIL fp;
- f_open(&fp, "/flash/main.py", FA_WRITE | FA_CREATE_ALWAYS);
+ f_open(&sflash_vfs_fat->fatfs, &fp, "/main.py", FA_WRITE | FA_CREATE_ALWAYS);
UINT n;
f_write(&fp, fresh_main_py, sizeof(fresh_main_py) - 1 /* don't count null terminator */, &n);
f_close(&fp);
diff --git a/cc3200/simplelink/user.h b/cc3200/simplelink/user.h
index af3f14e34..d3f6d4adf 100644
--- a/cc3200/simplelink/user.h
+++ b/cc3200/simplelink/user.h
@@ -163,7 +163,7 @@ extern "C" {
\warning
*/
-#define SL_INC_STD_BSD_API_NAMING
+/* #define SL_INC_STD_BSD_API_NAMING */
/*!
diff --git a/cc3200/telnet/telnet.c b/cc3200/telnet/telnet.c
index e90bf928f..26e45a75f 100644
--- a/cc3200/telnet/telnet.c
+++ b/cc3200/telnet/telnet.c
@@ -296,23 +296,23 @@ static void telnet_wait_for_enabled (void) {
static bool telnet_create_socket (void) {
SlSockNonblocking_t nonBlockingOption;
- sockaddr_in sServerAddress;
+ SlSockAddrIn_t sServerAddress;
_i16 result;
// Open a socket for telnet
- ASSERT ((telnet_data.sd = sl_Socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) > 0);
+ ASSERT ((telnet_data.sd = sl_Socket(SL_AF_INET, SL_SOCK_STREAM, SL_IPPROTO_TCP)) > 0);
if (telnet_data.sd > 0) {
// add the socket to the network administration
modusocket_socket_add(telnet_data.sd, false);
// Enable non-blocking mode
nonBlockingOption.NonblockingEnabled = 1;
- ASSERT ((result = sl_SetSockOpt(telnet_data.sd, SOL_SOCKET, SL_SO_NONBLOCKING, &nonBlockingOption, sizeof(nonBlockingOption))) == SL_SOC_OK);
+ ASSERT ((result = sl_SetSockOpt(telnet_data.sd, SL_SOL_SOCKET, SL_SO_NONBLOCKING, &nonBlockingOption, sizeof(nonBlockingOption))) == SL_SOC_OK);
// Bind the socket to a port number
- sServerAddress.sin_family = AF_INET;
- sServerAddress.sin_addr.s_addr = INADDR_ANY;
- sServerAddress.sin_port = htons(TELNET_PORT);
+ sServerAddress.sin_family = SL_AF_INET;
+ sServerAddress.sin_addr.s_addr = SL_INADDR_ANY;
+ sServerAddress.sin_port = sl_Htons(TELNET_PORT);
ASSERT ((result |= sl_Bind(telnet_data.sd, (const SlSockAddr_t *)&sServerAddress, sizeof(sServerAddress))) == SL_SOC_OK);
@@ -330,7 +330,7 @@ static bool telnet_create_socket (void) {
static void telnet_wait_for_connection (void) {
SlSocklen_t in_addrSize;
- sockaddr_in sClientAddress;
+ SlSockAddrIn_t sClientAddress;
// accepts a connection from a TCP client, if there is any, otherwise returns SL_EAGAIN
telnet_data.n_sd = sl_Accept(telnet_data.sd, (SlSockAddr_t *)&sClientAddress, (SlSocklen_t *)&in_addrSize);
diff --git a/cc3200/util/std.h b/cc3200/util/std.h
deleted file mode 100644
index a74c90e25..000000000
--- a/cc3200/util/std.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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.
- */
-
-// This file is needed because in some cases we can't include stdio.h,
-// because the CC3100 socket driver has name clashes with it.
-
-typedef unsigned int size_t;
-
-int printf(const char *fmt, ...);
-int snprintf(char *str, size_t size, const char *fmt, ...);
-
-// Convenience function, defined in main.c.
-void stoupper (char *str);