cc3200: Add WDT functionality as part of the pyb module.
Also improve pybsd, and make it save it's pin configuration. This is a necessary step towards supporting the CC3200 low power deep sleep (LPDS) mode.
This commit is contained in:
parent
fe2eb5f58a
commit
11aa6ba456
@ -96,6 +96,7 @@ APP_MODS_SRC_C = $(addprefix mods/,\
|
||||
pybsd.c \
|
||||
pybsystick.c \
|
||||
pybuart.c \
|
||||
pybwdt.c \
|
||||
)
|
||||
|
||||
APP_CC3100_SRC_C = $(addprefix drivers/cc3100/src/,\
|
||||
|
@ -5,6 +5,7 @@ BOOT_INC += -Ibootmgr/sl
|
||||
BOOT_INC += -Ihal
|
||||
BOOT_INC += -Ihal/inc
|
||||
BOOT_INC += -I../drivers/cc3100/inc
|
||||
BOOT_INC += -Imods
|
||||
BOOT_INC += -Isimplelink
|
||||
BOOT_INC += -Isimplelink/oslib
|
||||
BOOT_INC += -Iutil
|
||||
@ -38,6 +39,10 @@ BOOT_CC3100_SRC_C = $(addprefix drivers/cc3100/,\
|
||||
src/wlan.c \
|
||||
)
|
||||
|
||||
BOOT_MODS_SRC_C = $(addprefix mods/,\
|
||||
pybwdt.c \
|
||||
)
|
||||
|
||||
BOOT_SL_SRC_C = $(addprefix simplelink/,\
|
||||
cc_pal.c \
|
||||
)
|
||||
@ -62,8 +67,8 @@ BOOT_STM_SRC_C = $(addprefix stmhal/,\
|
||||
string0.c \
|
||||
)
|
||||
|
||||
OBJ = $(addprefix $(BUILD)/, $(BOOT_HAL_SRC_C:.c=.o) $(BOOT_SL_SRC_C:.c=.o) $(BOOT_CC3100_SRC_C:.c=.o) $(BOOT_UTIL_SRC_C:.c=.o) $(BOOT_MAIN_SRC_C:.c=.o))
|
||||
OBJ += $(addprefix $(BUILD)/, $(BOOT_MAIN_SRC_S:.s=.o) $(BOOT_PY_SRC_C:.c=.o) $(BOOT_STM_SRC_C:.c=.o))
|
||||
OBJ = $(addprefix $(BUILD)/, $(BOOT_HAL_SRC_C:.c=.o) $(BOOT_MODS_SRC_C:.c=.o) $(BOOT_SL_SRC_C:.c=.o) $(BOOT_CC3100_SRC_C:.c=.o) $(BOOT_UTIL_SRC_C:.c=.o))
|
||||
OBJ += $(addprefix $(BUILD)/, $(BOOT_MAIN_SRC_C:.c=.o) $(BOOT_MAIN_SRC_S:.s=.o) $(BOOT_PY_SRC_C:.c=.o) $(BOOT_STM_SRC_C:.c=.o))
|
||||
|
||||
# Add the linker script
|
||||
LINKER_SCRIPT = bootmgr/bootmgr.lds
|
||||
@ -72,9 +77,6 @@ LDFLAGS += -T $(LINKER_SCRIPT)
|
||||
# Add the bootloader specific CFLAGS
|
||||
CFLAGS += $(BOOT_CPPDEFINES) $(BOOT_INC)
|
||||
|
||||
# Optimize for size all sources except for main
|
||||
|
||||
|
||||
# Disable strict aliasing for the simplelink driver
|
||||
$(BUILD)/drivers/cc3100/src/driver.o: CFLAGS += -fno-strict-aliasing
|
||||
|
||||
|
@ -49,6 +49,7 @@
|
||||
#include "utils.h"
|
||||
#include "cc3200_hal.h"
|
||||
#include "debug.h"
|
||||
#include "pybwdt.h"
|
||||
|
||||
|
||||
//*****************************************************************************
|
||||
@ -153,6 +154,8 @@ static void bootmgr_board_init(void) {
|
||||
// Mandatory MCU Initialization
|
||||
PRCMCC3200MCUInit();
|
||||
|
||||
pybwdt_check_reset_cause();
|
||||
|
||||
// Enable the Data Hashing Engine
|
||||
HASH_Init();
|
||||
|
||||
|
@ -1,58 +0,0 @@
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
|
||||
//
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// Neither the name of Texas Instruments Incorporated nor the names of
|
||||
// its contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#ifndef __CC_TYPES_H__
|
||||
#define __CC_TYPES_H__
|
||||
|
||||
typedef unsigned long long u64;
|
||||
typedef unsigned long u32;
|
||||
typedef int i32;
|
||||
typedef unsigned short u16;
|
||||
typedef short i16;
|
||||
typedef unsigned char u8;
|
||||
typedef char i8;
|
||||
|
||||
typedef void * cc_hndl;
|
||||
|
||||
typedef u32 (*sys_irq_dsbl)();
|
||||
typedef void (*sys_irq_enbl)(u32 mask);
|
||||
#define UNUSED(x) ((x) = (x))
|
||||
|
||||
#define INTRODUCE_SYNC_BARRIER() { \
|
||||
__asm(" dsb \n" \
|
||||
" isb \n"); \
|
||||
}
|
||||
|
||||
#endif //__CC_TYPES_H__
|
@ -32,6 +32,7 @@
|
||||
#include MICROPY_HAL_H
|
||||
#include "mptask.h"
|
||||
#include "simplelink.h"
|
||||
#include "pybwdt.h"
|
||||
#include "debug.h"
|
||||
|
||||
/******************************************************************************
|
||||
@ -62,6 +63,9 @@ int main (void) {
|
||||
// Initialize the clocks and the interrupt system
|
||||
HAL_SystemInit();
|
||||
|
||||
// Start the watchdog
|
||||
pybwdt_init0();
|
||||
|
||||
#ifdef DEBUG
|
||||
ASSERT (OSI_OK == osi_TaskCreate(TASK_Micropython,
|
||||
(const signed char *)"MicroPy",
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include "inc/hw_memmap.h"
|
||||
#include "pybuart.h"
|
||||
#include "osi.h"
|
||||
#include "pybwdt.h"
|
||||
|
||||
|
||||
//*****************************************************************************
|
||||
@ -45,10 +46,11 @@
|
||||
//! \return none
|
||||
//!
|
||||
//*****************************************************************************
|
||||
void
|
||||
vApplicationIdleHook( void)
|
||||
void vApplicationIdleHook (void)
|
||||
{
|
||||
//Handle Idle Hook for Profiling, Power Management etc
|
||||
// kick the watchdog
|
||||
pybwdt_kick();
|
||||
// gate the processor clock to save power
|
||||
__WFI();
|
||||
}
|
||||
|
||||
@ -61,7 +63,7 @@ vApplicationIdleHook( void)
|
||||
//! \return none
|
||||
//!
|
||||
//*****************************************************************************
|
||||
void vApplicationMallocFailedHook()
|
||||
void vApplicationMallocFailedHook (void)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
// Break into the debugger
|
||||
@ -70,9 +72,9 @@ void vApplicationMallocFailedHook()
|
||||
printf("\nFATAL ERROR: FreeRTOS malloc failed!\n");
|
||||
#endif
|
||||
|
||||
//Handle Memory Allocation Errors
|
||||
while(1)
|
||||
for ( ; ; )
|
||||
{
|
||||
// TODO: Blink the BLD
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,7 +87,7 @@ void vApplicationMallocFailedHook()
|
||||
//! \return none
|
||||
//!
|
||||
//*****************************************************************************
|
||||
void vApplicationStackOverflowHook( OsiTaskHandle *pxTask, signed char *pcTaskName)
|
||||
void vApplicationStackOverflowHook (OsiTaskHandle *pxTask, signed char *pcTaskName)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
// Break into the debugger
|
||||
@ -94,9 +96,9 @@ void vApplicationStackOverflowHook( OsiTaskHandle *pxTask, signed char *pcTaskNa
|
||||
printf("\nFATAL ERROR: Application: %s stack overflow!\n", pcTaskName);
|
||||
#endif
|
||||
|
||||
//Handle FreeRTOS Stack Overflow
|
||||
while(1)
|
||||
for ( ; ; )
|
||||
{
|
||||
// TODO: Blink the BLD
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,7 +111,7 @@ void vApplicationStackOverflowHook( OsiTaskHandle *pxTask, signed char *pcTaskNa
|
||||
//! \return none
|
||||
//!
|
||||
//*****************************************************************************
|
||||
void vApplicationTickHook( void )
|
||||
void vApplicationTickHook (void)
|
||||
{
|
||||
HAL_IncrementTick();
|
||||
}
|
||||
|
@ -58,6 +58,7 @@
|
||||
#include "pybadc.h"
|
||||
#include "pybi2c.h"
|
||||
#include "pybsd.h"
|
||||
#include "pybwdt.h"
|
||||
#include "utils.h"
|
||||
#include "gccollect.h"
|
||||
|
||||
@ -251,7 +252,7 @@ STATIC mp_obj_t pyb_repl_uart(uint n_args, const mp_obj_t *args) {
|
||||
} else if (mp_obj_get_type(args[0]) == &pyb_uart_type) {
|
||||
pyb_stdio_uart = args[0];
|
||||
} else {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_num_type_invalid_arguments));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, mpexception_num_type_invalid_arguments));
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
@ -269,6 +270,30 @@ STATIC mp_obj_t pyb_mkdisk(mp_obj_t path_o) {
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_mkdisk_obj, pyb_mkdisk);
|
||||
|
||||
/// \function wdt_enable('msec')
|
||||
/// Enabled the watchdog timer with msec timeout value
|
||||
STATIC mp_obj_t pyb_enable_wdt(mp_obj_t msec_in) {
|
||||
mp_int_t msec = mp_obj_get_int(msec_in);
|
||||
pybwdt_ret_code_t ret;
|
||||
ret = pybwdt_enable (msec);
|
||||
if (ret == E_PYBWDT_IS_RUNNING) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, mpexception_os_request_not_possible));
|
||||
}
|
||||
else if (ret == E_PYBWDT_INVALID_TIMEOUT) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments));
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_enable_wdt_obj, pyb_enable_wdt);
|
||||
|
||||
/// \function wdt_kick()
|
||||
/// Kicks the watchdog timer
|
||||
STATIC mp_obj_t pyb_kick_wdt(void) {
|
||||
pybwdt_kick ();
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_kick_wdt_obj, pyb_kick_wdt);
|
||||
|
||||
MP_DECLARE_CONST_FUN_OBJ(pyb_main_obj); // defined in main.c
|
||||
|
||||
STATIC const mp_map_elem_t pyb_module_globals_table[] = {
|
||||
@ -300,6 +325,8 @@ STATIC const mp_map_elem_t pyb_module_globals_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_udelay), (mp_obj_t)&pyb_udelay_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_sync), (mp_obj_t)&pyb_sync_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_mkdisk), (mp_obj_t)&pyb_mkdisk_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_enable_wdt), (mp_obj_t)&pyb_enable_wdt_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_kick_wdt), (mp_obj_t)&pyb_kick_wdt_obj },
|
||||
|
||||
#if MICROPY_HW_ENABLE_RNG
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_rng), (mp_obj_t)&pyb_rng_get_obj },
|
||||
@ -316,7 +343,7 @@ STATIC const mp_map_elem_t pyb_module_globals_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_UART), (mp_obj_t)&pyb_uart_type },
|
||||
|
||||
#if MICROPY_HW_HAS_SDCARD
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_SD), (mp_obj_t)&pyb_sdcard_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_SD), (mp_obj_t)&pyb_sd_type },
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -111,7 +111,7 @@ STATIC mp_obj_t adc_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw,
|
||||
}
|
||||
|
||||
// disable the callback before re-configuring
|
||||
pyb_obj_adc_t *self = m_new_obj(pyb_obj_adc_t);
|
||||
pyb_obj_adc_t *self = m_new_obj_with_finaliser(pyb_obj_adc_t);
|
||||
self->base.type = &pyb_adc_type;
|
||||
self->channel = channel;
|
||||
self->num = num;
|
||||
|
@ -324,7 +324,7 @@ STATIC mp_obj_t pyb_i2c_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n
|
||||
}
|
||||
|
||||
// create and setup the object
|
||||
pyb_i2c_obj_t *self = m_new_obj(pyb_i2c_obj_t);
|
||||
pyb_i2c_obj_t *self = m_new_obj_with_finaliser(pyb_i2c_obj_t);
|
||||
self->base.type = &pyb_i2c_type;
|
||||
self->mode = PYBI2C_MODE_DISABLED;
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* 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
|
||||
@ -49,76 +49,116 @@
|
||||
|
||||
#define PYBSD_FREQUENCY_HZ 15000000 // 15MHz
|
||||
|
||||
static const pin_obj_t *pybsd_pin_sd_detect;
|
||||
static bool pybsd_is_enabled;
|
||||
static bool pybsd_in_path;
|
||||
static FATFS *sd_fatfs;
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
FATFS *fatfs;
|
||||
pin_obj_t *pin_d0;
|
||||
pin_obj_t *pin_clk;
|
||||
pin_obj_t *pin_cmd;
|
||||
pin_obj_t *pin_sd_detect;
|
||||
byte af_d0;
|
||||
byte af_clk;
|
||||
byte af_cmd;
|
||||
bool pinsset;
|
||||
bool enabled;
|
||||
bool inpath;
|
||||
} pybsd_obj_t;
|
||||
|
||||
/******************************************************************************
|
||||
DECLARE PRIVATE DATA
|
||||
******************************************************************************/
|
||||
STATIC pybsd_obj_t pybsd_obj;
|
||||
|
||||
/******************************************************************************
|
||||
DECLARE PRIVATE FUNCTIONS
|
||||
******************************************************************************/
|
||||
STATIC mp_obj_t pybsd_make_new (mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args);
|
||||
STATIC mp_obj_t pybsd_disable (mp_obj_t self_in);
|
||||
STATIC mp_obj_t pybsd_enable (mp_obj_t self_in);
|
||||
|
||||
/******************************************************************************
|
||||
DECLARE PUBLIC FUNCTIONS
|
||||
******************************************************************************/
|
||||
void pybsd_init0 (void) {
|
||||
// Allocate memory for the sd file system
|
||||
ASSERT ((sd_fatfs = mem_Malloc(sizeof(FATFS))) != NULL);
|
||||
// allocate memory for the sd file system
|
||||
ASSERT ((pybsd_obj.fatfs = mem_Malloc(sizeof(FATFS))) != NULL);
|
||||
}
|
||||
|
||||
bool pybsd_is_present(void) {
|
||||
if (pybsd_pin_sd_detect) {
|
||||
return pybsd_is_enabled && MAP_GPIOPinRead(pybsd_pin_sd_detect->port, pybsd_pin_sd_detect->bit);
|
||||
if (pybsd_obj.pin_sd_detect) {
|
||||
return pybsd_obj.enabled && MAP_GPIOPinRead(pybsd_obj.pin_sd_detect->port, pybsd_obj.pin_sd_detect->bit);
|
||||
}
|
||||
return pybsd_is_enabled;
|
||||
return pybsd_obj.enabled;
|
||||
}
|
||||
|
||||
void pybsd_deinit (void) {
|
||||
pybsd_disable ((mp_obj_t)&pybsd_obj);
|
||||
pybsd_obj.pin_sd_detect = NULL;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
// Micro Python bindings
|
||||
//
|
||||
|
||||
/// \method sd_config([value])
|
||||
/// \classmethod \constructor()
|
||||
/// Configure the pins used for the sd card.
|
||||
/// May receive 6 or 7 arguments. The 7th optional argument is the card detect pin.
|
||||
/// May receive 0, 6 or 7 arguments. The 7th optional argument is the card detect pin.
|
||||
/// this pin needs no external pull-up and must be low when the sdcard is inserted.
|
||||
///
|
||||
/// Usage:
|
||||
/// sd = pyb.SD()
|
||||
////
|
||||
/// sd = pyb.SD(d0_pin, d0_af, clk_pin, clk_af, cmd_pin, cmd_af)
|
||||
///
|
||||
/// pyb.SDcard.config_pins (d0_pin, d0_af, clk_pin, clk_af, cmd_pin, cmd_af)
|
||||
/// and:
|
||||
///
|
||||
/// or:
|
||||
/// sd = pyb.SD(d0_pin, d0_af, clk_pin, clk_af, cmd_pin, cmd_af, card_detect_pin)
|
||||
///
|
||||
/// pyb.SDcard.sd_config_pins (d0_pin, d0_af, clk_pin, clk_af, cmd_pin, cmd_af, card_detect_pin)
|
||||
///
|
||||
STATIC mp_obj_t pybsd_config_pins (mp_uint_t n_args, const mp_obj_t *args) {
|
||||
byte pybsd_pin_d0, pybsd_pin_clk, pybsd_pin_cmd;
|
||||
byte pybsd_af_d0, pybsd_af_clk, pybsd_af_cmd;
|
||||
const pin_obj_t *pin;
|
||||
STATIC mp_obj_t pybsd_make_new (mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, 7, false);
|
||||
|
||||
// get all the arguments
|
||||
pin = pin_find(args[1]);
|
||||
pybsd_pin_d0 = pin->pin_num;
|
||||
pybsd_af_d0 = mp_obj_get_int(args[2]);
|
||||
pin_verify_af (pybsd_af_d0);
|
||||
pin = pin_find(args[3]);
|
||||
pybsd_pin_clk = pin->pin_num;
|
||||
pybsd_af_clk = mp_obj_get_int(args[4]);
|
||||
pin_verify_af (pybsd_af_clk);
|
||||
pin = pin_find(args[5]);
|
||||
pybsd_pin_cmd = pin->pin_num;
|
||||
pybsd_af_cmd = mp_obj_get_int(args[6]);
|
||||
pin_verify_af (pybsd_af_cmd);
|
||||
if (n_args >= 6) {
|
||||
// get pins and afs
|
||||
pybsd_obj.pin_d0 = (pin_obj_t *)pin_find(args[0]);
|
||||
pybsd_obj.af_d0 = mp_obj_get_int(args[1]);
|
||||
pin_verify_af (pybsd_obj.af_d0);
|
||||
pybsd_obj.pin_clk = (pin_obj_t *)pin_find(args[2]);
|
||||
pybsd_obj.af_clk = mp_obj_get_int(args[3]);
|
||||
pin_verify_af (pybsd_obj.af_clk);
|
||||
pybsd_obj.pin_cmd = (pin_obj_t *)pin_find(args[4]);
|
||||
pybsd_obj.af_cmd = mp_obj_get_int(args[5]);
|
||||
pin_verify_af (pybsd_obj.af_cmd);
|
||||
|
||||
// configure the sdhost pins
|
||||
MAP_PinTypeSDHost(pybsd_pin_d0, pybsd_af_d0);
|
||||
MAP_PinTypeSDHost(pybsd_pin_clk, pybsd_af_clk);
|
||||
MAP_PinTypeSDHost(pybsd_pin_cmd, pybsd_af_cmd);
|
||||
MAP_PinDirModeSet(pybsd_pin_clk, PIN_DIR_MODE_OUT);
|
||||
// configure the card detect pin if provided
|
||||
if (n_args == 8) {
|
||||
pybsd_pin_sd_detect = pin_find(args[7]);
|
||||
pin_config(pybsd_pin_sd_detect, PIN_MODE_0, GPIO_DIR_MODE_IN, PIN_TYPE_STD_PU, PIN_STRENGTH_4MA);
|
||||
// configure the sdhost pins
|
||||
MAP_PinTypeSDHost(pybsd_obj.pin_d0->pin_num, pybsd_obj.af_d0);
|
||||
MAP_PinTypeSDHost(pybsd_obj.pin_clk->pin_num, pybsd_obj.af_clk);
|
||||
MAP_PinDirModeSet(pybsd_obj.pin_clk->pin_num, PIN_DIR_MODE_OUT);
|
||||
MAP_PinTypeSDHost(pybsd_obj.pin_cmd->pin_num, pybsd_obj.af_cmd);
|
||||
|
||||
// card detect pin was provided
|
||||
if (n_args == 7) {
|
||||
pybsd_obj.pin_sd_detect = (pin_obj_t *)pin_find(args[6]);
|
||||
pin_config(pybsd_obj.pin_sd_detect, PIN_MODE_0, GPIO_DIR_MODE_IN, PIN_TYPE_STD_PU, PIN_STRENGTH_4MA);
|
||||
}
|
||||
pybsd_obj.pinsset = true;
|
||||
}
|
||||
else if (n_args == 0) {
|
||||
if (!pybsd_obj.pinsset) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, mpexception_num_type_invalid_arguments));
|
||||
}
|
||||
}
|
||||
else {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, mpexception_num_type_invalid_arguments));
|
||||
}
|
||||
|
||||
return mp_const_none;
|
||||
pybsd_obj.base.type = &pyb_sd_type;
|
||||
return &pybsd_obj;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pybsd_config_pins_obj, 7, 8, pybsd_config_pins);
|
||||
|
||||
STATIC mp_obj_t pybsd_enable(mp_obj_t self) {
|
||||
/// \method enable()
|
||||
/// Enables the sd card and mounts the file system
|
||||
STATIC mp_obj_t pybsd_enable (mp_obj_t self_in) {
|
||||
pybsd_obj_t *self = self_in;
|
||||
// Enable SD peripheral clock
|
||||
MAP_PRCMPeripheralClkEnable(PRCM_SDHOST, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK);
|
||||
// Reset MMCHS
|
||||
@ -128,31 +168,34 @@ STATIC mp_obj_t pybsd_enable(mp_obj_t self) {
|
||||
// Configure the card clock
|
||||
MAP_SDHostSetExpClk(SDHOST_BASE, MAP_PRCMPeripheralClockGet(PRCM_SDHOST), PYBSD_FREQUENCY_HZ);
|
||||
|
||||
pybsd_is_enabled = true;
|
||||
self->enabled = true;
|
||||
|
||||
// try to mount the sd card on /SD
|
||||
if (FR_OK != f_mount(sd_fatfs, "/SD", 1)) {
|
||||
if (FR_OK != f_mount(self->fatfs, "/SD", 1)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, mpexception_os_operation_failed));
|
||||
}
|
||||
|
||||
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_SD));
|
||||
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_SD_slash_LIB));
|
||||
pybsd_in_path = true;
|
||||
self->inpath = true;
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pybsd_enable_obj, pybsd_enable);
|
||||
|
||||
STATIC mp_obj_t pybsd_disable(mp_obj_t self) {
|
||||
if (pybsd_is_enabled) {
|
||||
pybsd_is_enabled = false;
|
||||
/// \method disable()
|
||||
/// Disables the sd card and unmounts the file system
|
||||
STATIC mp_obj_t pybsd_disable (mp_obj_t self_in) {
|
||||
pybsd_obj_t *self = self_in;
|
||||
if (self->enabled) {
|
||||
self->enabled = false;
|
||||
// unmount the sd card
|
||||
f_mount (NULL, "/SD", 1);
|
||||
// remove sd paths from mp_sys_path
|
||||
if (pybsd_in_path) {
|
||||
if (self->inpath) {
|
||||
mp_obj_list_remove(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_SD));
|
||||
mp_obj_list_remove(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_SD_slash_LIB));
|
||||
pybsd_in_path = false;
|
||||
self->inpath = false;
|
||||
}
|
||||
// disable the peripheral
|
||||
MAP_PRCMPeripheralClkDisable(PRCM_SDHOST, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK);
|
||||
@ -162,18 +205,16 @@ STATIC mp_obj_t pybsd_disable(mp_obj_t self) {
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pybsd_disable_obj, pybsd_disable);
|
||||
|
||||
STATIC const mp_map_elem_t pybsd_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_config_pins), (mp_obj_t)&pybsd_config_pins_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_enable), (mp_obj_t)&pybsd_enable_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_disable), (mp_obj_t)&pybsd_disable_obj },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(pybsd_locals_dict, pybsd_locals_dict_table);
|
||||
|
||||
static const mp_obj_type_t sdcard_type = {
|
||||
const mp_obj_type_t pyb_sd_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_SD,
|
||||
.make_new = pybsd_make_new,
|
||||
.locals_dict = (mp_obj_t)&pybsd_locals_dict,
|
||||
};
|
||||
|
||||
const mp_obj_base_t pyb_sdcard_obj = {&sdcard_type};
|
||||
|
||||
#endif // MICROPY_HW_HAS_SDCARD
|
||||
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* 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
|
||||
@ -29,8 +29,9 @@
|
||||
#if MICROPY_HW_HAS_SDCARD
|
||||
void pybsd_init0 (void);
|
||||
bool pybsd_is_present(void);
|
||||
void pybsd_deinit (void);
|
||||
|
||||
extern const struct _mp_obj_base_t pyb_sdcard_obj;
|
||||
extern const mp_obj_type_t pyb_sd_type;
|
||||
#endif
|
||||
|
||||
#endif // PYBSD_H_
|
||||
|
136
cc3200/mods/pybwdt.c
Normal file
136
cc3200/mods/pybwdt.c
Normal file
@ -0,0 +1,136 @@
|
||||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Daniel Campora
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "py/mpconfig.h"
|
||||
#include MICROPY_HAL_H
|
||||
#include "py/obj.h"
|
||||
#include "py/runtime.h"
|
||||
#include "inc/hw_types.h"
|
||||
#include "inc/hw_gpio.h"
|
||||
#include "inc/hw_ints.h"
|
||||
#include "inc/hw_memmap.h"
|
||||
#include "rom_map.h"
|
||||
#include "wdt.h"
|
||||
#include "prcm.h"
|
||||
#include "utils.h"
|
||||
#include "pybwdt.h"
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
DECLARE CONSTANTS
|
||||
******************************************************************************/
|
||||
#define PYBWDT_MILLISECONDS_TO_TICKS(ms) ((80000000 / 1000) * (ms))
|
||||
#define PYBWDT_MIN_TIMEOUT_MS (500)
|
||||
|
||||
/******************************************************************************
|
||||
DECLARE TYPES
|
||||
******************************************************************************/
|
||||
typedef struct {
|
||||
bool servers;
|
||||
bool simplelink;
|
||||
bool running;
|
||||
}pybwdt_data_t;
|
||||
|
||||
/******************************************************************************
|
||||
DECLARE PRIVATE DATA
|
||||
******************************************************************************/
|
||||
static pybwdt_data_t pybwdt_data;
|
||||
|
||||
/******************************************************************************
|
||||
DEFINE PUBLIC FUNCTIONS
|
||||
******************************************************************************/
|
||||
// must be called in main.c just after initializing the hal
|
||||
void pybwdt_init0 (void) {
|
||||
pybwdt_data.running = false;
|
||||
}
|
||||
|
||||
void pybwdt_check_reset_cause (void) {
|
||||
// if we are recovering from a WDT reset, trigger
|
||||
// a hibernate cycle for a clean boot
|
||||
if (MAP_PRCMSysResetCauseGet() == PRCM_WDT_RESET) {
|
||||
HWREG(0x400F70B8) = 1;
|
||||
UtilsDelay(800000/5);
|
||||
HWREG(0x400F70B0) = 1;
|
||||
UtilsDelay(800000/5);
|
||||
|
||||
HWREG(0x4402E16C) |= 0x2;
|
||||
UtilsDelay(800);
|
||||
HWREG(0x4402F024) &= 0xF7FFFFFF;
|
||||
|
||||
MAP_PRCMHibernateWakeupSourceEnable(PRCM_HIB_SLOW_CLK_CTR);
|
||||
// set the sleep interval to 10ms
|
||||
MAP_PRCMHibernateIntervalSet(330);
|
||||
MAP_PRCMHibernateEnter();
|
||||
}
|
||||
}
|
||||
|
||||
// minimum timeout value is 500ms
|
||||
pybwdt_ret_code_t pybwdt_enable (uint32_t timeout) {
|
||||
if (timeout >= PYBWDT_MIN_TIMEOUT_MS) {
|
||||
if (!pybwdt_data.running) {
|
||||
// Enable the WDT peripheral clock
|
||||
MAP_PRCMPeripheralClkEnable(PRCM_WDT, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK);
|
||||
|
||||
// Unlock to be able to configure the registers
|
||||
MAP_WatchdogUnlock(WDT_BASE);
|
||||
|
||||
// Make the WDT stall when the debugger stops on a breakpoint
|
||||
MAP_WatchdogStallEnable (WDT_BASE);
|
||||
|
||||
// Set the watchdog timer reload value
|
||||
// the WDT trigger a system reset after the second timeout
|
||||
// so, divide by the 2 timeout value received
|
||||
MAP_WatchdogReloadSet(WDT_BASE, PYBWDT_MILLISECONDS_TO_TICKS(timeout / 2));
|
||||
|
||||
// Start the timer. Once the timer is started, it cannot be disabled.
|
||||
MAP_WatchdogEnable(WDT_BASE);
|
||||
pybwdt_data.running = true;
|
||||
|
||||
return E_PYBWDT_OK;
|
||||
}
|
||||
return E_PYBWDT_IS_RUNNING;
|
||||
}
|
||||
return E_PYBWDT_INVALID_TIMEOUT;
|
||||
}
|
||||
|
||||
void pybwdt_kick (void) {
|
||||
// check that the servers and simplelink are running fine
|
||||
if (pybwdt_data.servers && pybwdt_data.simplelink && pybwdt_data.running) {
|
||||
pybwdt_data.servers = false;
|
||||
pybwdt_data.simplelink = false;
|
||||
MAP_WatchdogIntClear(WDT_BASE);
|
||||
}
|
||||
}
|
||||
|
||||
void pybwdt_srv_alive (void) {
|
||||
pybwdt_data.servers = true;
|
||||
}
|
||||
|
||||
void pybwdt_sl_alive (void) {
|
||||
pybwdt_data.simplelink = true;
|
||||
}
|
43
cc3200/mods/pybwdt.h
Normal file
43
cc3200/mods/pybwdt.h
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Daniel Campora
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef PYBWDT_H_
|
||||
#define PYBWDT_H_
|
||||
|
||||
typedef enum {
|
||||
E_PYBWDT_OK = 0,
|
||||
E_PYBWDT_IS_RUNNING = -1,
|
||||
E_PYBWDT_INVALID_TIMEOUT = -2
|
||||
}pybwdt_ret_code_t;
|
||||
|
||||
void pybwdt_init0 (void);
|
||||
void pybwdt_check_reset_cause (void);
|
||||
pybwdt_ret_code_t pybwdt_enable (uint32_t timeout);
|
||||
void pybwdt_kick (void);
|
||||
void pybwdt_srv_alive (void);
|
||||
void pybwdt_sl_alive (void);
|
||||
|
||||
#endif /* PYBWDT_H_ */
|
@ -229,15 +229,19 @@ soft_reset_exit:
|
||||
|
||||
sflash_disk_flush();
|
||||
|
||||
#if MICROPY_HW_HAS_SDCARD
|
||||
pybsd_deinit();
|
||||
#endif
|
||||
|
||||
printf("PYB: soft reboot\n");
|
||||
|
||||
// wait for all bus transfers to complete
|
||||
HAL_Delay(50);
|
||||
|
||||
// disable wlan services
|
||||
wlan_stop_servers();
|
||||
wlan_stop();
|
||||
|
||||
// wait for all bus transfers to complete
|
||||
HAL_Delay(50);
|
||||
|
||||
uart_deinit();
|
||||
|
||||
goto soft_reset;
|
||||
|
@ -33,10 +33,11 @@ Q(micros)
|
||||
Q(elapsed_millis)
|
||||
Q(elapsed_micros)
|
||||
Q(udelay)
|
||||
Q(SD)
|
||||
Q(SDcard)
|
||||
Q(FileIO)
|
||||
Q(flush)
|
||||
Q(FileIO)
|
||||
Q(mkdisk)
|
||||
Q(enable_wdt)
|
||||
Q(kick_wdt)
|
||||
// Entries for sys.path
|
||||
Q(/SFLASH)
|
||||
Q(/SFLASH/LIB)
|
||||
@ -58,7 +59,6 @@ Q(chdir)
|
||||
Q(getcwd)
|
||||
Q(listdir)
|
||||
Q(mkdir)
|
||||
Q(mkdisk)
|
||||
Q(remove)
|
||||
Q(rmdir)
|
||||
Q(unlink)
|
||||
@ -162,7 +162,6 @@ Q(disable)
|
||||
|
||||
// for SD class
|
||||
Q(SD)
|
||||
Q(config_pins)
|
||||
Q(enable)
|
||||
Q(disable)
|
||||
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include "mpexception.h"
|
||||
#include "telnet.h"
|
||||
#include "ftp.h"
|
||||
#include "pybwdt.h"
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
@ -119,6 +120,8 @@ void TASK_Servers (void *pvParameters) {
|
||||
|
||||
cycle = cycle ? false : true;
|
||||
HAL_Delay(SERVERS_CYCLE_TIME_MS);
|
||||
// set the alive flag for the wdt
|
||||
pybwdt_srv_alive();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,6 +50,7 @@
|
||||
#include "rom_map.h"
|
||||
#include "inc/hw_types.h"
|
||||
#include "interrupt.h"
|
||||
#include "pybwdt.h"
|
||||
|
||||
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
|
||||
//Local function definition
|
||||
@ -59,7 +60,7 @@ QueueHandle_t xSimpleLinkSpawnQueue = NULL;
|
||||
TaskHandle_t xSimpleLinkSpawnTaskHndl = NULL;
|
||||
// Queue size
|
||||
#define slQUEUE_SIZE ( 3 )
|
||||
|
||||
#define SL_SPAWN_MAX_WAIT_MS ( 200 )
|
||||
|
||||
/*!
|
||||
\brief This function registers an interrupt in NVIC table
|
||||
@ -494,11 +495,13 @@ void vSimpleLinkSpawnTask(void *pvParameters)
|
||||
|
||||
for(;;)
|
||||
{
|
||||
ret = xQueueReceive( xSimpleLinkSpawnQueue, &Msg, portMAX_DELAY );
|
||||
ret = xQueueReceive( xSimpleLinkSpawnQueue, &Msg, SL_SPAWN_MAX_WAIT_MS);
|
||||
if(ret == pdPASS)
|
||||
{
|
||||
Msg.pEntry(Msg.pValue);
|
||||
}
|
||||
// set the alive flag for the wdt
|
||||
pybwdt_sl_alive();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user