mirror of https://github.com/ARMmbed/mbed-os.git
Merge branch 'fix_astyle_error' of ssh://github.com/0xc0170/mbed-os into rollup-b.1
commit
5c1c7bf71f
|
@ -16,6 +16,7 @@ hal/storage_abstraction
|
||||||
TESTS/mbed_hal/trng/pithy
|
TESTS/mbed_hal/trng/pithy
|
||||||
features/nanostack/coap-service
|
features/nanostack/coap-service
|
||||||
features/nanostack/sal-stack-nanostack
|
features/nanostack/sal-stack-nanostack
|
||||||
|
features/nanostack/targets
|
||||||
rtos/TARGET_CORTEX/rtx5
|
rtos/TARGET_CORTEX/rtx5
|
||||||
TESTS/mbed_hal/trng/pithy
|
TESTS/mbed_hal/trng/pithy
|
||||||
targets
|
targets
|
||||||
|
|
|
@ -132,7 +132,9 @@ matrix:
|
||||||
- git diff --name-only $TRAVIS_BRANCH | grep '.*\.\(h\|c\|hpp\|cpp\)' | fgrep -v -f .astyleignore | xargs -n 100 -I {} bash -c "astyle -n --options=.astylerc \"{}\"" > astyle-files-changed.out;
|
- git diff --name-only $TRAVIS_BRANCH | grep '.*\.\(h\|c\|hpp\|cpp\)' | fgrep -v -f .astyleignore | xargs -n 100 -I {} bash -c "astyle -n --options=.astylerc \"{}\"" > astyle-files-changed.out;
|
||||||
if [ $(cat astyle-files-changed.out | grep Formatted | wc -l) -ne 0 ]; then
|
if [ $(cat astyle-files-changed.out | grep Formatted | wc -l) -ne 0 ]; then
|
||||||
git --no-pager diff;
|
git --no-pager diff;
|
||||||
echo "Please fix style issues as shown above";
|
echo "";
|
||||||
|
echo "AStyle check failed, please fix style issues as shown above";
|
||||||
|
(exit 1);
|
||||||
else
|
else
|
||||||
echo "Coding style check OK";
|
echo "Coding style check OK";
|
||||||
fi
|
fi
|
||||||
|
@ -155,7 +157,6 @@ matrix:
|
||||||
STATUSM="$STATUSM ($(python -c "print '%+d' % ($CURR-$PREV)") files)"
|
STATUSM="$STATUSM ($(python -c "print '%+d' % ($CURR-$PREV)") files)"
|
||||||
fi
|
fi
|
||||||
- bash -c "$STATUS" success "$STATUSM"
|
- bash -c "$STATUS" success "$STATUSM"
|
||||||
|
|
||||||
- env:
|
- env:
|
||||||
- NAME=events
|
- NAME=events
|
||||||
- EVENTS=events
|
- EVENTS=events
|
||||||
|
|
|
@ -16,9 +16,9 @@
|
||||||
|
|
||||||
/** \addtogroup hal_critical
|
/** \addtogroup hal_critical
|
||||||
* @{
|
* @{
|
||||||
* \defgroup hal_critical_test Tests
|
* \defgroup hal_critical_test Tests
|
||||||
* Tests definitions of the HAL Critical module.
|
* Tests definitions of the HAL Critical module.
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MBED_CRITICAL_SECTION_TEST_H
|
#ifndef MBED_CRITICAL_SECTION_TEST_H
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
* @{
|
* @{
|
||||||
* \defgroup hal_qspi_tests Tests
|
* \defgroup hal_qspi_tests Tests
|
||||||
* QSPI tests of the HAL.
|
* QSPI tests of the HAL.
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
#ifndef MBED_QSPI_TEST_H
|
#ifndef MBED_QSPI_TEST_H
|
||||||
#define MBED_QSPI_TEST_H
|
#define MBED_QSPI_TEST_H
|
||||||
|
|
|
@ -183,7 +183,7 @@ void test_set_time_twice()
|
||||||
/* Set the time to NEW_TIME and check it */
|
/* Set the time to NEW_TIME and check it */
|
||||||
set_time(NEW_TIME);
|
set_time(NEW_TIME);
|
||||||
current_time = time(NULL);
|
current_time = time(NULL);
|
||||||
TEST_ASSERT_EQUAL (true, (current_time == NEW_TIME));
|
TEST_ASSERT_EQUAL(true, (current_time == NEW_TIME));
|
||||||
|
|
||||||
/* Wait 2 seconds */
|
/* Wait 2 seconds */
|
||||||
wait_ms(2000);
|
wait_ms(2000);
|
||||||
|
@ -191,7 +191,7 @@ void test_set_time_twice()
|
||||||
/* set the time to NEW_TIME again and check it */
|
/* set the time to NEW_TIME again and check it */
|
||||||
set_time(NEW_TIME);
|
set_time(NEW_TIME);
|
||||||
current_time = time(NULL);
|
current_time = time(NULL);
|
||||||
TEST_ASSERT_EQUAL (true, (current_time == NEW_TIME));
|
TEST_ASSERT_EQUAL(true, (current_time == NEW_TIME));
|
||||||
}
|
}
|
||||||
|
|
||||||
Case cases[] = {
|
Case cases[] = {
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
* @{
|
* @{
|
||||||
* @defgroup hal_sleep_test_util Tests
|
* @defgroup hal_sleep_test_util Tests
|
||||||
* Tests of the sleep HAL.
|
* Tests of the sleep HAL.
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MBED_SLEEP_TEST_UTILS_H
|
#ifndef MBED_SLEEP_TEST_UTILS_H
|
||||||
|
|
|
@ -26,7 +26,8 @@ class stubInternetSocket : public InternetSocket {
|
||||||
protected:
|
protected:
|
||||||
nsapi_error_t return_value;
|
nsapi_error_t return_value;
|
||||||
public:
|
public:
|
||||||
stubInternetSocket() {
|
stubInternetSocket()
|
||||||
|
{
|
||||||
return_value = 0;
|
return_value = 0;
|
||||||
}
|
}
|
||||||
virtual nsapi_error_t connect(const SocketAddress &address)
|
virtual nsapi_error_t connect(const SocketAddress &address)
|
||||||
|
|
|
@ -20,8 +20,8 @@
|
||||||
using namespace mbed;
|
using namespace mbed;
|
||||||
|
|
||||||
AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) :
|
AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) :
|
||||||
AT_CellularBase(at), _ip_stack_type_requested(DEFAULT_STACK), _is_connected(false), _is_blocking(true),
|
AT_CellularBase(at), _ip_stack_type_requested(DEFAULT_STACK), _is_connected(false), _is_blocking(true),
|
||||||
_current_op(OP_INVALID), _device(device), _nw(0), _fh(0)
|
_current_op(OP_INVALID), _device(device), _nw(0), _fh(0)
|
||||||
{
|
{
|
||||||
_stack = NULL;
|
_stack = NULL;
|
||||||
_ip_stack_type = DEFAULT_STACK;
|
_ip_stack_type = DEFAULT_STACK;
|
||||||
|
@ -115,7 +115,7 @@ void AT_CellularContext::set_sim_pin(const char *sim_pin)
|
||||||
}
|
}
|
||||||
|
|
||||||
nsapi_error_t AT_CellularContext::connect(const char *sim_pin, const char *apn, const char *uname,
|
nsapi_error_t AT_CellularContext::connect(const char *sim_pin, const char *apn, const char *uname,
|
||||||
const char *pwd)
|
const char *pwd)
|
||||||
{
|
{
|
||||||
return NSAPI_ERROR_OK;
|
return NSAPI_ERROR_OK;
|
||||||
}
|
}
|
||||||
|
@ -173,7 +173,7 @@ bool AT_CellularContext::set_new_context(int cid)
|
||||||
|
|
||||||
nsapi_error_t AT_CellularContext::do_activate_context()
|
nsapi_error_t AT_CellularContext::do_activate_context()
|
||||||
{
|
{
|
||||||
return NSAPI_ERROR_OK;
|
return NSAPI_ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AT_CellularContext::do_connect()
|
void AT_CellularContext::do_connect()
|
||||||
|
|
|
@ -26,8 +26,8 @@ MBED_WEAK CellularDevice *CellularDevice::get_default_instance()
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0), _sms_ref_count(0),_power_ref_count(0), _sim_ref_count(0),
|
CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0), _sms_ref_count(0), _power_ref_count(0), _sim_ref_count(0),
|
||||||
_info_ref_count(0), _fh(fh), _queue(5 * EVENTS_EVENT_SIZE), _state_machine(0), _nw(0)
|
_info_ref_count(0), _fh(fh), _queue(5 * EVENTS_EVENT_SIZE), _state_machine(0), _nw(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,11 +41,11 @@ events::EventQueue *CellularDevice::get_queue()
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CellularDevice::set_plmn(char const*)
|
void CellularDevice::set_plmn(char const *)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void CellularDevice::set_sim_pin(char const*)
|
void CellularDevice::set_sim_pin(char const *)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
namespace mbed {
|
namespace mbed {
|
||||||
|
|
||||||
CellularStateMachine::CellularStateMachine(CellularDevice &device, events::EventQueue &queue) :
|
CellularStateMachine::CellularStateMachine(CellularDevice &device, events::EventQueue &queue) :
|
||||||
_cellularDevice(device), _queue(queue)
|
_cellularDevice(device), _queue(queue)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ public:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int close()
|
virtual int close()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,8 @@ public:
|
||||||
std::list<nsapi_error_t> return_values;
|
std::list<nsapi_error_t> return_values;
|
||||||
nsapi_error_t return_value;
|
nsapi_error_t return_value;
|
||||||
|
|
||||||
NetworkStackstub() {
|
NetworkStackstub()
|
||||||
|
{
|
||||||
return_value = 0;
|
return_value = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ public:
|
||||||
*/
|
*/
|
||||||
FlashIAPBlockDevice(uint32_t address = MBED_CONF_FLASHIAP_BLOCK_DEVICE_BASE_ADDRESS,
|
FlashIAPBlockDevice(uint32_t address = MBED_CONF_FLASHIAP_BLOCK_DEVICE_BASE_ADDRESS,
|
||||||
uint32_t size = MBED_CONF_FLASHIAP_BLOCK_DEVICE_SIZE);
|
uint32_t size = MBED_CONF_FLASHIAP_BLOCK_DEVICE_SIZE);
|
||||||
|
|
||||||
virtual ~FlashIAPBlockDevice();
|
virtual ~FlashIAPBlockDevice();
|
||||||
|
|
||||||
/** Initialize a block device
|
/** Initialize a block device
|
||||||
|
|
|
@ -182,7 +182,7 @@ int QSPIFBlockDevice::init()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Soft Reset
|
// Soft Reset
|
||||||
if ( -1 == _reset_flash_mem()) {
|
if (-1 == _reset_flash_mem()) {
|
||||||
tr_error("Init - Unable to initialize flash memory, tests failed");
|
tr_error("Init - Unable to initialize flash memory, tests failed");
|
||||||
status = QSPIF_BD_ERROR_DEVICE_ERROR;
|
status = QSPIF_BD_ERROR_DEVICE_ERROR;
|
||||||
goto exit_point;
|
goto exit_point;
|
||||||
|
@ -192,7 +192,7 @@ int QSPIFBlockDevice::init()
|
||||||
|
|
||||||
/* Read Manufacturer ID (1byte), and Device ID (2bytes)*/
|
/* Read Manufacturer ID (1byte), and Device ID (2bytes)*/
|
||||||
qspi_status = _qspi_send_general_command(QSPIF_RDID, QSPI_NO_ADDRESS_COMMAND, NULL, 0, (char *)vendor_device_ids,
|
qspi_status = _qspi_send_general_command(QSPIF_RDID, QSPI_NO_ADDRESS_COMMAND, NULL, 0, (char *)vendor_device_ids,
|
||||||
data_length);
|
data_length);
|
||||||
if (qspi_status != QSPI_STATUS_OK) {
|
if (qspi_status != QSPI_STATUS_OK) {
|
||||||
tr_error("Init - Read Vendor ID Failed");
|
tr_error("Init - Read Vendor ID Failed");
|
||||||
status = QSPIF_BD_ERROR_DEVICE_ERROR;
|
status = QSPIF_BD_ERROR_DEVICE_ERROR;
|
||||||
|
@ -211,21 +211,21 @@ int QSPIFBlockDevice::init()
|
||||||
}
|
}
|
||||||
|
|
||||||
//Synchronize Device
|
//Synchronize Device
|
||||||
if ( false == _is_mem_ready()) {
|
if (false == _is_mem_ready()) {
|
||||||
tr_error("Init - _is_mem_ready Failed");
|
tr_error("Init - _is_mem_ready Failed");
|
||||||
status = QSPIF_BD_ERROR_READY_FAILED;
|
status = QSPIF_BD_ERROR_READY_FAILED;
|
||||||
goto exit_point;
|
goto exit_point;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************** Parse SFDP Header ***********************************/
|
/**************************** Parse SFDP Header ***********************************/
|
||||||
if ( 0 != _sfdp_parse_sfdp_headers(basic_table_addr, basic_table_size, sector_map_table_addr, sector_map_table_size)) {
|
if (0 != _sfdp_parse_sfdp_headers(basic_table_addr, basic_table_size, sector_map_table_addr, sector_map_table_size)) {
|
||||||
tr_error("Init - Parse SFDP Headers Failed");
|
tr_error("Init - Parse SFDP Headers Failed");
|
||||||
status = QSPIF_BD_ERROR_PARSING_FAILED;
|
status = QSPIF_BD_ERROR_PARSING_FAILED;
|
||||||
goto exit_point;
|
goto exit_point;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************** Parse Basic Parameters Table ***********************************/
|
/**************************** Parse Basic Parameters Table ***********************************/
|
||||||
if ( 0 != _sfdp_parse_basic_param_table(basic_table_addr, basic_table_size) ) {
|
if (0 != _sfdp_parse_basic_param_table(basic_table_addr, basic_table_size)) {
|
||||||
tr_error("Init - Parse Basic Param Table Failed");
|
tr_error("Init - Parse Basic Param Table Failed");
|
||||||
status = QSPIF_BD_ERROR_PARSING_FAILED;
|
status = QSPIF_BD_ERROR_PARSING_FAILED;
|
||||||
goto exit_point;
|
goto exit_point;
|
||||||
|
@ -236,10 +236,10 @@ int QSPIFBlockDevice::init()
|
||||||
_device_size_bytes; // If there's no region map, we have a single region sized the entire device size
|
_device_size_bytes; // If there's no region map, we have a single region sized the entire device size
|
||||||
_region_high_boundary[0] = _device_size_bytes - 1;
|
_region_high_boundary[0] = _device_size_bytes - 1;
|
||||||
|
|
||||||
if ( (sector_map_table_addr != 0) && (0 != sector_map_table_size) ) {
|
if ((sector_map_table_addr != 0) && (0 != sector_map_table_size)) {
|
||||||
tr_info("Init - Parsing Sector Map Table - addr: 0x%lxh, Size: %d", sector_map_table_addr,
|
tr_info("Init - Parsing Sector Map Table - addr: 0x%lxh, Size: %d", sector_map_table_addr,
|
||||||
sector_map_table_size);
|
sector_map_table_size);
|
||||||
if (0 != _sfdp_parse_sector_map_table(sector_map_table_addr, sector_map_table_size) ) {
|
if (0 != _sfdp_parse_sector_map_table(sector_map_table_addr, sector_map_table_size)) {
|
||||||
tr_error("Init - Parse Sector Map Table Failed");
|
tr_error("Init - Parse Sector Map Table Failed");
|
||||||
status = QSPIF_BD_ERROR_PARSING_FAILED;
|
status = QSPIF_BD_ERROR_PARSING_FAILED;
|
||||||
goto exit_point;
|
goto exit_point;
|
||||||
|
@ -348,7 +348,7 @@ int QSPIFBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t size
|
||||||
}
|
}
|
||||||
|
|
||||||
result = _qspi_send_program_command(_prog_instruction, buffer, addr, &written_bytes);
|
result = _qspi_send_program_command(_prog_instruction, buffer, addr, &written_bytes);
|
||||||
if ( (result != QSPI_STATUS_OK) || (chunk != written_bytes) ) {
|
if ((result != QSPI_STATUS_OK) || (chunk != written_bytes)) {
|
||||||
tr_error("Write failed");
|
tr_error("Write failed");
|
||||||
program_failed = true;
|
program_failed = true;
|
||||||
status = QSPIF_BD_ERROR_DEVICE_ERROR;
|
status = QSPIF_BD_ERROR_DEVICE_ERROR;
|
||||||
|
@ -359,7 +359,7 @@ int QSPIFBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t size
|
||||||
addr += chunk;
|
addr += chunk;
|
||||||
size -= chunk;
|
size -= chunk;
|
||||||
|
|
||||||
if ( false == _is_mem_ready()) {
|
if (false == _is_mem_ready()) {
|
||||||
tr_error("Device not ready after write, failed");
|
tr_error("Device not ready after write, failed");
|
||||||
program_failed = true;
|
program_failed = true;
|
||||||
status = QSPIF_BD_ERROR_READY_FAILED;
|
status = QSPIF_BD_ERROR_READY_FAILED;
|
||||||
|
@ -397,7 +397,7 @@ int QSPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
|
||||||
return QSPIF_BD_ERROR_INVALID_ERASE_PARAMS;
|
return QSPIF_BD_ERROR_INVALID_ERASE_PARAMS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ((addr % get_erase_size(addr)) != 0 ) || (((addr + in_size) % get_erase_size(addr + in_size - 1)) != 0 ) ) {
|
if (((addr % get_erase_size(addr)) != 0) || (((addr + in_size) % get_erase_size(addr + in_size - 1)) != 0)) {
|
||||||
tr_error("Invalid erase - unaligned address and size");
|
tr_error("Invalid erase - unaligned address and size");
|
||||||
return QSPIF_BD_ERROR_INVALID_ERASE_PARAMS;
|
return QSPIF_BD_ERROR_INVALID_ERASE_PARAMS;
|
||||||
}
|
}
|
||||||
|
@ -409,7 +409,7 @@ int QSPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
|
||||||
type = _utils_iterate_next_largest_erase_type(bitfield, size, (int)addr, _region_high_boundary[region]);
|
type = _utils_iterate_next_largest_erase_type(bitfield, size, (int)addr, _region_high_boundary[region]);
|
||||||
cur_erase_inst = _erase_type_inst_arr[type];
|
cur_erase_inst = _erase_type_inst_arr[type];
|
||||||
offset = addr % _erase_type_size_arr[type];
|
offset = addr % _erase_type_size_arr[type];
|
||||||
chunk = ( (offset + size) < _erase_type_size_arr[type]) ? size : (_erase_type_size_arr[type] - offset);
|
chunk = ((offset + size) < _erase_type_size_arr[type]) ? size : (_erase_type_size_arr[type] - offset);
|
||||||
|
|
||||||
tr_debug("Erase - addr: %llu, size:%d, Inst: 0x%xh, chunk: %lu ",
|
tr_debug("Erase - addr: %llu, size:%d, Inst: 0x%xh, chunk: %lu ",
|
||||||
addr, size, cur_erase_inst, chunk);
|
addr, size, cur_erase_inst, chunk);
|
||||||
|
@ -425,7 +425,7 @@ int QSPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
|
||||||
goto exit_point;
|
goto exit_point;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (QSPI_STATUS_OK != _qspi_send_erase_command(cur_erase_inst, addr, size) ) {
|
if (QSPI_STATUS_OK != _qspi_send_erase_command(cur_erase_inst, addr, size)) {
|
||||||
tr_error("QSPI Erase command failed!");
|
tr_error("QSPI Erase command failed!");
|
||||||
erase_failed = true;
|
erase_failed = true;
|
||||||
status = QSPIF_BD_ERROR_DEVICE_ERROR;
|
status = QSPIF_BD_ERROR_DEVICE_ERROR;
|
||||||
|
@ -435,13 +435,13 @@ int QSPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
|
||||||
addr += chunk;
|
addr += chunk;
|
||||||
size -= chunk;
|
size -= chunk;
|
||||||
|
|
||||||
if ( (size > 0) && (addr > _region_high_boundary[region]) ) {
|
if ((size > 0) && (addr > _region_high_boundary[region])) {
|
||||||
// erase crossed to next region
|
// erase crossed to next region
|
||||||
region++;
|
region++;
|
||||||
bitfield = _region_erase_types_bitfield[region];
|
bitfield = _region_erase_types_bitfield[region];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( false == _is_mem_ready()) {
|
if (false == _is_mem_ready()) {
|
||||||
tr_error("QSPI After Erase Device not ready - failed");
|
tr_error("QSPI After Erase Device not ready - failed");
|
||||||
erase_failed = true;
|
erase_failed = true;
|
||||||
status = QSPIF_BD_ERROR_READY_FAILED;
|
status = QSPIF_BD_ERROR_READY_FAILED;
|
||||||
|
@ -525,7 +525,7 @@ int QSPIFBlockDevice::get_erase_value() const
|
||||||
static PinName *generate_initialized_active_qspif_csel_arr()
|
static PinName *generate_initialized_active_qspif_csel_arr()
|
||||||
{
|
{
|
||||||
PinName *init_arr = new PinName[QSPIF_MAX_ACTIVE_FLASH_DEVICES];
|
PinName *init_arr = new PinName[QSPIF_MAX_ACTIVE_FLASH_DEVICES];
|
||||||
for ( int i_ind = 0; i_ind < QSPIF_MAX_ACTIVE_FLASH_DEVICES; i_ind++ ) {
|
for (int i_ind = 0; i_ind < QSPIF_MAX_ACTIVE_FLASH_DEVICES; i_ind++) {
|
||||||
init_arr[i_ind] = NC;
|
init_arr[i_ind] = NC;
|
||||||
}
|
}
|
||||||
return init_arr;
|
return init_arr;
|
||||||
|
@ -535,13 +535,13 @@ int QSPIFBlockDevice::add_new_csel_instance(PinName csel)
|
||||||
{
|
{
|
||||||
int status = 0;
|
int status = 0;
|
||||||
_devices_mutex->lock();
|
_devices_mutex->lock();
|
||||||
if (_number_of_active_qspif_flash_csel >= QSPIF_MAX_ACTIVE_FLASH_DEVICES ) {
|
if (_number_of_active_qspif_flash_csel >= QSPIF_MAX_ACTIVE_FLASH_DEVICES) {
|
||||||
status = -2;
|
status = -2;
|
||||||
goto exit_point;
|
goto exit_point;
|
||||||
}
|
}
|
||||||
|
|
||||||
// verify the device is unique(no identical csel already exists)
|
// verify the device is unique(no identical csel already exists)
|
||||||
for ( int i_ind = 0; i_ind < QSPIF_MAX_ACTIVE_FLASH_DEVICES; i_ind++ ) {
|
for (int i_ind = 0; i_ind < QSPIF_MAX_ACTIVE_FLASH_DEVICES; i_ind++) {
|
||||||
if (_active_qspif_flash_csel_arr[i_ind] == csel) {
|
if (_active_qspif_flash_csel_arr[i_ind] == csel) {
|
||||||
status = -1;
|
status = -1;
|
||||||
goto exit_point;
|
goto exit_point;
|
||||||
|
@ -549,7 +549,7 @@ int QSPIFBlockDevice::add_new_csel_instance(PinName csel)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert new csel into existing device list
|
// Insert new csel into existing device list
|
||||||
for ( int i_ind = 0; i_ind < QSPIF_MAX_ACTIVE_FLASH_DEVICES; i_ind++ ) {
|
for (int i_ind = 0; i_ind < QSPIF_MAX_ACTIVE_FLASH_DEVICES; i_ind++) {
|
||||||
if (_active_qspif_flash_csel_arr[i_ind] == NC) {
|
if (_active_qspif_flash_csel_arr[i_ind] == NC) {
|
||||||
_active_qspif_flash_csel_arr[i_ind] = csel;
|
_active_qspif_flash_csel_arr[i_ind] = csel;
|
||||||
break;
|
break;
|
||||||
|
@ -567,7 +567,7 @@ int QSPIFBlockDevice::remove_csel_instance(PinName csel)
|
||||||
int status = -1;
|
int status = -1;
|
||||||
_devices_mutex->lock();
|
_devices_mutex->lock();
|
||||||
// remove the csel from existing device list
|
// remove the csel from existing device list
|
||||||
for ( int i_ind = 0; i_ind < QSPIF_MAX_ACTIVE_FLASH_DEVICES; i_ind++ ) {
|
for (int i_ind = 0; i_ind < QSPIF_MAX_ACTIVE_FLASH_DEVICES; i_ind++) {
|
||||||
if (_active_qspif_flash_csel_arr[i_ind] == csel) {
|
if (_active_qspif_flash_csel_arr[i_ind] == csel) {
|
||||||
_active_qspif_flash_csel_arr[i_ind] = NC;
|
_active_qspif_flash_csel_arr[i_ind] = NC;
|
||||||
if (_number_of_active_qspif_flash_csel > 0) {
|
if (_number_of_active_qspif_flash_csel > 0) {
|
||||||
|
@ -595,14 +595,14 @@ int QSPIFBlockDevice::_sfdp_parse_sector_map_table(uint32_t sector_map_table_add
|
||||||
|
|
||||||
|
|
||||||
qspi_status_t status = _qspi_send_read_command(QSPIF_SFDP, (char *)sector_map_table, sector_map_table_addr /*address*/,
|
qspi_status_t status = _qspi_send_read_command(QSPIF_SFDP, (char *)sector_map_table, sector_map_table_addr /*address*/,
|
||||||
sector_map_table_size);
|
sector_map_table_size);
|
||||||
if (status != QSPI_STATUS_OK) {
|
if (status != QSPI_STATUS_OK) {
|
||||||
tr_error("Init - Read SFDP First Table Failed");
|
tr_error("Init - Read SFDP First Table Failed");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Currently we support only Single Map Descriptor
|
// Currently we support only Single Map Descriptor
|
||||||
if (! ( (sector_map_table[0] & 0x3) == 0x03 ) && (sector_map_table[1] == 0x0) ) {
|
if (!((sector_map_table[0] & 0x3) == 0x03) && (sector_map_table[1] == 0x0)) {
|
||||||
tr_error("Sector Map - Supporting Only Single! Map Descriptor (not map commands)");
|
tr_error("Sector Map - Supporting Only Single! Map Descriptor (not map commands)");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -648,7 +648,7 @@ int QSPIFBlockDevice::_sfdp_parse_basic_param_table(uint32_t basic_table_addr, s
|
||||||
uint8_t param_table[SFDP_DEFAULT_BASIC_PARAMS_TABLE_SIZE_BYTES]; /* Up To 16 DWORDS = 64 Bytes */
|
uint8_t param_table[SFDP_DEFAULT_BASIC_PARAMS_TABLE_SIZE_BYTES]; /* Up To 16 DWORDS = 64 Bytes */
|
||||||
|
|
||||||
qspi_status_t status = _qspi_send_read_command(QSPIF_SFDP, (char *)param_table, basic_table_addr /*address*/,
|
qspi_status_t status = _qspi_send_read_command(QSPIF_SFDP, (char *)param_table, basic_table_addr /*address*/,
|
||||||
basic_table_size);
|
basic_table_size);
|
||||||
if (status != QSPI_STATUS_OK) {
|
if (status != QSPI_STATUS_OK) {
|
||||||
tr_error("Init - Read SFDP First Table Failed");
|
tr_error("Init - Read SFDP First Table Failed");
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -664,8 +664,8 @@ int QSPIFBlockDevice::_sfdp_parse_basic_param_table(uint32_t basic_table_addr, s
|
||||||
uint32_t density_bits = (
|
uint32_t density_bits = (
|
||||||
(param_table[7] << 24) |
|
(param_table[7] << 24) |
|
||||||
(param_table[6] << 16) |
|
(param_table[6] << 16) |
|
||||||
(param_table[5] << 8 ) |
|
(param_table[5] << 8) |
|
||||||
param_table[4] );
|
param_table[4]);
|
||||||
_device_size_bytes = (density_bits + 1) / 8;
|
_device_size_bytes = (density_bits + 1) / 8;
|
||||||
|
|
||||||
// Set Default read/program/erase Instructions
|
// Set Default read/program/erase Instructions
|
||||||
|
@ -704,8 +704,8 @@ int QSPIFBlockDevice::_sfdp_parse_basic_param_table(uint32_t basic_table_addr, s
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int QSPIFBlockDevice::_sfdp_parse_sfdp_headers(uint32_t& basic_table_addr, size_t& basic_table_size,
|
int QSPIFBlockDevice::_sfdp_parse_sfdp_headers(uint32_t &basic_table_addr, size_t &basic_table_size,
|
||||||
uint32_t& sector_map_table_addr, size_t& sector_map_table_size)
|
uint32_t §or_map_table_addr, size_t §or_map_table_size)
|
||||||
{
|
{
|
||||||
uint8_t sfdp_header[QSPIF_SFDP_HEADER_SIZE];
|
uint8_t sfdp_header[QSPIF_SFDP_HEADER_SIZE];
|
||||||
uint8_t param_header[QSPIF_PARAM_HEADER_SIZE];
|
uint8_t param_header[QSPIF_PARAM_HEADER_SIZE];
|
||||||
|
@ -758,14 +758,14 @@ int QSPIFBlockDevice::_sfdp_parse_sfdp_headers(uint32_t& basic_table_addr, size_
|
||||||
if ((param_header[0] == 0) && (param_header[7] == 0xFF)) {
|
if ((param_header[0] == 0) && (param_header[7] == 0xFF)) {
|
||||||
// Found Basic Params Table: LSB=0x00, MSB=0xFF
|
// Found Basic Params Table: LSB=0x00, MSB=0xFF
|
||||||
tr_debug("Found Basic Param Table at Table: %d", i_ind + 1);
|
tr_debug("Found Basic Param Table at Table: %d", i_ind + 1);
|
||||||
basic_table_addr = ( (param_header[6] << 16) | (param_header[5] << 8) | (param_header[4]) );
|
basic_table_addr = ((param_header[6] << 16) | (param_header[5] << 8) | (param_header[4]));
|
||||||
// Supporting up to 64 Bytes Table (16 DWORDS)
|
// Supporting up to 64 Bytes Table (16 DWORDS)
|
||||||
basic_table_size = ((param_header[3] * 4) < SFDP_DEFAULT_BASIC_PARAMS_TABLE_SIZE_BYTES) ? (param_header[3] * 4) : 64;
|
basic_table_size = ((param_header[3] * 4) < SFDP_DEFAULT_BASIC_PARAMS_TABLE_SIZE_BYTES) ? (param_header[3] * 4) : 64;
|
||||||
|
|
||||||
} else if ((param_header[0] == 81) && (param_header[7] == 0xFF)) {
|
} else if ((param_header[0] == 81) && (param_header[7] == 0xFF)) {
|
||||||
// Found Sector Map Table: LSB=0x81, MSB=0xFF
|
// Found Sector Map Table: LSB=0x81, MSB=0xFF
|
||||||
tr_debug("Found Sector Map Table at Table: %d", i_ind + 1);
|
tr_debug("Found Sector Map Table at Table: %d", i_ind + 1);
|
||||||
sector_map_table_addr = ( (param_header[6] << 16) | (param_header[5] << 8) | (param_header[4]) );
|
sector_map_table_addr = ((param_header[6] << 16) | (param_header[5] << 8) | (param_header[4]));
|
||||||
sector_map_table_size = param_header[3] * 4;
|
sector_map_table_size = param_header[3] * 4;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -780,43 +780,43 @@ int QSPIFBlockDevice::_sfdp_set_qpi_enabled(uint8_t *basic_param_table_ptr)
|
||||||
uint8_t config_reg[1];
|
uint8_t config_reg[1];
|
||||||
|
|
||||||
// QPI 4-4-4 Enable Procedure is specified in 5 Bits
|
// QPI 4-4-4 Enable Procedure is specified in 5 Bits
|
||||||
uint8_t en_seq_444_value = ( ((basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_444_MODE_EN_SEQ_BYTE] & 0xF0) >> 4) | ((
|
uint8_t en_seq_444_value = (((basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_444_MODE_EN_SEQ_BYTE] & 0xF0) >> 4) | ((
|
||||||
basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_444_MODE_EN_SEQ_BYTE + 1] & 0x01) << 4 ));
|
basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_444_MODE_EN_SEQ_BYTE + 1] & 0x01) << 4));
|
||||||
|
|
||||||
switch (en_seq_444_value) {
|
switch (en_seq_444_value) {
|
||||||
case 1:
|
case 1:
|
||||||
case 2:
|
case 2:
|
||||||
tr_debug("_sfdp_set_qpi_enabled - send command 38h");
|
tr_debug("_sfdp_set_qpi_enabled - send command 38h");
|
||||||
if (QSPI_STATUS_OK != _qspi_send_general_command(0x38, QSPI_NO_ADDRESS_COMMAND, NULL, 0, NULL, 0)) {
|
if (QSPI_STATUS_OK != _qspi_send_general_command(0x38, QSPI_NO_ADDRESS_COMMAND, NULL, 0, NULL, 0)) {
|
||||||
tr_error("_sfdp_set_qpi_enabled - send command 38h Failed");
|
tr_error("_sfdp_set_qpi_enabled - send command 38h Failed");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
tr_debug("_sfdp_set_qpi_enabled - send command 35h");
|
tr_debug("_sfdp_set_qpi_enabled - send command 35h");
|
||||||
if (QSPI_STATUS_OK != _qspi_send_general_command(0x35, QSPI_NO_ADDRESS_COMMAND, NULL, 0, NULL, 0)) {
|
if (QSPI_STATUS_OK != _qspi_send_general_command(0x35, QSPI_NO_ADDRESS_COMMAND, NULL, 0, NULL, 0)) {
|
||||||
tr_error("_sfdp_set_qpi_enabled - send command 35h Failed");
|
tr_error("_sfdp_set_qpi_enabled - send command 35h Failed");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 8:
|
case 8:
|
||||||
tr_debug("_sfdp_set_qpi_enabled - set config bit 6 and send command 71h");
|
tr_debug("_sfdp_set_qpi_enabled - set config bit 6 and send command 71h");
|
||||||
if (QSPI_STATUS_OK != _qspi_send_general_command(0x65, 0x800003, NULL, 0, (char *)config_reg, 1)) {
|
if (QSPI_STATUS_OK != _qspi_send_general_command(0x65, 0x800003, NULL, 0, (char *)config_reg, 1)) {
|
||||||
tr_error("_sfdp_set_qpi_enabled - set config bit 6 command 65h Failed");
|
tr_error("_sfdp_set_qpi_enabled - set config bit 6 command 65h Failed");
|
||||||
}
|
}
|
||||||
config_reg[0] |= 0x40; //Set Bit 6
|
config_reg[0] |= 0x40; //Set Bit 6
|
||||||
if (QSPI_STATUS_OK != _qspi_send_general_command(0x71, 0x800003, NULL, 0, (char *)config_reg, 1)) {
|
if (QSPI_STATUS_OK != _qspi_send_general_command(0x71, 0x800003, NULL, 0, (char *)config_reg, 1)) {
|
||||||
tr_error("_sfdp_set_qpi_enabled - send command 71h Failed");
|
tr_error("_sfdp_set_qpi_enabled - send command 71h Failed");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 16:
|
case 16:
|
||||||
tr_debug("_sfdp_set_qpi_enabled - reset config bits 0-7 and send command 61h");
|
tr_debug("_sfdp_set_qpi_enabled - reset config bits 0-7 and send command 61h");
|
||||||
if (QSPI_STATUS_OK != _qspi_send_general_command(0x65, QSPI_NO_ADDRESS_COMMAND, NULL, 0, (char *)config_reg, 1)) {
|
if (QSPI_STATUS_OK != _qspi_send_general_command(0x65, QSPI_NO_ADDRESS_COMMAND, NULL, 0, (char *)config_reg, 1)) {
|
||||||
tr_error("_sfdp_set_qpi_enabled - send command 65h Failed");
|
tr_error("_sfdp_set_qpi_enabled - send command 65h Failed");
|
||||||
}
|
}
|
||||||
config_reg[0] &= 0x7F; //Reset Bit 7 of CR
|
config_reg[0] &= 0x7F; //Reset Bit 7 of CR
|
||||||
if (QSPI_STATUS_OK != _qspi_send_general_command(0x61, QSPI_NO_ADDRESS_COMMAND, NULL, 0, (char *)config_reg, 1)) {
|
if (QSPI_STATUS_OK != _qspi_send_general_command(0x61, QSPI_NO_ADDRESS_COMMAND, NULL, 0, (char *)config_reg, 1)) {
|
||||||
tr_error("_sfdp_set_qpi_enabled - send command 61 Failed");
|
tr_error("_sfdp_set_qpi_enabled - send command 61 Failed");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -883,8 +883,8 @@ int QSPIFBlockDevice::_sfdp_set_quad_enabled(uint8_t *basic_param_table_ptr)
|
||||||
|
|
||||||
// Read Status Register
|
// Read Status Register
|
||||||
if (QSPI_STATUS_OK == _qspi_send_general_command(_read_register_inst, QSPI_NO_ADDRESS_COMMAND, NULL, 0,
|
if (QSPI_STATUS_OK == _qspi_send_general_command(_read_register_inst, QSPI_NO_ADDRESS_COMMAND, NULL, 0,
|
||||||
status_reg,
|
status_reg,
|
||||||
sr_read_size) ) { // store received values in status_value
|
sr_read_size)) { // store received values in status_value
|
||||||
tr_debug("Reading Status Register Success: value = 0x%x", (int)status_reg[0]);
|
tr_debug("Reading Status Register Success: value = 0x%x", (int)status_reg[0]);
|
||||||
} else {
|
} else {
|
||||||
tr_error("Reading Status Register failed");
|
tr_error("Reading Status Register failed");
|
||||||
|
@ -903,8 +903,8 @@ int QSPIFBlockDevice::_sfdp_set_quad_enabled(uint8_t *basic_param_table_ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (QSPI_STATUS_OK == _qspi_send_general_command(_write_register_inst, QSPI_NO_ADDRESS_COMMAND, (char *)status_reg,
|
if (QSPI_STATUS_OK == _qspi_send_general_command(_write_register_inst, QSPI_NO_ADDRESS_COMMAND, (char *)status_reg,
|
||||||
sr_write_size, NULL,
|
sr_write_size, NULL,
|
||||||
0) ) { // Write QE to status_register
|
0)) { // Write QE to status_register
|
||||||
tr_debug("_setQuadEnable - Writing Status Register Success: value = 0x%x",
|
tr_debug("_setQuadEnable - Writing Status Register Success: value = 0x%x",
|
||||||
(int)status_reg[0]);
|
(int)status_reg[0]);
|
||||||
} else {
|
} else {
|
||||||
|
@ -912,7 +912,7 @@ int QSPIFBlockDevice::_sfdp_set_quad_enabled(uint8_t *basic_param_table_ptr)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( false == _is_mem_ready()) {
|
if (false == _is_mem_ready()) {
|
||||||
tr_error("Device not ready after write, failed");
|
tr_error("Device not ready after write, failed");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -921,8 +921,8 @@ int QSPIFBlockDevice::_sfdp_set_quad_enabled(uint8_t *basic_param_table_ptr)
|
||||||
// For Debug
|
// For Debug
|
||||||
memset(status_reg, 0, QSPI_MAX_STATUS_REGISTER_SIZE);
|
memset(status_reg, 0, QSPI_MAX_STATUS_REGISTER_SIZE);
|
||||||
if (QSPI_STATUS_OK == _qspi_send_general_command(_read_register_inst, QSPI_NO_ADDRESS_COMMAND, NULL, 0,
|
if (QSPI_STATUS_OK == _qspi_send_general_command(_read_register_inst, QSPI_NO_ADDRESS_COMMAND, NULL, 0,
|
||||||
(char *)status_reg,
|
(char *)status_reg,
|
||||||
sr_read_size) ) { // store received values in status_value
|
sr_read_size)) { // store received values in status_value
|
||||||
tr_debug("Reading Status Register Success: value = 0x%x", (int)status_reg[0]);
|
tr_debug("Reading Status Register Success: value = 0x%x", (int)status_reg[0]);
|
||||||
} else {
|
} else {
|
||||||
tr_error("Reading Status Register failed");
|
tr_error("Reading Status Register failed");
|
||||||
|
@ -938,7 +938,7 @@ int QSPIFBlockDevice::_sfdp_detect_page_size(uint8_t *basic_param_table_ptr, int
|
||||||
|
|
||||||
if (basic_param_table_size > QSPIF_BASIC_PARAM_TABLE_PAGE_SIZE_BYTE) {
|
if (basic_param_table_size > QSPIF_BASIC_PARAM_TABLE_PAGE_SIZE_BYTE) {
|
||||||
// Page Size is specified by 4 Bits (N), calculated by 2^N
|
// Page Size is specified by 4 Bits (N), calculated by 2^N
|
||||||
int page_to_power_size = ( (int)basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_PAGE_SIZE_BYTE]) >> 4;
|
int page_to_power_size = ((int)basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_PAGE_SIZE_BYTE]) >> 4;
|
||||||
page_size = local_math_power(2, page_to_power_size);
|
page_size = local_math_power(2, page_to_power_size);
|
||||||
tr_debug("Detected Page Size: %d", page_size);
|
tr_debug("Detected Page Size: %d", page_size);
|
||||||
} else {
|
} else {
|
||||||
|
@ -948,8 +948,8 @@ int QSPIFBlockDevice::_sfdp_detect_page_size(uint8_t *basic_param_table_ptr, int
|
||||||
}
|
}
|
||||||
|
|
||||||
int QSPIFBlockDevice::_sfdp_detect_erase_types_inst_and_size(uint8_t *basic_param_table_ptr, int basic_param_table_size,
|
int QSPIFBlockDevice::_sfdp_detect_erase_types_inst_and_size(uint8_t *basic_param_table_ptr, int basic_param_table_size,
|
||||||
unsigned int& erase4k_inst,
|
unsigned int &erase4k_inst,
|
||||||
unsigned int *erase_type_inst_arr, unsigned int *erase_type_size_arr)
|
unsigned int *erase_type_inst_arr, unsigned int *erase_type_size_arr)
|
||||||
{
|
{
|
||||||
erase4k_inst = 0xff;
|
erase4k_inst = 0xff;
|
||||||
bool found_4Kerase_type = false;
|
bool found_4Kerase_type = false;
|
||||||
|
@ -963,14 +963,14 @@ int QSPIFBlockDevice::_sfdp_detect_erase_types_inst_and_size(uint8_t *basic_para
|
||||||
for (int i_ind = 0; i_ind < 4; i_ind++) {
|
for (int i_ind = 0; i_ind < 4; i_ind++) {
|
||||||
erase_type_inst_arr[i_ind] = 0xff; //0xFF default for unsupported type
|
erase_type_inst_arr[i_ind] = 0xff; //0xFF default for unsupported type
|
||||||
erase_type_size_arr[i_ind] = local_math_power(2,
|
erase_type_size_arr[i_ind] = local_math_power(2,
|
||||||
basic_param_table_ptr[QSPIF_BASIC_PARAM_ERASE_TYPE_1_SIZE_BYTE + 2 * i_ind]); // Size given as 2^N
|
basic_param_table_ptr[QSPIF_BASIC_PARAM_ERASE_TYPE_1_SIZE_BYTE + 2 * i_ind]); // Size given as 2^N
|
||||||
tr_info("Erase Type(A) %d - Inst: 0x%xh, Size: %d", (i_ind + 1), erase_type_inst_arr[i_ind],
|
tr_info("Erase Type(A) %d - Inst: 0x%xh, Size: %d", (i_ind + 1), erase_type_inst_arr[i_ind],
|
||||||
erase_type_size_arr[i_ind]);
|
erase_type_size_arr[i_ind]);
|
||||||
if (erase_type_size_arr[i_ind] > 1) {
|
if (erase_type_size_arr[i_ind] > 1) {
|
||||||
// if size==1 type is not supported
|
// if size==1 type is not supported
|
||||||
erase_type_inst_arr[i_ind] = basic_param_table_ptr[QSPIF_BASIC_PARAM_ERASE_TYPE_1_BYTE + 2 * i_ind];
|
erase_type_inst_arr[i_ind] = basic_param_table_ptr[QSPIF_BASIC_PARAM_ERASE_TYPE_1_BYTE + 2 * i_ind];
|
||||||
|
|
||||||
if ((erase_type_size_arr[i_ind] < _min_common_erase_size) || (_min_common_erase_size == 0) ) {
|
if ((erase_type_size_arr[i_ind] < _min_common_erase_size) || (_min_common_erase_size == 0)) {
|
||||||
//Set default minimal common erase for singal region
|
//Set default minimal common erase for singal region
|
||||||
_min_common_erase_size = erase_type_size_arr[i_ind];
|
_min_common_erase_size = erase_type_size_arr[i_ind];
|
||||||
}
|
}
|
||||||
|
@ -1001,8 +1001,8 @@ int QSPIFBlockDevice::_sfdp_detect_erase_types_inst_and_size(uint8_t *basic_para
|
||||||
}
|
}
|
||||||
|
|
||||||
int QSPIFBlockDevice::_sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table_ptr, int basic_param_table_size,
|
int QSPIFBlockDevice::_sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table_ptr, int basic_param_table_size,
|
||||||
bool& set_quad_enable,
|
bool &set_quad_enable,
|
||||||
bool& is_qpi_mode, unsigned int& read_inst)
|
bool &is_qpi_mode, unsigned int &read_inst)
|
||||||
{
|
{
|
||||||
set_quad_enable = false;
|
set_quad_enable = false;
|
||||||
is_qpi_mode = false;
|
is_qpi_mode = false;
|
||||||
|
@ -1100,7 +1100,7 @@ int QSPIFBlockDevice::_reset_flash_mem()
|
||||||
tr_info("_reset_flash_mem:");
|
tr_info("_reset_flash_mem:");
|
||||||
//Read the Status Register from device
|
//Read the Status Register from device
|
||||||
if (QSPI_STATUS_OK == _qspi_send_general_command(QSPIF_RDSR, QSPI_NO_ADDRESS_COMMAND, NULL, 0, status_value,
|
if (QSPI_STATUS_OK == _qspi_send_general_command(QSPIF_RDSR, QSPI_NO_ADDRESS_COMMAND, NULL, 0, status_value,
|
||||||
QSPI_MAX_STATUS_REGISTER_SIZE) ) { // store received values in status_value
|
QSPI_MAX_STATUS_REGISTER_SIZE)) { // store received values in status_value
|
||||||
tr_debug("Reading Status Register Success: value = 0x%x", (int)status_value[0]);
|
tr_debug("Reading Status Register Success: value = 0x%x", (int)status_value[0]);
|
||||||
} else {
|
} else {
|
||||||
tr_error("Reading Status Register failed: value = 0x%x", (int)status_value[0]);
|
tr_error("Reading Status Register failed: value = 0x%x", (int)status_value[0]);
|
||||||
|
@ -1110,7 +1110,7 @@ int QSPIFBlockDevice::_reset_flash_mem()
|
||||||
if (0 == status) {
|
if (0 == status) {
|
||||||
//Send Reset Enable
|
//Send Reset Enable
|
||||||
if (QSPI_STATUS_OK == _qspi_send_general_command(QSPIF_RSTEN, QSPI_NO_ADDRESS_COMMAND, NULL, 0, NULL,
|
if (QSPI_STATUS_OK == _qspi_send_general_command(QSPIF_RSTEN, QSPI_NO_ADDRESS_COMMAND, NULL, 0, NULL,
|
||||||
0) ) { // store received values in status_value
|
0)) { // store received values in status_value
|
||||||
tr_debug("Sending RSTEN Success");
|
tr_debug("Sending RSTEN Success");
|
||||||
} else {
|
} else {
|
||||||
tr_error("Sending RSTEN failed");
|
tr_error("Sending RSTEN failed");
|
||||||
|
@ -1121,7 +1121,7 @@ int QSPIFBlockDevice::_reset_flash_mem()
|
||||||
if (0 == status) {
|
if (0 == status) {
|
||||||
//Send Reset
|
//Send Reset
|
||||||
if (QSPI_STATUS_OK == _qspi_send_general_command(QSPIF_RST, QSPI_NO_ADDRESS_COMMAND, NULL, 0, NULL,
|
if (QSPI_STATUS_OK == _qspi_send_general_command(QSPIF_RST, QSPI_NO_ADDRESS_COMMAND, NULL, 0, NULL,
|
||||||
0)) { // store received values in status_value
|
0)) { // store received values in status_value
|
||||||
tr_debug("Sending RST Success");
|
tr_debug("Sending RST Success");
|
||||||
} else {
|
} else {
|
||||||
tr_error("Sending RST failed");
|
tr_error("Sending RST failed");
|
||||||
|
@ -1148,10 +1148,10 @@ bool QSPIFBlockDevice::_is_mem_ready()
|
||||||
//Read the Status Register from device
|
//Read the Status Register from device
|
||||||
memset(status_value, 0xFF, QSPI_MAX_STATUS_REGISTER_SIZE);
|
memset(status_value, 0xFF, QSPI_MAX_STATUS_REGISTER_SIZE);
|
||||||
if (QSPI_STATUS_OK != _qspi_send_general_command(QSPIF_RDSR, QSPI_NO_ADDRESS_COMMAND, NULL, 0, status_value,
|
if (QSPI_STATUS_OK != _qspi_send_general_command(QSPIF_RDSR, QSPI_NO_ADDRESS_COMMAND, NULL, 0, status_value,
|
||||||
QSPI_MAX_STATUS_REGISTER_SIZE)) { // store received values in status_value
|
QSPI_MAX_STATUS_REGISTER_SIZE)) { // store received values in status_value
|
||||||
tr_error("Reading Status Register failed");
|
tr_error("Reading Status Register failed");
|
||||||
}
|
}
|
||||||
} while ( (status_value[0] & QSPIF_STATUS_BIT_WIP) != 0 && retries < IS_MEM_READY_MAX_RETRIES );
|
} while ((status_value[0] & QSPIF_STATUS_BIT_WIP) != 0 && retries < IS_MEM_READY_MAX_RETRIES);
|
||||||
|
|
||||||
if ((status_value[0] & QSPIF_STATUS_BIT_WIP) != 0) {
|
if ((status_value[0] & QSPIF_STATUS_BIT_WIP) != 0) {
|
||||||
tr_error("_is_mem_ready FALSE: status value = 0x%x ", (int)status_value[0]);
|
tr_error("_is_mem_ready FALSE: status value = 0x%x ", (int)status_value[0]);
|
||||||
|
@ -1172,14 +1172,14 @@ int QSPIFBlockDevice::_set_write_enable()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( false == _is_mem_ready()) {
|
if (false == _is_mem_ready()) {
|
||||||
tr_error("Device not ready, write failed");
|
tr_error("Device not ready, write failed");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(status_value, 0, QSPI_MAX_STATUS_REGISTER_SIZE);
|
memset(status_value, 0, QSPI_MAX_STATUS_REGISTER_SIZE);
|
||||||
if (QSPI_STATUS_OK != _qspi_send_general_command(QSPIF_RDSR, QSPI_NO_ADDRESS_COMMAND, NULL, 0, status_value,
|
if (QSPI_STATUS_OK != _qspi_send_general_command(QSPIF_RDSR, QSPI_NO_ADDRESS_COMMAND, NULL, 0, status_value,
|
||||||
QSPI_MAX_STATUS_REGISTER_SIZE)) { // store received values in status_value
|
QSPI_MAX_STATUS_REGISTER_SIZE)) { // store received values in status_value
|
||||||
tr_error("Reading Status Register failed");
|
tr_error("Reading Status Register failed");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1207,8 +1207,8 @@ int QSPIFBlockDevice::_enable_fast_mdoe()
|
||||||
|
|
||||||
// Read Status Register
|
// Read Status Register
|
||||||
if (QSPI_STATUS_OK == _qspi_send_general_command(read_conf_register_inst, QSPI_NO_ADDRESS_COMMAND, NULL, 0,
|
if (QSPI_STATUS_OK == _qspi_send_general_command(read_conf_register_inst, QSPI_NO_ADDRESS_COMMAND, NULL, 0,
|
||||||
&status_reg[1],
|
&status_reg[1],
|
||||||
QSPI_MAX_STATUS_REGISTER_SIZE - 1) ) { // store received values in status_value
|
QSPI_MAX_STATUS_REGISTER_SIZE - 1)) { // store received values in status_value
|
||||||
tr_debug("Reading Config Register Success: value = 0x%x", (int)status_reg[2]);
|
tr_debug("Reading Config Register Success: value = 0x%x", (int)status_reg[2]);
|
||||||
} else {
|
} else {
|
||||||
tr_error("Reading Config Register failed");
|
tr_error("Reading Config Register failed");
|
||||||
|
@ -1227,8 +1227,8 @@ int QSPIFBlockDevice::_enable_fast_mdoe()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (QSPI_STATUS_OK == _qspi_send_general_command(_write_register_inst, QSPI_NO_ADDRESS_COMMAND, status_reg,
|
if (QSPI_STATUS_OK == _qspi_send_general_command(_write_register_inst, QSPI_NO_ADDRESS_COMMAND, status_reg,
|
||||||
QSPI_MAX_STATUS_REGISTER_SIZE, NULL,
|
QSPI_MAX_STATUS_REGISTER_SIZE, NULL,
|
||||||
0) ) { // Write Fast mode bit to status_register
|
0)) { // Write Fast mode bit to status_register
|
||||||
tr_debug("fast mode enable - Writing Config Register Success: value = 0x%x",
|
tr_debug("fast mode enable - Writing Config Register Success: value = 0x%x",
|
||||||
(int)status_reg[2]);
|
(int)status_reg[2]);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1236,7 +1236,7 @@ int QSPIFBlockDevice::_enable_fast_mdoe()
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( false == _is_mem_ready()) {
|
if (false == _is_mem_ready()) {
|
||||||
tr_error("Device not ready after write, failed");
|
tr_error("Device not ready after write, failed");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -1244,8 +1244,8 @@ int QSPIFBlockDevice::_enable_fast_mdoe()
|
||||||
// For Debug
|
// For Debug
|
||||||
memset(status_reg, 0, QSPI_MAX_STATUS_REGISTER_SIZE);
|
memset(status_reg, 0, QSPI_MAX_STATUS_REGISTER_SIZE);
|
||||||
if (QSPI_STATUS_OK == _qspi_send_general_command(read_conf_register_inst, QSPI_NO_ADDRESS_COMMAND, NULL, 0,
|
if (QSPI_STATUS_OK == _qspi_send_general_command(read_conf_register_inst, QSPI_NO_ADDRESS_COMMAND, NULL, 0,
|
||||||
&status_reg[1],
|
&status_reg[1],
|
||||||
QSPI_MAX_STATUS_REGISTER_SIZE - 1) ) { // store received values in status_value
|
QSPI_MAX_STATUS_REGISTER_SIZE - 1)) { // store received values in status_value
|
||||||
tr_debug("Verifying Config Register Success: value = 0x%x", (int)status_reg[2]);
|
tr_debug("Verifying Config Register Success: value = 0x%x", (int)status_reg[2]);
|
||||||
} else {
|
} else {
|
||||||
tr_error("Verifying Config Register failed");
|
tr_error("Verifying Config Register failed");
|
||||||
|
@ -1279,7 +1279,7 @@ int QSPIFBlockDevice::_utils_find_addr_region(bd_size_t offset)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int QSPIFBlockDevice::_utils_iterate_next_largest_erase_type(uint8_t& bitfield, int size, int offset, int boundry)
|
int QSPIFBlockDevice::_utils_iterate_next_largest_erase_type(uint8_t &bitfield, int size, int offset, int boundry)
|
||||||
{
|
{
|
||||||
// Iterate on all supported Erase Types of the Region to which the offset belong to.
|
// Iterate on all supported Erase Types of the Region to which the offset belong to.
|
||||||
// Iterates from highest type to lowest
|
// Iterates from highest type to lowest
|
||||||
|
@ -1289,8 +1289,8 @@ int QSPIFBlockDevice::_utils_iterate_next_largest_erase_type(uint8_t& bitfield,
|
||||||
for (i_ind = 3; i_ind >= 0; i_ind--) {
|
for (i_ind = 3; i_ind >= 0; i_ind--) {
|
||||||
if (bitfield & type_mask) {
|
if (bitfield & type_mask) {
|
||||||
largest_erase_type = i_ind;
|
largest_erase_type = i_ind;
|
||||||
if ( (size > (int)(_erase_type_size_arr[largest_erase_type])) &&
|
if ((size > (int)(_erase_type_size_arr[largest_erase_type])) &&
|
||||||
((boundry - offset) > (int)(_erase_type_size_arr[largest_erase_type])) ) {
|
((boundry - offset) > (int)(_erase_type_size_arr[largest_erase_type]))) {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
bitfield &= ~type_mask;
|
bitfield &= ~type_mask;
|
||||||
|
@ -1315,12 +1315,12 @@ qspi_status_t QSPIFBlockDevice::_qspi_set_frequency(int freq)
|
||||||
}
|
}
|
||||||
|
|
||||||
qspi_status_t QSPIFBlockDevice::_qspi_send_read_command(unsigned int read_inst, void *buffer, bd_addr_t addr,
|
qspi_status_t QSPIFBlockDevice::_qspi_send_read_command(unsigned int read_inst, void *buffer, bd_addr_t addr,
|
||||||
bd_size_t size)
|
bd_size_t size)
|
||||||
{
|
{
|
||||||
// Send Read command to device driver
|
// Send Read command to device driver
|
||||||
size_t buf_len = size;
|
size_t buf_len = size;
|
||||||
|
|
||||||
if (_qspi.read(read_inst, -1, (unsigned int )addr, (char *)buffer, &buf_len) != QSPI_STATUS_OK ) {
|
if (_qspi.read(read_inst, -1, (unsigned int)addr, (char *)buffer, &buf_len) != QSPI_STATUS_OK) {
|
||||||
tr_error("Read failed");
|
tr_error("Read failed");
|
||||||
return QSPI_STATUS_ERROR;
|
return QSPI_STATUS_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -1330,7 +1330,7 @@ qspi_status_t QSPIFBlockDevice::_qspi_send_read_command(unsigned int read_inst,
|
||||||
}
|
}
|
||||||
|
|
||||||
qspi_status_t QSPIFBlockDevice::_qspi_send_program_command(unsigned int progInst, const void *buffer, bd_addr_t addr,
|
qspi_status_t QSPIFBlockDevice::_qspi_send_program_command(unsigned int progInst, const void *buffer, bd_addr_t addr,
|
||||||
bd_size_t *size)
|
bd_size_t *size)
|
||||||
{
|
{
|
||||||
// Send Program (write) command to device driver
|
// Send Program (write) command to device driver
|
||||||
qspi_status_t result = QSPI_STATUS_OK;
|
qspi_status_t result = QSPI_STATUS_OK;
|
||||||
|
@ -1366,8 +1366,8 @@ qspi_status_t QSPIFBlockDevice::_qspi_send_erase_command(unsigned int erase_inst
|
||||||
}
|
}
|
||||||
|
|
||||||
qspi_status_t QSPIFBlockDevice::_qspi_send_general_command(unsigned int instruction, bd_addr_t addr,
|
qspi_status_t QSPIFBlockDevice::_qspi_send_general_command(unsigned int instruction, bd_addr_t addr,
|
||||||
const char *tx_buffer,
|
const char *tx_buffer,
|
||||||
size_t tx_length, const char *rx_buffer, size_t rx_length)
|
size_t tx_length, const char *rx_buffer, size_t rx_length)
|
||||||
{
|
{
|
||||||
// Send a general command Instruction to driver
|
// Send a general command Instruction to driver
|
||||||
qspi_status_t status = _qspi.command_transfer(instruction, (int)addr, tx_buffer, tx_length, rx_buffer, rx_length);
|
qspi_status_t status = _qspi.command_transfer(instruction, (int)addr, tx_buffer, tx_length, rx_buffer, rx_length);
|
||||||
|
@ -1380,12 +1380,12 @@ qspi_status_t QSPIFBlockDevice::_qspi_send_general_command(unsigned int instruct
|
||||||
}
|
}
|
||||||
|
|
||||||
qspi_status_t QSPIFBlockDevice::_qspi_configure_format(qspi_bus_width_t inst_width, qspi_bus_width_t address_width,
|
qspi_status_t QSPIFBlockDevice::_qspi_configure_format(qspi_bus_width_t inst_width, qspi_bus_width_t address_width,
|
||||||
qspi_address_size_t address_size, qspi_bus_width_t alt_width, qspi_alt_size_t alt_size, qspi_bus_width_t data_width,
|
qspi_address_size_t address_size, qspi_bus_width_t alt_width, qspi_alt_size_t alt_size, qspi_bus_width_t data_width,
|
||||||
int dummy_cycles)
|
int dummy_cycles)
|
||||||
{
|
{
|
||||||
// Configure QSPI driver Bus format
|
// Configure QSPI driver Bus format
|
||||||
qspi_status_t status = _qspi.configure_format(inst_width, address_width, address_size, alt_width, alt_size, data_width,
|
qspi_status_t status = _qspi.configure_format(inst_width, address_width, address_size, alt_width, alt_size, data_width,
|
||||||
dummy_cycles);
|
dummy_cycles);
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ enum qspif_polarity_mode {
|
||||||
QSPIF_POLARITY_MODE_1 /* CPOL=1, CPHA=1 */
|
QSPIF_POLARITY_MODE_1 /* CPOL=1, CPHA=1 */
|
||||||
};
|
};
|
||||||
|
|
||||||
#define QSPIF_MAX_REGIONS 10
|
#define QSPIF_MAX_REGIONS 10
|
||||||
#define MAX_NUM_OF_ERASE_TYPES 4
|
#define MAX_NUM_OF_ERASE_TYPES 4
|
||||||
#define QSPIF_MAX_ACTIVE_FLASH_DEVICES 10
|
#define QSPIF_MAX_ACTIVE_FLASH_DEVICES 10
|
||||||
|
|
||||||
|
@ -121,7 +121,10 @@ public:
|
||||||
|
|
||||||
/** Desctruct QSPIFBlockDevie
|
/** Desctruct QSPIFBlockDevie
|
||||||
*/
|
*/
|
||||||
~QSPIFBlockDevice() {deinit();}
|
~QSPIFBlockDevice()
|
||||||
|
{
|
||||||
|
deinit();
|
||||||
|
}
|
||||||
|
|
||||||
/** Read blocks from a block device
|
/** Read blocks from a block device
|
||||||
*
|
*
|
||||||
|
@ -227,7 +230,7 @@ private:
|
||||||
/********************************/
|
/********************************/
|
||||||
// Send Program => Write command to Driver
|
// Send Program => Write command to Driver
|
||||||
qspi_status_t _qspi_send_program_command(unsigned int prog_instruction, const void *buffer, bd_addr_t addr,
|
qspi_status_t _qspi_send_program_command(unsigned int prog_instruction, const void *buffer, bd_addr_t addr,
|
||||||
bd_size_t *size);
|
bd_size_t *size);
|
||||||
|
|
||||||
// Send Read command to Driver
|
// Send Read command to Driver
|
||||||
qspi_status_t _qspi_send_read_command(unsigned int read_instruction, void *buffer, bd_addr_t addr, bd_size_t size);
|
qspi_status_t _qspi_send_read_command(unsigned int read_instruction, void *buffer, bd_addr_t addr, bd_size_t size);
|
||||||
|
@ -237,7 +240,7 @@ private:
|
||||||
|
|
||||||
// Send Generic command_transfer command to Driver
|
// Send Generic command_transfer command to Driver
|
||||||
qspi_status_t _qspi_send_general_command(unsigned int instruction_int, bd_addr_t addr, const char *tx_buffer,
|
qspi_status_t _qspi_send_general_command(unsigned int instruction_int, bd_addr_t addr, const char *tx_buffer,
|
||||||
size_t tx_length, const char *rx_buffer, size_t rx_length);
|
size_t tx_length, const char *rx_buffer, size_t rx_length);
|
||||||
|
|
||||||
// Send Bus configure_format command to Driver
|
// Send Bus configure_format command to Driver
|
||||||
qspi_status_t _qspi_configure_format(qspi_bus_width_t inst_width, qspi_bus_width_t address_width,
|
qspi_status_t _qspi_configure_format(qspi_bus_width_t inst_width, qspi_bus_width_t address_width,
|
||||||
|
@ -266,8 +269,8 @@ private:
|
||||||
/* SFDP Detection and Parsing Functions */
|
/* SFDP Detection and Parsing Functions */
|
||||||
/****************************************/
|
/****************************************/
|
||||||
// Parse SFDP Headers and retrieve Basic Param and Sector Map Tables (if exist)
|
// Parse SFDP Headers and retrieve Basic Param and Sector Map Tables (if exist)
|
||||||
int _sfdp_parse_sfdp_headers(uint32_t& basic_table_addr, size_t& basic_table_size,
|
int _sfdp_parse_sfdp_headers(uint32_t &basic_table_addr, size_t &basic_table_size,
|
||||||
uint32_t& sector_map_table_addr, size_t& sector_map_table_size);
|
uint32_t §or_map_table_addr, size_t §or_map_table_size);
|
||||||
|
|
||||||
// Parse and Detect required Basic Parameters from Table
|
// Parse and Detect required Basic Parameters from Table
|
||||||
int _sfdp_parse_basic_param_table(uint32_t basic_table_addr, size_t basic_table_size);
|
int _sfdp_parse_basic_param_table(uint32_t basic_table_addr, size_t basic_table_size);
|
||||||
|
@ -276,8 +279,8 @@ private:
|
||||||
int _sfdp_parse_sector_map_table(uint32_t sector_map_table_addr, size_t sector_map_table_size);
|
int _sfdp_parse_sector_map_table(uint32_t sector_map_table_addr, size_t sector_map_table_size);
|
||||||
|
|
||||||
// Detect fastest read Bus mode supported by device
|
// Detect fastest read Bus mode supported by device
|
||||||
int _sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table_ptr, int basic_param_table_size, bool& set_quad_enable,
|
int _sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table_ptr, int basic_param_table_size, bool &set_quad_enable,
|
||||||
bool& is_qpi_mode, unsigned int& read_inst);
|
bool &is_qpi_mode, unsigned int &read_inst);
|
||||||
|
|
||||||
// Enable Quad mode if supported (1-1-4, 1-4-4, 4-4-4 bus modes)
|
// Enable Quad mode if supported (1-1-4, 1-4-4, 4-4-4 bus modes)
|
||||||
int _sfdp_set_quad_enabled(uint8_t *basic_param_table_ptr);
|
int _sfdp_set_quad_enabled(uint8_t *basic_param_table_ptr);
|
||||||
|
@ -290,8 +293,8 @@ private:
|
||||||
|
|
||||||
// Detect all supported erase types
|
// Detect all supported erase types
|
||||||
int _sfdp_detect_erase_types_inst_and_size(uint8_t *basic_param_table_ptr, int basic_param_table_size,
|
int _sfdp_detect_erase_types_inst_and_size(uint8_t *basic_param_table_ptr, int basic_param_table_size,
|
||||||
unsigned int& erase4k_inst,
|
unsigned int &erase4k_inst,
|
||||||
unsigned int *erase_type_inst_arr, unsigned int *erase_type_size_arr);
|
unsigned int *erase_type_inst_arr, unsigned int *erase_type_size_arr);
|
||||||
|
|
||||||
/***********************/
|
/***********************/
|
||||||
/* Utilities Functions */
|
/* Utilities Functions */
|
||||||
|
@ -301,7 +304,7 @@ private:
|
||||||
|
|
||||||
// Iterate on all supported Erase Types of the Region to which the offset belong to.
|
// Iterate on all supported Erase Types of the Region to which the offset belong to.
|
||||||
// Iterates from highest type to lowest
|
// Iterates from highest type to lowest
|
||||||
int _utils_iterate_next_largest_erase_type(uint8_t& bitfield, int size, int offset, int boundry);
|
int _utils_iterate_next_largest_erase_type(uint8_t &bitfield, int size, int offset, int boundry);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Internal Members
|
// Internal Members
|
||||||
|
|
|
@ -43,7 +43,7 @@ static SingletonPtr<PlatformMutex> _mutex;
|
||||||
// Mutex is protecting rand() per srand for buffer writing and verification.
|
// Mutex is protecting rand() per srand for buffer writing and verification.
|
||||||
// Mutex is also protecting printouts for clear logs.
|
// Mutex is also protecting printouts for clear logs.
|
||||||
// Mutex is NOT protecting Block Device actions: erase/program/read - which is the purpose of the multithreaded test!
|
// Mutex is NOT protecting Block Device actions: erase/program/read - which is the purpose of the multithreaded test!
|
||||||
void basic_erase_program_read_test(QSPIFBlockDevice& blockD, bd_size_t block_size, uint8_t *write_block,
|
void basic_erase_program_read_test(QSPIFBlockDevice &blockD, bd_size_t block_size, uint8_t *write_block,
|
||||||
uint8_t *read_block, unsigned addrwidth)
|
uint8_t *read_block, unsigned addrwidth)
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
@ -79,10 +79,10 @@ void basic_erase_program_read_test(QSPIFBlockDevice& blockD, bd_size_t block_siz
|
||||||
int val_rand;
|
int val_rand;
|
||||||
for (bd_size_t i_ind = 0; i_ind < block_size; i_ind++) {
|
for (bd_size_t i_ind = 0; i_ind < block_size; i_ind++) {
|
||||||
val_rand = rand();
|
val_rand = rand();
|
||||||
if ( (0xff & val_rand) != read_block[i_ind] ) {
|
if ((0xff & val_rand) != read_block[i_ind]) {
|
||||||
utest_printf("\n Assert Failed Buf Read - block:size: %llx:%llu \n", block, block_size);
|
utest_printf("\n Assert Failed Buf Read - block:size: %llx:%llu \n", block, block_size);
|
||||||
utest_printf("\n pos: %llu, exp: %02x, act: %02x, wrt: %02x \n", i_ind, (0xff & val_rand), read_block[i_ind],
|
utest_printf("\n pos: %llu, exp: %02x, act: %02x, wrt: %02x \n", i_ind, (0xff & val_rand), read_block[i_ind],
|
||||||
write_block[i_ind] );
|
write_block[i_ind]);
|
||||||
}
|
}
|
||||||
TEST_ASSERT_EQUAL(0xff & val_rand, read_block[i_ind]);
|
TEST_ASSERT_EQUAL(0xff & val_rand, read_block[i_ind]);
|
||||||
}
|
}
|
||||||
|
@ -208,7 +208,7 @@ static void test_qspif_thread_job(void *vBlockD/*, int thread_num*/)
|
||||||
|
|
||||||
uint8_t *write_block = new (std::nothrow) uint8_t[block_size];
|
uint8_t *write_block = new (std::nothrow) uint8_t[block_size];
|
||||||
uint8_t *read_block = new (std::nothrow) uint8_t[block_size];
|
uint8_t *read_block = new (std::nothrow) uint8_t[block_size];
|
||||||
if (!write_block || !read_block ) {
|
if (!write_block || !read_block) {
|
||||||
utest_printf("\n Not enough memory for test");
|
utest_printf("\n Not enough memory for test");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,7 @@ int SPIFReducedBlockDevice::init()
|
||||||
uint32_t table_addr = (
|
uint32_t table_addr = (
|
||||||
(header[14] << 24) |
|
(header[14] << 24) |
|
||||||
(header[13] << 16) |
|
(header[13] << 16) |
|
||||||
(header[12] << 8 ));
|
(header[12] << 8));
|
||||||
|
|
||||||
uint8_t table[8];
|
uint8_t table[8];
|
||||||
_cmdread(SPIF_SFDP, 4, 8, table_addr, table);
|
_cmdread(SPIF_SFDP, 4, 8, table_addr, table);
|
||||||
|
@ -121,8 +121,8 @@ int SPIFReducedBlockDevice::init()
|
||||||
uint32_t density = (
|
uint32_t density = (
|
||||||
(table[7] << 24) |
|
(table[7] << 24) |
|
||||||
(table[6] << 16) |
|
(table[6] << 16) |
|
||||||
(table[5] << 8 ) |
|
(table[5] << 8) |
|
||||||
(table[4] << 0 ));
|
(table[4] << 0));
|
||||||
// Table bytes 5-8 : Bits 0|30 indicate Flash Density (size) in bits (divide by 8 for Bytes)
|
// Table bytes 5-8 : Bits 0|30 indicate Flash Density (size) in bits (divide by 8 for Bytes)
|
||||||
_size = (density / 8) + 1;
|
_size = (density / 8) + 1;
|
||||||
|
|
||||||
|
|
|
@ -114,7 +114,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
#if !defined(DOXYGEN_ONLY)
|
#if !defined(DOXYGEN_ONLY)
|
||||||
virtual void lock()
|
virtual void lock()
|
||||||
{
|
{
|
||||||
_mutex->lock();
|
_mutex->lock();
|
||||||
|
@ -127,7 +127,7 @@ protected:
|
||||||
|
|
||||||
analogin_t _adc;
|
analogin_t _adc;
|
||||||
static SingletonPtr<PlatformMutex> _mutex;
|
static SingletonPtr<PlatformMutex> _mutex;
|
||||||
#endif //!defined(DOXYGEN_ONLY)
|
#endif //!defined(DOXYGEN_ONLY)
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace mbed
|
} // namespace mbed
|
||||||
|
|
|
@ -141,7 +141,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
#if !defined(DOXYGEN_ONLY)
|
#if !defined(DOXYGEN_ONLY)
|
||||||
virtual void lock()
|
virtual void lock()
|
||||||
{
|
{
|
||||||
_mutex.lock();
|
_mutex.lock();
|
||||||
|
@ -154,7 +154,7 @@ protected:
|
||||||
|
|
||||||
dac_t _dac;
|
dac_t _dac;
|
||||||
PlatformMutex _mutex;
|
PlatformMutex _mutex;
|
||||||
#endif //!defined(DOXYGEN_ONLY)
|
#endif //!defined(DOXYGEN_ONLY)
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace mbed
|
} // namespace mbed
|
||||||
|
|
|
@ -124,7 +124,7 @@ public:
|
||||||
* wait(0.2);
|
* wait(0.2);
|
||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* @endcode
|
* @endcode
|
||||||
*/
|
*/
|
||||||
CAN(PinName rd, PinName td);
|
CAN(PinName rd, PinName td);
|
||||||
|
|
|
@ -121,9 +121,9 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
#if !defined(DOXYGEN_ONLY)
|
#if !defined(DOXYGEN_ONLY)
|
||||||
gpio_t gpio;
|
gpio_t gpio;
|
||||||
#endif //!defined(DOXYGEN_ONLY)
|
#endif //!defined(DOXYGEN_ONLY)
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace mbed
|
} // namespace mbed
|
||||||
|
|
|
@ -165,9 +165,9 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
#if !defined(DOXYGEN_ONLY)
|
#if !defined(DOXYGEN_ONLY)
|
||||||
gpio_t gpio;
|
gpio_t gpio;
|
||||||
#endif //!defined(DOXYGEN_ONLY)
|
#endif //!defined(DOXYGEN_ONLY)
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace mbed
|
} // namespace mbed
|
||||||
|
|
|
@ -144,9 +144,9 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
#if !defined(DOXYGEN_ONLY)
|
#if !defined(DOXYGEN_ONLY)
|
||||||
gpio_t gpio;
|
gpio_t gpio;
|
||||||
#endif //!defined(DOXYGEN_ONLY)
|
#endif //!defined(DOXYGEN_ONLY)
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace mbed
|
} // namespace mbed
|
||||||
|
|
|
@ -185,7 +185,7 @@ public:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if defined(DOXYGEN_ONLY)
|
#if defined(DOXYGEN_ONLY)
|
||||||
/** Calls an event on the queue
|
/** Calls an event on the queue
|
||||||
*
|
*
|
||||||
* The specified callback will be executed in the context of the event
|
* The specified callback will be executed in the context of the event
|
||||||
|
@ -266,8 +266,11 @@ public:
|
||||||
* }
|
* }
|
||||||
* @endcode
|
* @endcode
|
||||||
*/
|
*/
|
||||||
|
// AStyle ignore, not handling correctly below
|
||||||
|
// *INDENT-OFF*
|
||||||
template <typename T, typename R, typename ...Args>
|
template <typename T, typename R, typename ...Args>
|
||||||
int call(T *obj, R (T::*method)(Args ...args), Args ...args);
|
int call(T *obj, R (T::*method)(Args ...args), Args ...args);
|
||||||
|
// *INDENT-ON*
|
||||||
|
|
||||||
/** Calls an event on the queue after a specified delay
|
/** Calls an event on the queue after a specified delay
|
||||||
*
|
*
|
||||||
|
@ -346,8 +349,11 @@ public:
|
||||||
* }
|
* }
|
||||||
* @endcode
|
* @endcode
|
||||||
*/
|
*/
|
||||||
|
// AStyle ignore, not handling correctly below
|
||||||
|
// *INDENT-OFF*
|
||||||
template <typename T, typename R, typename ...Args>
|
template <typename T, typename R, typename ...Args>
|
||||||
int call_in(int ms, T *obj, R (T::*method)(Args ...args), Args ...args);
|
int call_in(int ms, T *obj, R (T::*method)(Args ...args), Args ...args);
|
||||||
|
// *INDENT-ON*
|
||||||
|
|
||||||
/** Calls an event on the queue periodically
|
/** Calls an event on the queue periodically
|
||||||
*
|
*
|
||||||
|
@ -440,8 +446,11 @@ public:
|
||||||
* }
|
* }
|
||||||
* @endcode
|
* @endcode
|
||||||
*/
|
*/
|
||||||
|
// AStyle ignore, not handling correctly below
|
||||||
|
// *INDENT-OFF*
|
||||||
template <typename T, typename R, typename ...Args>
|
template <typename T, typename R, typename ...Args>
|
||||||
int call_every(int ms, T *obj, R (T::*method)(Args ...args), Args ...args);
|
int call_every(int ms, T *obj, R (T::*method)(Args ...args), Args ...args);
|
||||||
|
// *INDENT-ON*
|
||||||
|
|
||||||
/** Creates an event bound to the event queue
|
/** Creates an event bound to the event queue
|
||||||
*
|
*
|
||||||
|
@ -483,8 +492,11 @@ public:
|
||||||
* }
|
* }
|
||||||
* @endcode
|
* @endcode
|
||||||
*/
|
*/
|
||||||
|
// AStyle ignore, not handling correctly below
|
||||||
|
// *INDENT-OFF*
|
||||||
template <typename R, typename ...BoundArgs, typename ...Args>
|
template <typename R, typename ...BoundArgs, typename ...Args>
|
||||||
Event<void(Args...)> event(R (*func)(BoundArgs...), Args ...args);
|
Event<void(Args...)> event(R (*func)(BoundArgs...), Args ...args);
|
||||||
|
// *INDENT-ON*
|
||||||
|
|
||||||
/** Creates an event bound to the event queue
|
/** Creates an event bound to the event queue
|
||||||
*
|
*
|
||||||
|
@ -528,8 +540,11 @@ public:
|
||||||
* }
|
* }
|
||||||
* @endcode
|
* @endcode
|
||||||
*/
|
*/
|
||||||
|
// AStyle ignore, not handling correctly below
|
||||||
|
// *INDENT-OFF*
|
||||||
template <typename T, typename R, typename ...BoundArgs, typename ...ContextArgs, typename ...Args>
|
template <typename T, typename R, typename ...BoundArgs, typename ...ContextArgs, typename ...Args>
|
||||||
Event<void(Args...)> event(T *obj, R (T::*method)(BoundArgs..., Args...), ContextArgs ...context_args);
|
Event<void(Args...)> event(T *obj, R (T::*method)(BoundArgs..., Args...), ContextArgs ...context_args);
|
||||||
|
// *INDENT-ON*
|
||||||
|
|
||||||
/** Creates an event bound to the event queue
|
/** Creates an event bound to the event queue
|
||||||
*
|
*
|
||||||
|
@ -569,7 +584,7 @@ public:
|
||||||
template <typename R, typename ...BoundArgs, typename ...ContextArgs, typename ...Args>
|
template <typename R, typename ...BoundArgs, typename ...ContextArgs, typename ...Args>
|
||||||
Event<void(Args...)> event(mbed::Callback<R(BoundArgs..., Args...)> cb, ContextArgs ...context_args);
|
Event<void(Args...)> event(mbed::Callback<R(BoundArgs..., Args...)> cb, ContextArgs ...context_args);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
/** Calls an event on the queue
|
/** Calls an event on the queue
|
||||||
*
|
*
|
||||||
|
@ -2800,10 +2815,10 @@ public:
|
||||||
*/
|
*/
|
||||||
template <typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1, typename A2, typename A3, typename A4>
|
template <typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1, typename A2, typename A3, typename A4>
|
||||||
Event<void(A0, A1, A2, A3, A4)> event(mbed::Callback<R(B0, B1, B2, B3, B4, A0, A1, A2, A3, A4)> cb, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4);
|
Event<void(A0, A1, A2, A3, A4)> event(mbed::Callback<R(B0, B1, B2, B3, B4, A0, A1, A2, A3, A4)> cb, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
#if !defined(DOXYGEN_ONLY)
|
#if !defined(DOXYGEN_ONLY)
|
||||||
template <typename F>
|
template <typename F>
|
||||||
friend class Event;
|
friend class Event;
|
||||||
struct equeue _equeue;
|
struct equeue _equeue;
|
||||||
|
@ -3380,7 +3395,7 @@ protected:
|
||||||
f(c0, c1, c2, c3, c4, a0, a1, a2, a3, a4);
|
f(c0, c1, c2, c3, c4, a0, a1, a2, a3, a4);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#endif //!defined(DOXYGEN_ONLY)
|
#endif //!defined(DOXYGEN_ONLY)
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -208,7 +208,7 @@ int equeue_timeleft(equeue_t *q, int id);
|
||||||
// of hardware timers or even other event loops, allowing an event queue to
|
// of hardware timers or even other event loops, allowing an event queue to
|
||||||
// be effectively backgrounded.
|
// be effectively backgrounded.
|
||||||
void equeue_background(equeue_t *queue,
|
void equeue_background(equeue_t *queue,
|
||||||
void (*update)(void *timer, int ms), void *timer);
|
void (*update)(void *timer, int ms), void *timer);
|
||||||
|
|
||||||
// Chain an event queue onto another event queue
|
// Chain an event queue onto another event queue
|
||||||
//
|
//
|
||||||
|
|
|
@ -70,7 +70,7 @@ static void test_sim_interface()
|
||||||
nsapi_error_t err = sim->set_pin(MBED_CONF_APP_CELLULAR_SIM_PIN);
|
nsapi_error_t err = sim->set_pin(MBED_CONF_APP_CELLULAR_SIM_PIN);
|
||||||
MBED_ASSERT(err == NSAPI_ERROR_OK);
|
MBED_ASSERT(err == NSAPI_ERROR_OK);
|
||||||
|
|
||||||
// 2. test set_pin_query
|
// 2. test set_pin_query
|
||||||
wait(1);
|
wait(1);
|
||||||
err = sim->set_pin_query(MBED_CONF_APP_CELLULAR_SIM_PIN, false);
|
err = sim->set_pin_query(MBED_CONF_APP_CELLULAR_SIM_PIN, false);
|
||||||
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED);
|
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED);
|
||||||
|
|
|
@ -112,7 +112,7 @@ static void test_sms_initialize_text_mode()
|
||||||
{
|
{
|
||||||
nsapi_error_t err = sms->initialize(CellularSMS::CellularSMSMmodeText);
|
nsapi_error_t err = sms->initialize(CellularSMS::CellularSMSMmodeText);
|
||||||
TEST_ASSERT(err == NSAPI_ERROR_OK || (err == NSAPI_ERROR_DEVICE_ERROR &&
|
TEST_ASSERT(err == NSAPI_ERROR_OK || (err == NSAPI_ERROR_DEVICE_ERROR &&
|
||||||
((AT_CellularSMS *)sms)->get_device_error().errCode == SIM_BUSY));
|
((AT_CellularSMS *)sms)->get_device_error().errCode == SIM_BUSY));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,40 +120,40 @@ static void test_sms_initialize_pdu_mode()
|
||||||
{
|
{
|
||||||
nsapi_error_t err = sms->initialize(CellularSMS::CellularSMSMmodePDU);
|
nsapi_error_t err = sms->initialize(CellularSMS::CellularSMSMmodePDU);
|
||||||
TEST_ASSERT(err == NSAPI_ERROR_OK || (err == NSAPI_ERROR_DEVICE_ERROR &&
|
TEST_ASSERT(err == NSAPI_ERROR_OK || (err == NSAPI_ERROR_DEVICE_ERROR &&
|
||||||
((AT_CellularSMS *)sms)->get_device_error().errCode == SIM_BUSY));
|
((AT_CellularSMS *)sms)->get_device_error().errCode == SIM_BUSY));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_set_cscs()
|
static void test_set_cscs()
|
||||||
{
|
{
|
||||||
nsapi_error_t err = sms->set_cscs("IRA");
|
nsapi_error_t err = sms->set_cscs("IRA");
|
||||||
TEST_ASSERT(err == NSAPI_ERROR_OK || (err == NSAPI_ERROR_DEVICE_ERROR &&
|
TEST_ASSERT(err == NSAPI_ERROR_OK || (err == NSAPI_ERROR_DEVICE_ERROR &&
|
||||||
((AT_CellularSMS *)sms)->get_device_error().errCode == SIM_BUSY));
|
((AT_CellularSMS *)sms)->get_device_error().errCode == SIM_BUSY));
|
||||||
err = sms->set_cscs("UCS2");
|
err = sms->set_cscs("UCS2");
|
||||||
TEST_ASSERT(err == NSAPI_ERROR_OK || (err == NSAPI_ERROR_DEVICE_ERROR &&
|
TEST_ASSERT(err == NSAPI_ERROR_OK || (err == NSAPI_ERROR_DEVICE_ERROR &&
|
||||||
((AT_CellularSMS *)sms)->get_device_error().errCode == SIM_BUSY));
|
((AT_CellularSMS *)sms)->get_device_error().errCode == SIM_BUSY));
|
||||||
err = sms->set_cscs("GSM");
|
err = sms->set_cscs("GSM");
|
||||||
TEST_ASSERT(err == NSAPI_ERROR_OK || (err == NSAPI_ERROR_DEVICE_ERROR &&
|
TEST_ASSERT(err == NSAPI_ERROR_OK || (err == NSAPI_ERROR_DEVICE_ERROR &&
|
||||||
((AT_CellularSMS *)sms)->get_device_error().errCode == SIM_BUSY));
|
((AT_CellularSMS *)sms)->get_device_error().errCode == SIM_BUSY));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_set_csca()
|
static void test_set_csca()
|
||||||
{
|
{
|
||||||
nsapi_error_t err = sms->set_csca("55555", 129);
|
nsapi_error_t err = sms->set_csca("55555", 129);
|
||||||
TEST_ASSERT(err == NSAPI_ERROR_OK || (err == NSAPI_ERROR_DEVICE_ERROR &&
|
TEST_ASSERT(err == NSAPI_ERROR_OK || (err == NSAPI_ERROR_DEVICE_ERROR &&
|
||||||
((AT_CellularSMS *)sms)->get_device_error().errCode == SIM_BUSY));
|
((AT_CellularSMS *)sms)->get_device_error().errCode == SIM_BUSY));
|
||||||
err = sms->set_csca("+35855555", 145);
|
err = sms->set_csca("+35855555", 145);
|
||||||
TEST_ASSERT(err == NSAPI_ERROR_OK || (err == NSAPI_ERROR_DEVICE_ERROR &&
|
TEST_ASSERT(err == NSAPI_ERROR_OK || (err == NSAPI_ERROR_DEVICE_ERROR &&
|
||||||
((AT_CellularSMS *)sms)->get_device_error().errCode == SIM_BUSY));
|
((AT_CellularSMS *)sms)->get_device_error().errCode == SIM_BUSY));
|
||||||
err = sms->set_csca(service_center_address, service_address_type);
|
err = sms->set_csca(service_center_address, service_address_type);
|
||||||
TEST_ASSERT(err == NSAPI_ERROR_OK || (err == NSAPI_ERROR_DEVICE_ERROR &&
|
TEST_ASSERT(err == NSAPI_ERROR_OK || (err == NSAPI_ERROR_DEVICE_ERROR &&
|
||||||
((AT_CellularSMS *)sms)->get_device_error().errCode == SIM_BUSY));
|
((AT_CellularSMS *)sms)->get_device_error().errCode == SIM_BUSY));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_set_cpms_me()
|
static void test_set_cpms_me()
|
||||||
{
|
{
|
||||||
nsapi_error_t err = sms->set_cpms("ME", "ME", "ME");
|
nsapi_error_t err = sms->set_cpms("ME", "ME", "ME");
|
||||||
TEST_ASSERT(err == NSAPI_ERROR_OK || (err == NSAPI_ERROR_DEVICE_ERROR &&
|
TEST_ASSERT(err == NSAPI_ERROR_OK || (err == NSAPI_ERROR_DEVICE_ERROR &&
|
||||||
((AT_CellularSMS *)sms)->get_device_error().errCode == SIM_BUSY));
|
((AT_CellularSMS *)sms)->get_device_error().errCode == SIM_BUSY));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MBED_CONF_APP_CELLULAR_PHONE_NUMBER
|
#ifdef MBED_CONF_APP_CELLULAR_PHONE_NUMBER
|
||||||
|
|
|
@ -41,8 +41,8 @@ using namespace mbed_cellular_util;
|
||||||
using namespace mbed;
|
using namespace mbed;
|
||||||
|
|
||||||
AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) :
|
AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) :
|
||||||
AT_CellularBase(at), _ip_stack_type_requested(DEFAULT_STACK), _is_connected(false), _is_blocking(true),
|
AT_CellularBase(at), _ip_stack_type_requested(DEFAULT_STACK), _is_connected(false), _is_blocking(true),
|
||||||
_current_op(OP_INVALID), _device(device), _nw(0), _fh(0)
|
_current_op(OP_INVALID), _device(device), _nw(0), _fh(0)
|
||||||
{
|
{
|
||||||
tr_debug("AT_CellularContext::AT_CellularContext(): apn: %s", apn);
|
tr_debug("AT_CellularContext::AT_CellularContext(): apn: %s", apn);
|
||||||
_stack = NULL;
|
_stack = NULL;
|
||||||
|
@ -218,7 +218,7 @@ void AT_CellularContext::set_sim_pin(const char *sim_pin)
|
||||||
}
|
}
|
||||||
|
|
||||||
nsapi_error_t AT_CellularContext::connect(const char *sim_pin, const char *apn, const char *uname,
|
nsapi_error_t AT_CellularContext::connect(const char *sim_pin, const char *apn, const char *uname,
|
||||||
const char *pwd)
|
const char *pwd)
|
||||||
{
|
{
|
||||||
set_sim_pin(sim_pin);
|
set_sim_pin(sim_pin);
|
||||||
set_credentials(apn, uname, pwd);
|
set_credentials(apn, uname, pwd);
|
||||||
|
@ -458,7 +458,7 @@ bool AT_CellularContext::set_new_context(int cid)
|
||||||
|
|
||||||
nsapi_error_t AT_CellularContext::do_activate_context()
|
nsapi_error_t AT_CellularContext::do_activate_context()
|
||||||
{
|
{
|
||||||
_at.lock();
|
_at.lock();
|
||||||
|
|
||||||
nsapi_error_t err = NSAPI_ERROR_OK;
|
nsapi_error_t err = NSAPI_ERROR_OK;
|
||||||
|
|
||||||
|
@ -536,7 +536,7 @@ void AT_CellularContext::do_connect()
|
||||||
#if !NSAPI_PPP_AVAILABLE
|
#if !NSAPI_PPP_AVAILABLE
|
||||||
// in PPP mode we did not activate any context, just searched the correct _cid
|
// in PPP mode we did not activate any context, just searched the correct _cid
|
||||||
if (_status_cb) {
|
if (_status_cb) {
|
||||||
_status_cb((nsapi_event_t)CellularActivatePDPContext, (intptr_t )&_cb_data);
|
_status_cb((nsapi_event_t)CellularActivatePDPContext, (intptr_t)&_cb_data);
|
||||||
}
|
}
|
||||||
#endif // !NSAPI_PPP_AVAILABLE
|
#endif // !NSAPI_PPP_AVAILABLE
|
||||||
}
|
}
|
||||||
|
@ -810,7 +810,7 @@ nsapi_error_t AT_CellularContext::get_pdpcontext_params(pdpContextList_t ¶ms
|
||||||
void AT_CellularContext::cellular_callback(nsapi_event_t ev, intptr_t ptr)
|
void AT_CellularContext::cellular_callback(nsapi_event_t ev, intptr_t ptr)
|
||||||
{
|
{
|
||||||
if (ev >= NSAPI_EVENT_CELLULAR_STATUS_BASE && ev <= NSAPI_EVENT_CELLULAR_STATUS_END) {
|
if (ev >= NSAPI_EVENT_CELLULAR_STATUS_BASE && ev <= NSAPI_EVENT_CELLULAR_STATUS_END) {
|
||||||
cell_callback_data_t* data = (cell_callback_data_t*)ptr;
|
cell_callback_data_t *data = (cell_callback_data_t *)ptr;
|
||||||
cellular_connection_status_t st = (cellular_connection_status_t)ev;
|
cellular_connection_status_t st = (cellular_connection_status_t)ev;
|
||||||
_cb_data.error = data->error;
|
_cb_data.error = data->error;
|
||||||
tr_debug("AT_CellularContext::cellular_callback, network_callback called with event: %d, err: %d, data: %d", ev, data->error, data->status_data);
|
tr_debug("AT_CellularContext::cellular_callback, network_callback called with event: %d, err: %d, data: %d", ev, data->error, data->status_data);
|
||||||
|
@ -853,16 +853,16 @@ void AT_CellularContext::cellular_callback(nsapi_event_t ev, intptr_t ptr)
|
||||||
_semaphore.release();
|
_semaphore.release();
|
||||||
} else {
|
} else {
|
||||||
if ((st == CellularDeviceReady && _current_op == OP_DEVICE_READY) ||
|
if ((st == CellularDeviceReady && _current_op == OP_DEVICE_READY) ||
|
||||||
(st == CellularSIMStatusChanged && _current_op == OP_SIM_READY &&
|
(st == CellularSIMStatusChanged && _current_op == OP_SIM_READY &&
|
||||||
data->status_data == CellularSIM::SimStateReady)) {
|
data->status_data == CellularSIM::SimStateReady)) {
|
||||||
// target reached, release semaphore
|
// target reached, release semaphore
|
||||||
_semaphore.release();
|
_semaphore.release();
|
||||||
} else if (st == CellularRegistrationStatusChanged && (data->status_data == CellularNetwork::RegisteredHomeNetwork ||
|
} else if (st == CellularRegistrationStatusChanged && (data->status_data == CellularNetwork::RegisteredHomeNetwork ||
|
||||||
data->status_data == CellularNetwork::RegisteredRoaming || data->status_data == CellularNetwork::AlreadyRegistered) && _current_op == OP_REGISTER) {
|
data->status_data == CellularNetwork::RegisteredRoaming || data->status_data == CellularNetwork::AlreadyRegistered) && _current_op == OP_REGISTER) {
|
||||||
// target reached, release semaphore
|
// target reached, release semaphore
|
||||||
_semaphore.release();
|
_semaphore.release();
|
||||||
} else if (st == CellularAttachNetwork && (_current_op == OP_ATTACH || _current_op == OP_CONNECT) &&
|
} else if (st == CellularAttachNetwork && (_current_op == OP_ATTACH || _current_op == OP_CONNECT) &&
|
||||||
data->status_data == CellularNetwork::Attached) {
|
data->status_data == CellularNetwork::Attached) {
|
||||||
// target reached, release semaphore
|
// target reached, release semaphore
|
||||||
_semaphore.release();
|
_semaphore.release();
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,14 +34,14 @@ using namespace mbed;
|
||||||
#define DEFAULT_AT_TIMEOUT 1000 // at default timeout in milliseconds
|
#define DEFAULT_AT_TIMEOUT 1000 // at default timeout in milliseconds
|
||||||
|
|
||||||
AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : CellularDevice(fh), _atHandlers(0), _network(0), _sms(0),
|
AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : CellularDevice(fh), _atHandlers(0), _network(0), _sms(0),
|
||||||
_sim(0), _power(0), _information(0), _context_list(0), _default_timeout(DEFAULT_AT_TIMEOUT),
|
_sim(0), _power(0), _information(0), _context_list(0), _default_timeout(DEFAULT_AT_TIMEOUT),
|
||||||
_modem_debug_on(false)
|
_modem_debug_on(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
AT_CellularDevice::~AT_CellularDevice()
|
AT_CellularDevice::~AT_CellularDevice()
|
||||||
{
|
{
|
||||||
delete _state_machine;
|
delete _state_machine;
|
||||||
|
|
||||||
// make sure that all is deleted even if somewhere close was not called and reference counting is messed up.
|
// make sure that all is deleted even if somewhere close was not called and reference counting is messed up.
|
||||||
_network_ref_count = 1;
|
_network_ref_count = 1;
|
||||||
|
@ -56,10 +56,10 @@ AT_CellularDevice::~AT_CellularDevice()
|
||||||
close_sim();
|
close_sim();
|
||||||
close_information();
|
close_information();
|
||||||
|
|
||||||
AT_CellularContext* curr = _context_list;
|
AT_CellularContext *curr = _context_list;
|
||||||
AT_CellularContext* next;
|
AT_CellularContext *next;
|
||||||
while (curr) {
|
while (curr) {
|
||||||
next = (AT_CellularContext*)curr->_next;
|
next = (AT_CellularContext *)curr->_next;
|
||||||
delete curr;
|
delete curr;
|
||||||
curr = next;
|
curr = next;
|
||||||
}
|
}
|
||||||
|
@ -134,17 +134,17 @@ CellularContext *AT_CellularDevice::create_context(FileHandle *fh, const char *a
|
||||||
ATHandler *atHandler = get_at_handler(fh);
|
ATHandler *atHandler = get_at_handler(fh);
|
||||||
if (atHandler) {
|
if (atHandler) {
|
||||||
AT_CellularContext *ctx = create_context_impl(*atHandler, apn);
|
AT_CellularContext *ctx = create_context_impl(*atHandler, apn);
|
||||||
AT_CellularContext* curr = _context_list;
|
AT_CellularContext *curr = _context_list;
|
||||||
|
|
||||||
if (_context_list == NULL) {
|
if (_context_list == NULL) {
|
||||||
_context_list = ctx;
|
_context_list = ctx;
|
||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
AT_CellularContext* prev;
|
AT_CellularContext *prev;
|
||||||
while (curr) {
|
while (curr) {
|
||||||
prev = curr;
|
prev = curr;
|
||||||
curr = (AT_CellularContext*)curr->_next;
|
curr = (AT_CellularContext *)curr->_next;
|
||||||
}
|
}
|
||||||
|
|
||||||
prev->_next = ctx;
|
prev->_next = ctx;
|
||||||
|
@ -160,20 +160,20 @@ AT_CellularContext *AT_CellularDevice::create_context_impl(ATHandler &at, const
|
||||||
|
|
||||||
void AT_CellularDevice::delete_context(CellularContext *context)
|
void AT_CellularDevice::delete_context(CellularContext *context)
|
||||||
{
|
{
|
||||||
AT_CellularContext* curr = _context_list;
|
AT_CellularContext *curr = _context_list;
|
||||||
AT_CellularContext* prev = NULL;
|
AT_CellularContext *prev = NULL;
|
||||||
while (curr) {
|
while (curr) {
|
||||||
if (curr == context) {
|
if (curr == context) {
|
||||||
if (prev == NULL) {
|
if (prev == NULL) {
|
||||||
_context_list = (AT_CellularContext*)curr->_next;
|
_context_list = (AT_CellularContext *)curr->_next;
|
||||||
} else {
|
} else {
|
||||||
prev->_next = curr->_next;
|
prev->_next = curr->_next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
prev = curr;
|
prev = curr;
|
||||||
curr = (AT_CellularContext*)curr->_next;
|
curr = (AT_CellularContext *)curr->_next;
|
||||||
}
|
}
|
||||||
delete (AT_CellularContext*)context;
|
delete (AT_CellularContext *)context;
|
||||||
}
|
}
|
||||||
|
|
||||||
CellularNetwork *AT_CellularDevice::open_network(FileHandle *fh)
|
CellularNetwork *AT_CellularDevice::open_network(FileHandle *fh)
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
namespace mbed {
|
namespace mbed {
|
||||||
|
|
||||||
GEMALTO_CINTERION_CellularContext::GEMALTO_CINTERION_CellularContext(ATHandler &at, CellularDevice *device,
|
GEMALTO_CINTERION_CellularContext::GEMALTO_CINTERION_CellularContext(ATHandler &at, CellularDevice *device,
|
||||||
const char *apn) : AT_CellularContext(at, device, apn)
|
const char *apn) : AT_CellularContext(at, device, apn)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
namespace mbed {
|
namespace mbed {
|
||||||
|
|
||||||
SARA4_PPP_CellularContext::SARA4_PPP_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) :
|
SARA4_PPP_CellularContext::SARA4_PPP_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) :
|
||||||
AT_CellularContext(at, device, apn)
|
AT_CellularContext(at, device, apn)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
namespace mbed {
|
namespace mbed {
|
||||||
|
|
||||||
QUECTEL_BC95_CellularContext::QUECTEL_BC95_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) :
|
QUECTEL_BC95_CellularContext::QUECTEL_BC95_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) :
|
||||||
AT_CellularContext(at, device, apn)
|
AT_CellularContext(at, device, apn)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
namespace mbed {
|
namespace mbed {
|
||||||
|
|
||||||
QUECTEL_BG96_CellularContext::QUECTEL_BG96_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) :
|
QUECTEL_BG96_CellularContext::QUECTEL_BG96_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) :
|
||||||
AT_CellularContext(at, device, apn)
|
AT_CellularContext(at, device, apn)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
namespace mbed {
|
namespace mbed {
|
||||||
|
|
||||||
QUECTEL_UG96_CellularContext::QUECTEL_UG96_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) :
|
QUECTEL_UG96_CellularContext::QUECTEL_UG96_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) :
|
||||||
AT_CellularContext(at, device, apn)
|
AT_CellularContext(at, device, apn)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
namespace mbed {
|
namespace mbed {
|
||||||
|
|
||||||
TELIT_HE910_CellularContext::TELIT_HE910_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) :
|
TELIT_HE910_CellularContext::TELIT_HE910_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) :
|
||||||
AT_CellularContext(at, device, apn)
|
AT_CellularContext(at, device, apn)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
namespace mbed {
|
namespace mbed {
|
||||||
|
|
||||||
UBLOX_AT_CellularContext::UBLOX_AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) :
|
UBLOX_AT_CellularContext::UBLOX_AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) :
|
||||||
AT_CellularContext(at, device, apn)
|
AT_CellularContext(at, device, apn)
|
||||||
{
|
{
|
||||||
// The authentication to use
|
// The authentication to use
|
||||||
_auth = NSAPI_SECURITY_UNKNOWN;
|
_auth = NSAPI_SECURITY_UNKNOWN;
|
||||||
|
@ -75,9 +75,9 @@ nsapi_error_t UBLOX_AT_CellularContext::open_data_channel()
|
||||||
{
|
{
|
||||||
bool success = false;
|
bool success = false;
|
||||||
int active = 0;
|
int active = 0;
|
||||||
char * config = NULL;
|
char *config = NULL;
|
||||||
nsapi_error_t err = NSAPI_ERROR_NO_CONNECTION;
|
nsapi_error_t err = NSAPI_ERROR_NO_CONNECTION;
|
||||||
char imsi[MAX_IMSI_LENGTH+1];
|
char imsi[MAX_IMSI_LENGTH + 1];
|
||||||
|
|
||||||
// do check for stack to validate that we have support for stack
|
// do check for stack to validate that we have support for stack
|
||||||
_stack = get_stack();
|
_stack = get_stack();
|
||||||
|
@ -98,14 +98,14 @@ nsapi_error_t UBLOX_AT_CellularContext::open_data_channel()
|
||||||
if (_apn == NULL) {
|
if (_apn == NULL) {
|
||||||
err = get_imsi(imsi);
|
err = get_imsi(imsi);
|
||||||
if (err == NSAPI_ERROR_OK) {
|
if (err == NSAPI_ERROR_OK) {
|
||||||
config = (char*)apnconfig(imsi);
|
config = (char *)apnconfig(imsi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempt to connect
|
// Attempt to connect
|
||||||
do {
|
do {
|
||||||
get_next_credentials(&config);
|
get_next_credentials(&config);
|
||||||
if(_uname && _pwd) {
|
if (_uname && _pwd) {
|
||||||
_auth = (*_uname && *_pwd) ? _auth : NSAPI_SECURITY_NONE;
|
_auth = (*_uname && *_pwd) ? _auth : NSAPI_SECURITY_NONE;
|
||||||
} else {
|
} else {
|
||||||
_auth = NSAPI_SECURITY_NONE;
|
_auth = NSAPI_SECURITY_NONE;
|
||||||
|
@ -122,9 +122,9 @@ nsapi_error_t UBLOX_AT_CellularContext::open_data_channel()
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UBLOX_AT_CellularContext::activate_profile(const char* apn,
|
bool UBLOX_AT_CellularContext::activate_profile(const char *apn,
|
||||||
const char* username,
|
const char *username,
|
||||||
const char* password)
|
const char *password)
|
||||||
{
|
{
|
||||||
bool activated = false;
|
bool activated = false;
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
@ -253,7 +253,7 @@ bool UBLOX_AT_CellularContext::disconnect_modem_stack()
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsapi_error_t UBLOX_AT_CellularContext::get_imsi(char* imsi)
|
nsapi_error_t UBLOX_AT_CellularContext::get_imsi(char *imsi)
|
||||||
{
|
{
|
||||||
_at.lock();
|
_at.lock();
|
||||||
_at.cmd_start("AT+CIMI");
|
_at.cmd_start("AT+CIMI");
|
||||||
|
@ -269,7 +269,7 @@ nsapi_error_t UBLOX_AT_CellularContext::get_imsi(char* imsi)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the next set of credentials, based on IMSI.
|
// Get the next set of credentials, based on IMSI.
|
||||||
void UBLOX_AT_CellularContext::get_next_credentials(char ** config)
|
void UBLOX_AT_CellularContext::get_next_credentials(char **config)
|
||||||
{
|
{
|
||||||
if (*config) {
|
if (*config) {
|
||||||
_apn = _APN_GET(*config);
|
_apn = _APN_GET(*config);
|
||||||
|
|
|
@ -59,7 +59,7 @@ private:
|
||||||
* NSAPI_SECURITY_CHAP or NSAPI_SECURITY_UNKNOWN).
|
* NSAPI_SECURITY_CHAP or NSAPI_SECURITY_UNKNOWN).
|
||||||
* @return True if successful, otherwise false.
|
* @return True if successful, otherwise false.
|
||||||
*/
|
*/
|
||||||
bool activate_profile(const char* apn, const char* username, const char* password);
|
bool activate_profile(const char *apn, const char *username, const char *password);
|
||||||
|
|
||||||
/** Convert nsapi_security_t to the modem security numbers.
|
/** Convert nsapi_security_t to the modem security numbers.
|
||||||
*
|
*
|
||||||
|
@ -76,11 +76,11 @@ private:
|
||||||
|
|
||||||
/** Read IMSI of modem.
|
/** Read IMSI of modem.
|
||||||
*/
|
*/
|
||||||
nsapi_error_t get_imsi(char* imsi);
|
nsapi_error_t get_imsi(char *imsi);
|
||||||
|
|
||||||
/** Get the next set of credentials from the database.
|
/** Get the next set of credentials from the database.
|
||||||
*/
|
*/
|
||||||
void get_next_credentials(char ** config);
|
void get_next_credentials(char **config);
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace mbed */
|
} /* namespace mbed */
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
namespace mbed {
|
namespace mbed {
|
||||||
|
|
||||||
UBLOX_PPP_CellularContext::UBLOX_PPP_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) :
|
UBLOX_PPP_CellularContext::UBLOX_PPP_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) :
|
||||||
AT_CellularContext(at, device, apn)
|
AT_CellularContext(at, device, apn)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,10 @@ public:
|
||||||
virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);
|
virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);
|
||||||
virtual nsapi_connection_status_t get_connection_status() const;
|
virtual nsapi_connection_status_t get_connection_status() const;
|
||||||
|
|
||||||
void get_mac_address(uint8_t *buf) const { interface_phy.get_mac_address(buf); }
|
void get_mac_address(uint8_t *buf) const
|
||||||
|
{
|
||||||
|
interface_phy.get_mac_address(buf);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Callback from C-layer
|
* \brief Callback from C-layer
|
||||||
|
@ -40,15 +43,24 @@ public:
|
||||||
* */
|
* */
|
||||||
void network_handler(mesh_connection_status_t status);
|
void network_handler(mesh_connection_status_t status);
|
||||||
|
|
||||||
int8_t get_interface_id() const { return interface_id; }
|
int8_t get_interface_id() const
|
||||||
int8_t get_driver_id() const { return _device_id; }
|
{
|
||||||
|
return interface_id;
|
||||||
|
}
|
||||||
|
int8_t get_driver_id() const
|
||||||
|
{
|
||||||
|
return _device_id;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NanostackPhy &interface_phy;
|
NanostackPhy &interface_phy;
|
||||||
protected:
|
protected:
|
||||||
Interface(NanostackPhy &phy);
|
Interface(NanostackPhy &phy);
|
||||||
virtual nsapi_error_t register_phy();
|
virtual nsapi_error_t register_phy();
|
||||||
NanostackPhy &get_phy() const { return interface_phy; }
|
NanostackPhy &get_phy() const
|
||||||
|
{
|
||||||
|
return interface_phy;
|
||||||
|
}
|
||||||
int8_t interface_id;
|
int8_t interface_id;
|
||||||
int8_t _device_id;
|
int8_t _device_id;
|
||||||
rtos::Semaphore connect_semaphore;
|
rtos::Semaphore connect_semaphore;
|
||||||
|
@ -62,7 +74,10 @@ protected:
|
||||||
class Nanostack::MeshInterface : public Nanostack::Interface {
|
class Nanostack::MeshInterface : public Nanostack::Interface {
|
||||||
protected:
|
protected:
|
||||||
MeshInterface(NanostackRfPhy &phy) : Interface(phy) { }
|
MeshInterface(NanostackRfPhy &phy) : Interface(phy) { }
|
||||||
NanostackRfPhy &get_phy() const { return static_cast<NanostackRfPhy &>(Interface::get_phy()); }
|
NanostackRfPhy &get_phy() const
|
||||||
|
{
|
||||||
|
return static_cast<NanostackRfPhy &>(Interface::get_phy());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -116,12 +131,18 @@ public:
|
||||||
/** Get the interface ID
|
/** Get the interface ID
|
||||||
/return Interface identifier
|
/return Interface identifier
|
||||||
*/
|
*/
|
||||||
int8_t get_interface_id() const { return _interface->get_interface_id(); }
|
int8_t get_interface_id() const
|
||||||
|
{
|
||||||
|
return _interface->get_interface_id();
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
InterfaceNanostack();
|
InterfaceNanostack();
|
||||||
virtual Nanostack *get_stack(void);
|
virtual Nanostack *get_stack(void);
|
||||||
Nanostack::Interface *get_interface() const { return _interface; }
|
Nanostack::Interface *get_interface() const
|
||||||
|
{
|
||||||
|
return _interface;
|
||||||
|
}
|
||||||
virtual nsapi_error_t do_initialize() = 0;
|
virtual nsapi_error_t do_initialize() = 0;
|
||||||
|
|
||||||
Nanostack::Interface *_interface;
|
Nanostack::Interface *_interface;
|
||||||
|
@ -147,7 +168,10 @@ public:
|
||||||
protected:
|
protected:
|
||||||
MeshInterfaceNanostack() : _phy(NULL) { }
|
MeshInterfaceNanostack() : _phy(NULL) { }
|
||||||
MeshInterfaceNanostack(NanostackRfPhy *phy) : _phy(phy) { }
|
MeshInterfaceNanostack(NanostackRfPhy *phy) : _phy(phy) { }
|
||||||
Nanostack::MeshInterface *get_interface() const { return static_cast<Nanostack::MeshInterface *>(_interface); }
|
Nanostack::MeshInterface *get_interface() const
|
||||||
|
{
|
||||||
|
return static_cast<Nanostack::MeshInterface *>(_interface);
|
||||||
|
}
|
||||||
NanostackRfPhy *_phy;
|
NanostackRfPhy *_phy;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,10 @@ private:
|
||||||
EthernetInterface(NanostackEthernetPhy &phy) : Interface(phy) {}
|
EthernetInterface(NanostackEthernetPhy &phy) : Interface(phy) {}
|
||||||
nsapi_error_t initialize();
|
nsapi_error_t initialize();
|
||||||
protected:
|
protected:
|
||||||
NanostackEthernetPhy &get_phy() const { return static_cast<NanostackEthernetPhy &>(Interface::get_phy()); }
|
NanostackEthernetPhy &get_phy() const
|
||||||
|
{
|
||||||
|
return static_cast<NanostackEthernetPhy &>(Interface::get_phy());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Ethernet interface for Nanostack.
|
/** Ethernet interface for Nanostack.
|
||||||
|
@ -50,7 +53,10 @@ public:
|
||||||
nsapi_error_t initialize(NanostackEthernetPhy *phy);
|
nsapi_error_t initialize(NanostackEthernetPhy *phy);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Nanostack::EthernetInterface *get_interface() const { return static_cast<Nanostack::EthernetInterface *>(_interface); }
|
Nanostack::EthernetInterface *get_interface() const
|
||||||
|
{
|
||||||
|
return static_cast<Nanostack::EthernetInterface *>(_interface);
|
||||||
|
}
|
||||||
virtual nsapi_error_t do_initialize();
|
virtual nsapi_error_t do_initialize();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,8 +8,7 @@
|
||||||
#include "ns_trace.h"
|
#include "ns_trace.h"
|
||||||
#define TRACE_GROUP "nslp"
|
#define TRACE_GROUP "nslp"
|
||||||
|
|
||||||
class Nanostack::LoWPANNDInterface : public Nanostack::MeshInterface
|
class Nanostack::LoWPANNDInterface : public Nanostack::MeshInterface {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
virtual nsapi_error_t bringup(bool dhcp, const char *ip,
|
virtual nsapi_error_t bringup(bool dhcp, const char *ip,
|
||||||
const char *netmask, const char *gw,
|
const char *netmask, const char *gw,
|
||||||
|
@ -29,7 +28,7 @@ private:
|
||||||
|
|
||||||
Nanostack::LoWPANNDInterface *LoWPANNDInterface::get_interface() const
|
Nanostack::LoWPANNDInterface *LoWPANNDInterface::get_interface() const
|
||||||
{
|
{
|
||||||
return static_cast<Nanostack::LoWPANNDInterface*>(_interface);
|
return static_cast<Nanostack::LoWPANNDInterface *>(_interface);
|
||||||
}
|
}
|
||||||
|
|
||||||
nsapi_error_t LoWPANNDInterface::do_initialize()
|
nsapi_error_t LoWPANNDInterface::do_initialize()
|
||||||
|
|
|
@ -69,7 +69,7 @@ void Nanostack::Interface::attach(
|
||||||
}
|
}
|
||||||
|
|
||||||
Nanostack::Interface::Interface(NanostackPhy &phy) : interface_phy(phy), interface_id(-1), _device_id(-1),
|
Nanostack::Interface::Interface(NanostackPhy &phy) : interface_phy(phy), interface_id(-1), _device_id(-1),
|
||||||
_connect_status(NSAPI_STATUS_DISCONNECTED), _previous_connection_status(NSAPI_STATUS_DISCONNECTED), _blocking(true)
|
_connect_status(NSAPI_STATUS_DISCONNECTED), _previous_connection_status(NSAPI_STATUS_DISCONNECTED), _blocking(true)
|
||||||
{
|
{
|
||||||
mesh_system_init();
|
mesh_system_init();
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ nsapi_error_t MeshInterfaceNanostack::initialize(NanostackRfPhy *phy)
|
||||||
void Nanostack::Interface::network_handler(mesh_connection_status_t status)
|
void Nanostack::Interface::network_handler(mesh_connection_status_t status)
|
||||||
{
|
{
|
||||||
if ((status == MESH_CONNECTED || status == MESH_CONNECTED_LOCAL ||
|
if ((status == MESH_CONNECTED || status == MESH_CONNECTED_LOCAL ||
|
||||||
status == MESH_CONNECTED_GLOBAL) && _blocking) {
|
status == MESH_CONNECTED_GLOBAL) && _blocking) {
|
||||||
connect_semaphore.release();
|
connect_semaphore.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,10 +131,10 @@ void Nanostack::Interface::network_handler(mesh_connection_status_t status)
|
||||||
_connect_status = NSAPI_STATUS_LOCAL_UP;
|
_connect_status = NSAPI_STATUS_LOCAL_UP;
|
||||||
}
|
}
|
||||||
if (arm_net_address_get(interface_id, ADDR_IPV6_GP, temp_ipv6_global) == 0
|
if (arm_net_address_get(interface_id, ADDR_IPV6_GP, temp_ipv6_global) == 0
|
||||||
&& (memcmp(temp_ipv6_global, temp_ipv6_local, 16) != 0)) {
|
&& (memcmp(temp_ipv6_global, temp_ipv6_local, 16) != 0)) {
|
||||||
_connect_status = NSAPI_STATUS_GLOBAL_UP;
|
_connect_status = NSAPI_STATUS_GLOBAL_UP;
|
||||||
}
|
}
|
||||||
} else if (status == MESH_CONNECTED_LOCAL ) {
|
} else if (status == MESH_CONNECTED_LOCAL) {
|
||||||
_connect_status = NSAPI_STATUS_LOCAL_UP;
|
_connect_status = NSAPI_STATUS_LOCAL_UP;
|
||||||
} else if (status == MESH_CONNECTED_GLOBAL) {
|
} else if (status == MESH_CONNECTED_GLOBAL) {
|
||||||
_connect_status = NSAPI_STATUS_GLOBAL_UP;
|
_connect_status = NSAPI_STATUS_GLOBAL_UP;
|
||||||
|
|
|
@ -8,16 +8,15 @@
|
||||||
#include "arm_hal_phy.h"
|
#include "arm_hal_phy.h"
|
||||||
#include "EMAC.h"
|
#include "EMAC.h"
|
||||||
|
|
||||||
class EMACPhy : public NanostackEthernetPhy
|
class EMACPhy : public NanostackEthernetPhy {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
EMACPhy(NanostackMemoryManager &mem, EMAC &m);
|
EMACPhy(NanostackMemoryManager &mem, EMAC &m);
|
||||||
virtual int8_t phy_register();
|
virtual int8_t phy_register();
|
||||||
virtual void get_mac_address(uint8_t *mac);
|
virtual void get_mac_address(uint8_t *mac);
|
||||||
virtual void set_mac_address(uint8_t *mac);
|
virtual void set_mac_address(uint8_t *mac);
|
||||||
|
|
||||||
int8_t address_write(phy_address_type_e , uint8_t *);
|
int8_t address_write(phy_address_type_e, uint8_t *);
|
||||||
int8_t tx(uint8_t *data_ptr, uint16_t data_len, uint8_t tx_handle,data_protocol_e data_flow);
|
int8_t tx(uint8_t *data_ptr, uint16_t data_len, uint8_t tx_handle, data_protocol_e data_flow);
|
||||||
|
|
||||||
void emac_phy_rx(emac_mem_buf_t *mem);
|
void emac_phy_rx(emac_mem_buf_t *mem);
|
||||||
|
|
||||||
|
@ -34,65 +33,65 @@ static EMACPhy *single_phy;
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
static int8_t emac_phy_address_write(phy_address_type_e address_type, uint8_t *address_ptr)
|
static int8_t emac_phy_address_write(phy_address_type_e address_type, uint8_t *address_ptr)
|
||||||
{
|
{
|
||||||
return single_phy->address_write(address_type, address_ptr);
|
return single_phy->address_write(address_type, address_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int8_t emac_phy_interface_state_control(phy_interface_state_e, uint8_t)
|
static int8_t emac_phy_interface_state_control(phy_interface_state_e, uint8_t)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int8_t emac_phy_tx(uint8_t *data_ptr, uint16_t data_len, uint8_t tx_handle,data_protocol_e data_flow)
|
static int8_t emac_phy_tx(uint8_t *data_ptr, uint16_t data_len, uint8_t tx_handle, data_protocol_e data_flow)
|
||||||
{
|
{
|
||||||
return single_phy->tx(data_ptr, data_len, tx_handle, data_flow);
|
return single_phy->tx(data_ptr, data_len, tx_handle, data_flow);
|
||||||
}
|
}
|
||||||
|
|
||||||
EMACPhy::EMACPhy(NanostackMemoryManager &mem, EMAC &m) : memory_manager(mem), emac(m), device_id(-1)
|
EMACPhy::EMACPhy(NanostackMemoryManager &mem, EMAC &m) : memory_manager(mem), emac(m), device_id(-1)
|
||||||
{
|
{
|
||||||
/* Same default address logic as lwIP glue uses */
|
/* Same default address logic as lwIP glue uses */
|
||||||
#if (MBED_MAC_ADDRESS_SUM != MBED_MAC_ADDR_INTERFACE)
|
#if (MBED_MAC_ADDRESS_SUM != MBED_MAC_ADDR_INTERFACE)
|
||||||
mac_addr[0] = MBED_MAC_ADDR_0;
|
mac_addr[0] = MBED_MAC_ADDR_0;
|
||||||
mac_addr[1] = MBED_MAC_ADDR_1;
|
mac_addr[1] = MBED_MAC_ADDR_1;
|
||||||
mac_addr[2] = MBED_MAC_ADDR_2;
|
mac_addr[2] = MBED_MAC_ADDR_2;
|
||||||
mac_addr[3] = MBED_MAC_ADDR_3;
|
mac_addr[3] = MBED_MAC_ADDR_3;
|
||||||
mac_addr[4] = MBED_MAC_ADDR_4;
|
mac_addr[4] = MBED_MAC_ADDR_4;
|
||||||
mac_addr[5] = MBED_MAC_ADDR_5;
|
mac_addr[5] = MBED_MAC_ADDR_5;
|
||||||
#else
|
#else
|
||||||
mbed_mac_address((char *) mac_addr);
|
mbed_mac_address((char *) mac_addr);
|
||||||
#endif
|
#endif
|
||||||
/* We have a default MAC address, so do don't force them to supply one */
|
/* We have a default MAC address, so do don't force them to supply one */
|
||||||
/* They may or may not update hwaddr with their address */
|
/* They may or may not update hwaddr with their address */
|
||||||
emac.get_hwaddr(mac_addr);
|
emac.get_hwaddr(mac_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void EMACPhy::emac_phy_rx(emac_mem_buf_t *mem)
|
void EMACPhy::emac_phy_rx(emac_mem_buf_t *mem)
|
||||||
{
|
{
|
||||||
const uint8_t *ptr = NULL;
|
const uint8_t *ptr = NULL;
|
||||||
uint8_t *tmpbuf = NULL;
|
uint8_t *tmpbuf = NULL;
|
||||||
uint32_t total_len;
|
uint32_t total_len;
|
||||||
|
|
||||||
if (memory_manager.get_next(mem) == NULL) {
|
if (memory_manager.get_next(mem) == NULL) {
|
||||||
// Easy contiguous case
|
// Easy contiguous case
|
||||||
ptr = static_cast<const uint8_t*>(memory_manager.get_ptr(mem));
|
ptr = static_cast<const uint8_t *>(memory_manager.get_ptr(mem));
|
||||||
total_len = memory_manager.get_len(mem);
|
total_len = memory_manager.get_len(mem);
|
||||||
} else {
|
} else {
|
||||||
// Nanostack can't accept chunked data - make temporary contiguous copy
|
// Nanostack can't accept chunked data - make temporary contiguous copy
|
||||||
total_len = memory_manager.get_total_len(mem);
|
total_len = memory_manager.get_total_len(mem);
|
||||||
ptr = tmpbuf = static_cast<uint8_t *>(ns_dyn_mem_temporary_alloc(total_len));
|
ptr = tmpbuf = static_cast<uint8_t *>(ns_dyn_mem_temporary_alloc(total_len));
|
||||||
if (tmpbuf) {
|
if (tmpbuf) {
|
||||||
memory_manager.copy_from_buf(tmpbuf, total_len, mem);
|
memory_manager.copy_from_buf(tmpbuf, total_len, mem);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (ptr && phy.phy_rx_cb) {
|
if (ptr && phy.phy_rx_cb) {
|
||||||
phy.phy_rx_cb(ptr, total_len, 0xff, 0, device_id);
|
phy.phy_rx_cb(ptr, total_len, 0xff, 0, device_id);
|
||||||
|
}
|
||||||
|
ns_dyn_mem_free(tmpbuf);
|
||||||
|
memory_manager.free(mem);
|
||||||
}
|
}
|
||||||
ns_dyn_mem_free(tmpbuf);
|
|
||||||
memory_manager.free(mem);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
|
||||||
|
@ -106,7 +105,7 @@ int8_t EMACPhy::address_write(phy_address_type_e address_type, uint8_t *address_
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t EMACPhy::tx(uint8_t *data_ptr, uint16_t data_len, uint8_t tx_handle,data_protocol_e data_flow)
|
int8_t EMACPhy::tx(uint8_t *data_ptr, uint16_t data_len, uint8_t tx_handle, data_protocol_e data_flow)
|
||||||
{
|
{
|
||||||
emac_mem_buf_t *mem = memory_manager.alloc_pool(data_len, 0);
|
emac_mem_buf_t *mem = memory_manager.alloc_pool(data_len, 0);
|
||||||
if (!mem) {
|
if (!mem) {
|
||||||
|
@ -126,7 +125,7 @@ int8_t EMACPhy::phy_register()
|
||||||
|
|
||||||
phy.PHY_MAC = mac_addr;
|
phy.PHY_MAC = mac_addr;
|
||||||
phy.address_write = emac_phy_address_write;
|
phy.address_write = emac_phy_address_write;
|
||||||
phy.driver_description = const_cast<char*>("ETH");
|
phy.driver_description = const_cast<char *>("ETH");
|
||||||
phy.link_type = PHY_LINK_ETHERNET_TYPE;
|
phy.link_type = PHY_LINK_ETHERNET_TYPE;
|
||||||
phy.phy_MTU = 0;
|
phy.phy_MTU = 0;
|
||||||
phy.phy_header_length = 0;
|
phy.phy_header_length = 0;
|
||||||
|
@ -153,9 +152,9 @@ int8_t EMACPhy::phy_register()
|
||||||
emac.set_all_multicast(true);
|
emac.set_all_multicast(true);
|
||||||
|
|
||||||
device_id = arm_net_phy_register(&phy);
|
device_id = arm_net_phy_register(&phy);
|
||||||
// driver_readiness_status_callback = driver_status_cb;
|
// driver_readiness_status_callback = driver_status_cb;
|
||||||
|
|
||||||
if (device_id < 0){
|
if (device_id < 0) {
|
||||||
//tr_error("Ethernet Driver failed to register with Stack. RetCode=%i", eth_driver_enabled);
|
//tr_error("Ethernet Driver failed to register with Stack. RetCode=%i", eth_driver_enabled);
|
||||||
//driver_readiness_status_callback(0, eth_interface_id);
|
//driver_readiness_status_callback(0, eth_interface_id);
|
||||||
emac.power_down();
|
emac.power_down();
|
||||||
|
@ -188,7 +187,7 @@ nsapi_error_t Nanostack::add_ethernet_interface(EMAC &emac, bool default_if, Nan
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mac_addr) {
|
if (mac_addr) {
|
||||||
single_phy->set_mac_address(const_cast<uint8_t*>(mac_addr));
|
single_phy->set_mac_address(const_cast<uint8_t *>(mac_addr));
|
||||||
}
|
}
|
||||||
|
|
||||||
Nanostack::EthernetInterface *interface;
|
Nanostack::EthernetInterface *interface;
|
||||||
|
|
|
@ -44,11 +44,11 @@ nsapi_error_t NanostackEthernetInterface::initialize(NanostackEthernetPhy *phy)
|
||||||
}
|
}
|
||||||
|
|
||||||
return get_interface()->initialize();
|
return get_interface()->initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
nsapi_error_t Nanostack::EthernetInterface::bringup(bool dhcp, const char *ip,
|
nsapi_error_t Nanostack::EthernetInterface::bringup(bool dhcp, const char *ip,
|
||||||
const char *netmask, const char *gw,
|
const char *netmask, const char *gw,
|
||||||
nsapi_ip_stack_t stack, bool blocking)
|
nsapi_ip_stack_t stack, bool blocking)
|
||||||
{
|
{
|
||||||
if (stack == IPV4_STACK) {
|
if (stack == IPV4_STACK) {
|
||||||
return NSAPI_ERROR_UNSUPPORTED;
|
return NSAPI_ERROR_UNSUPPORTED;
|
||||||
|
|
|
@ -19,8 +19,7 @@
|
||||||
#include "mbed_assert.h"
|
#include "mbed_assert.h"
|
||||||
#include "NanostackMemoryManager.h"
|
#include "NanostackMemoryManager.h"
|
||||||
|
|
||||||
struct ns_stack_mem_t
|
struct ns_stack_mem_t {
|
||||||
{
|
|
||||||
ns_stack_mem_t *next;
|
ns_stack_mem_t *next;
|
||||||
void *payload;
|
void *payload;
|
||||||
uint32_t len;
|
uint32_t len;
|
||||||
|
|
|
@ -7,8 +7,7 @@
|
||||||
#include "ns_trace.h"
|
#include "ns_trace.h"
|
||||||
#define TRACE_GROUP "nsth"
|
#define TRACE_GROUP "nsth"
|
||||||
|
|
||||||
class Nanostack::ThreadInterface : public Nanostack::MeshInterface
|
class Nanostack::ThreadInterface : public Nanostack::MeshInterface {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
virtual nsapi_error_t bringup(bool dhcp, const char *ip,
|
virtual nsapi_error_t bringup(bool dhcp, const char *ip,
|
||||||
const char *netmask, const char *gw,
|
const char *netmask, const char *gw,
|
||||||
|
@ -73,7 +72,7 @@ private:
|
||||||
|
|
||||||
Nanostack::ThreadInterface *ThreadInterface::get_interface() const
|
Nanostack::ThreadInterface *ThreadInterface::get_interface() const
|
||||||
{
|
{
|
||||||
return static_cast<Nanostack::ThreadInterface*>(_interface);
|
return static_cast<Nanostack::ThreadInterface *>(_interface);
|
||||||
}
|
}
|
||||||
|
|
||||||
nsapi_error_t ThreadInterface::do_initialize()
|
nsapi_error_t ThreadInterface::do_initialize()
|
||||||
|
|
|
@ -189,7 +189,7 @@ static void enet_tasklet_poll_network_status(void *param)
|
||||||
memcpy(tasklet_data_ptr->ip, temp_ipv6, 16);
|
memcpy(tasklet_data_ptr->ip, temp_ipv6, 16);
|
||||||
uint8_t temp_ipv6_local[16];
|
uint8_t temp_ipv6_local[16];
|
||||||
if (arm_net_address_get(tasklet_data_ptr->network_interface_id, ADDR_IPV6_LL, temp_ipv6_local) == 0
|
if (arm_net_address_get(tasklet_data_ptr->network_interface_id, ADDR_IPV6_LL, temp_ipv6_local) == 0
|
||||||
&& (memcmp(temp_ipv6, temp_ipv6_local, 16) != 0)) {
|
&& (memcmp(temp_ipv6, temp_ipv6_local, 16) != 0)) {
|
||||||
enet_tasklet_network_state_changed(MESH_CONNECTED_GLOBAL);
|
enet_tasklet_network_state_changed(MESH_CONNECTED_GLOBAL);
|
||||||
} else {
|
} else {
|
||||||
enet_tasklet_network_state_changed(MESH_CONNECTED_LOCAL);;
|
enet_tasklet_network_state_changed(MESH_CONNECTED_LOCAL);;
|
||||||
|
@ -197,8 +197,9 @@ static void enet_tasklet_poll_network_status(void *param)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (tasklet_data_ptr->connection_status != MESH_DISCONNECTED &&
|
if (tasklet_data_ptr->connection_status != MESH_DISCONNECTED &&
|
||||||
tasklet_data_ptr->connection_status != MESH_BOOTSTRAP_STARTED)
|
tasklet_data_ptr->connection_status != MESH_BOOTSTRAP_STARTED) {
|
||||||
enet_tasklet_network_state_changed(MESH_DISCONNECTED);
|
enet_tasklet_network_state_changed(MESH_DISCONNECTED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,7 +243,7 @@ int8_t enet_tasklet_connect(mesh_interface_cb callback, int8_t nwk_interface_id)
|
||||||
|
|
||||||
if (re_connecting == false) {
|
if (re_connecting == false) {
|
||||||
tasklet_data_ptr->tasklet = eventOS_event_handler_create(&enet_tasklet_main,
|
tasklet_data_ptr->tasklet = eventOS_event_handler_create(&enet_tasklet_main,
|
||||||
ARM_LIB_TASKLET_INIT_EVENT);
|
ARM_LIB_TASKLET_INIT_EVENT);
|
||||||
if (tasklet_data_ptr->tasklet < 0) {
|
if (tasklet_data_ptr->tasklet < 0) {
|
||||||
// -1 handler already used by other tasklet
|
// -1 handler already used by other tasklet
|
||||||
// -2 memory allocation failure
|
// -2 memory allocation failure
|
||||||
|
|
|
@ -54,7 +54,7 @@ void mesh_system_init(void)
|
||||||
{
|
{
|
||||||
if (mesh_initialized == false) {
|
if (mesh_initialized == false) {
|
||||||
#if MBED_CONF_MBED_MESH_API_USE_MALLOC_FOR_HEAP
|
#if MBED_CONF_MBED_MESH_API_USE_MALLOC_FOR_HEAP
|
||||||
app_stack_heap = malloc(MBED_CONF_MBED_MESH_API_HEAP_SIZE+1);
|
app_stack_heap = malloc(MBED_CONF_MBED_MESH_API_HEAP_SIZE + 1);
|
||||||
MBED_ASSERT(app_stack_heap);
|
MBED_ASSERT(app_stack_heap);
|
||||||
#endif
|
#endif
|
||||||
ns_hal_init(app_stack_heap, MBED_CONF_MBED_MESH_API_HEAP_SIZE,
|
ns_hal_init(app_stack_heap, MBED_CONF_MBED_MESH_API_HEAP_SIZE,
|
||||||
|
|
|
@ -214,7 +214,7 @@ void nd_tasklet_parse_network_event(arm_event_s *event)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tasklet_data_ptr->tasklet_state != TASKLET_STATE_BOOTSTRAP_READY &&
|
if (tasklet_data_ptr->tasklet_state != TASKLET_STATE_BOOTSTRAP_READY &&
|
||||||
tasklet_data_ptr->network_interface_id != INVALID_INTERFACE_ID) {
|
tasklet_data_ptr->network_interface_id != INVALID_INTERFACE_ID) {
|
||||||
// Set 5s timer for new network scan
|
// Set 5s timer for new network scan
|
||||||
eventOS_event_timer_request(TIMER_EVENT_START_BOOTSTRAP,
|
eventOS_event_timer_request(TIMER_EVENT_START_BOOTSTRAP,
|
||||||
ARM_LIB_SYSTEM_TIMER_EVENT,
|
ARM_LIB_SYSTEM_TIMER_EVENT,
|
||||||
|
@ -268,15 +268,15 @@ void nd_tasklet_configure_and_connect_to_network(void)
|
||||||
tasklet_data_ptr->network_interface_id, NULL);
|
tasklet_data_ptr->network_interface_id, NULL);
|
||||||
|
|
||||||
arm_nwk_6lowpan_link_panid_filter_for_nwk_scan(
|
arm_nwk_6lowpan_link_panid_filter_for_nwk_scan(
|
||||||
tasklet_data_ptr->network_interface_id,
|
tasklet_data_ptr->network_interface_id,
|
||||||
MBED_CONF_MBED_MESH_API_6LOWPAN_ND_PANID_FILTER);
|
MBED_CONF_MBED_MESH_API_6LOWPAN_ND_PANID_FILTER);
|
||||||
|
|
||||||
// Enable MPL by default
|
// Enable MPL by default
|
||||||
const uint8_t all_mpl_forwarders[16] = {0xff, 0x03, [15]=0xfc};
|
const uint8_t all_mpl_forwarders[16] = {0xff, 0x03, [15] = 0xfc};
|
||||||
multicast_mpl_domain_subscribe(tasklet_data_ptr->network_interface_id,
|
multicast_mpl_domain_subscribe(tasklet_data_ptr->network_interface_id,
|
||||||
all_mpl_forwarders,
|
all_mpl_forwarders,
|
||||||
MULTICAST_MPL_SEED_ID_DEFAULT,
|
MULTICAST_MPL_SEED_ID_DEFAULT,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
status = arm_nwk_interface_up(tasklet_data_ptr->network_interface_id);
|
status = arm_nwk_interface_up(tasklet_data_ptr->network_interface_id);
|
||||||
if (status >= 0) {
|
if (status >= 0) {
|
||||||
|
@ -327,7 +327,7 @@ void nd_tasklet_trace_bootstrap_info()
|
||||||
tr_error("MAC Address read fail\n");
|
tr_error("MAC Address read fail\n");
|
||||||
} else {
|
} else {
|
||||||
uint8_t temp[2];
|
uint8_t temp[2];
|
||||||
common_write_16_bit(app_link_address_info.mac_short,temp);
|
common_write_16_bit(app_link_address_info.mac_short, temp);
|
||||||
tr_debug("MAC 16-bit: %s", trace_array(temp, 2));
|
tr_debug("MAC 16-bit: %s", trace_array(temp, 2));
|
||||||
common_write_16_bit(app_link_address_info.PANId, temp);
|
common_write_16_bit(app_link_address_info.PANId, temp);
|
||||||
tr_debug("PAN ID: %s", trace_array(temp, 2));
|
tr_debug("PAN ID: %s", trace_array(temp, 2));
|
||||||
|
@ -378,7 +378,7 @@ int8_t nd_tasklet_connect(mesh_interface_cb callback, int8_t nwk_interface_id)
|
||||||
|
|
||||||
if (re_connecting == false) {
|
if (re_connecting == false) {
|
||||||
tasklet_data_ptr->tasklet = eventOS_event_handler_create(&nd_tasklet_main,
|
tasklet_data_ptr->tasklet = eventOS_event_handler_create(&nd_tasklet_main,
|
||||||
ARM_LIB_TASKLET_INIT_EVENT);
|
ARM_LIB_TASKLET_INIT_EVENT);
|
||||||
if (tasklet_data_ptr->tasklet < 0) {
|
if (tasklet_data_ptr->tasklet < 0) {
|
||||||
// -1 handler already used by other tasklet
|
// -1 handler already used by other tasklet
|
||||||
// -2 memory allocation failure
|
// -2 memory allocation failure
|
||||||
|
|
|
@ -218,7 +218,7 @@ void thread_tasklet_parse_network_event(arm_event_s *event)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (thread_tasklet_data_ptr->tasklet_state != TASKLET_STATE_BOOTSTRAP_READY &&
|
if (thread_tasklet_data_ptr->tasklet_state != TASKLET_STATE_BOOTSTRAP_READY &&
|
||||||
thread_tasklet_data_ptr->nwk_if_id != INVALID_INTERFACE_ID) {
|
thread_tasklet_data_ptr->nwk_if_id != INVALID_INTERFACE_ID) {
|
||||||
// Set 5s timer for a new network scan
|
// Set 5s timer for a new network scan
|
||||||
eventOS_event_timer_request(TIMER_EVENT_START_BOOTSTRAP,
|
eventOS_event_timer_request(TIMER_EVENT_START_BOOTSTRAP,
|
||||||
ARM_LIB_SYSTEM_TIMER_EVENT,
|
ARM_LIB_SYSTEM_TIMER_EVENT,
|
||||||
|
@ -246,23 +246,25 @@ void thread_tasklet_poll_network_status(void *param)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (thread_tasklet_data_ptr->connection_status != MESH_DISCONNECTED &&
|
if (thread_tasklet_data_ptr->connection_status != MESH_DISCONNECTED &&
|
||||||
thread_tasklet_data_ptr->connection_status != MESH_BOOTSTRAP_STARTED)
|
thread_tasklet_data_ptr->connection_status != MESH_BOOTSTRAP_STARTED) {
|
||||||
thread_tasklet_network_state_changed(MESH_DISCONNECTED);
|
thread_tasklet_network_state_changed(MESH_DISCONNECTED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void read_link_configuration() {
|
void read_link_configuration()
|
||||||
|
{
|
||||||
|
|
||||||
thread_tasklet_data_ptr->link_config.panId = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_PANID;
|
thread_tasklet_data_ptr->link_config.panId = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_PANID;
|
||||||
TRACE_DETAIL("PANID %x", thread_tasklet_data_ptr->link_config.panId);
|
TRACE_DETAIL("PANID %x", thread_tasklet_data_ptr->link_config.panId);
|
||||||
|
|
||||||
thread_tasklet_data_ptr->link_config.rfChannel = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_CHANNEL;
|
thread_tasklet_data_ptr->link_config.rfChannel = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_CHANNEL;
|
||||||
TRACE_DETAIL("channel: %d", thread_tasklet_data_ptr->link_config.rfChannel);
|
TRACE_DETAIL("channel: %d", thread_tasklet_data_ptr->link_config.rfChannel);
|
||||||
|
|
||||||
// Mesh prefix
|
// Mesh prefix
|
||||||
const uint8_t mesh_local_prefix[] = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_ML_PREFIX;
|
const uint8_t mesh_local_prefix[] = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_ML_PREFIX;
|
||||||
MBED_ASSERT(sizeof(mesh_local_prefix) == 8);
|
MBED_ASSERT(sizeof(mesh_local_prefix) == 8);
|
||||||
|
|
||||||
memcpy(thread_tasklet_data_ptr->link_config.mesh_local_ula_prefix, mesh_local_prefix, 8);
|
memcpy(thread_tasklet_data_ptr->link_config.mesh_local_ula_prefix, mesh_local_prefix, 8);
|
||||||
TRACE_DETAIL("Mesh prefix: %s", trace_array(mesh_local_prefix, 8));
|
TRACE_DETAIL("Mesh prefix: %s", trace_array(mesh_local_prefix, 8));
|
||||||
|
|
||||||
|
@ -279,14 +281,14 @@ void read_link_configuration() {
|
||||||
thread_tasklet_data_ptr->link_config.key_rotation = 3600;
|
thread_tasklet_data_ptr->link_config.key_rotation = 3600;
|
||||||
thread_tasklet_data_ptr->link_config.key_sequence = 0;
|
thread_tasklet_data_ptr->link_config.key_sequence = 0;
|
||||||
|
|
||||||
thread_tasklet_data_ptr->link_config.securityPolicy = MBED_CONF_MBED_MESH_API_THREAD_SECURITY_POLICY;
|
thread_tasklet_data_ptr->link_config.securityPolicy = MBED_CONF_MBED_MESH_API_THREAD_SECURITY_POLICY;
|
||||||
|
|
||||||
// network name
|
// network name
|
||||||
MBED_ASSERT(strlen(MBED_CONF_MBED_MESH_API_THREAD_CONFIG_NETWORK_NAME) > 0 && strlen(MBED_CONF_MBED_MESH_API_THREAD_CONFIG_NETWORK_NAME) < 17);
|
MBED_ASSERT(strlen(MBED_CONF_MBED_MESH_API_THREAD_CONFIG_NETWORK_NAME) > 0 && strlen(MBED_CONF_MBED_MESH_API_THREAD_CONFIG_NETWORK_NAME) < 17);
|
||||||
memcpy(thread_tasklet_data_ptr->link_config.name, MBED_CONF_MBED_MESH_API_THREAD_CONFIG_NETWORK_NAME, strlen(MBED_CONF_MBED_MESH_API_THREAD_CONFIG_NETWORK_NAME));
|
memcpy(thread_tasklet_data_ptr->link_config.name, MBED_CONF_MBED_MESH_API_THREAD_CONFIG_NETWORK_NAME, strlen(MBED_CONF_MBED_MESH_API_THREAD_CONFIG_NETWORK_NAME));
|
||||||
|
|
||||||
thread_tasklet_data_ptr->link_config.timestamp = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_COMMISSIONING_DATASET_TIMESTAMP;
|
thread_tasklet_data_ptr->link_config.timestamp = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_COMMISSIONING_DATASET_TIMESTAMP;
|
||||||
|
|
||||||
// extended pan-id
|
// extended pan-id
|
||||||
const uint8_t extented_panid[] = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_EXTENDED_PANID;
|
const uint8_t extented_panid[] = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_EXTENDED_PANID;
|
||||||
MBED_ASSERT(sizeof(extented_panid) == 8);
|
MBED_ASSERT(sizeof(extented_panid) == 8);
|
||||||
|
@ -300,13 +302,12 @@ void read_link_configuration() {
|
||||||
void thread_tasklet_configure_and_connect_to_network(void)
|
void thread_tasklet_configure_and_connect_to_network(void)
|
||||||
{
|
{
|
||||||
int8_t status;
|
int8_t status;
|
||||||
link_configuration_s* temp_link_config=NULL;
|
link_configuration_s *temp_link_config = NULL;
|
||||||
|
|
||||||
|
|
||||||
if (MBED_CONF_MBED_MESH_API_THREAD_DEVICE_TYPE == MESH_DEVICE_TYPE_THREAD_MINIMAL_END_DEVICE) {
|
if (MBED_CONF_MBED_MESH_API_THREAD_DEVICE_TYPE == MESH_DEVICE_TYPE_THREAD_MINIMAL_END_DEVICE) {
|
||||||
thread_tasklet_data_ptr->operating_mode = NET_6LOWPAN_HOST;
|
thread_tasklet_data_ptr->operating_mode = NET_6LOWPAN_HOST;
|
||||||
}
|
} else if (MBED_CONF_MBED_MESH_API_THREAD_DEVICE_TYPE == MESH_DEVICE_TYPE_THREAD_SLEEPY_END_DEVICE) {
|
||||||
else if (MBED_CONF_MBED_MESH_API_THREAD_DEVICE_TYPE == MESH_DEVICE_TYPE_THREAD_SLEEPY_END_DEVICE) {
|
|
||||||
thread_tasklet_data_ptr->operating_mode = NET_6LOWPAN_SLEEPY_HOST;
|
thread_tasklet_data_ptr->operating_mode = NET_6LOWPAN_SLEEPY_HOST;
|
||||||
} else {
|
} else {
|
||||||
thread_tasklet_data_ptr->operating_mode = NET_6LOWPAN_ROUTER;
|
thread_tasklet_data_ptr->operating_mode = NET_6LOWPAN_ROUTER;
|
||||||
|
@ -316,16 +317,16 @@ void thread_tasklet_configure_and_connect_to_network(void)
|
||||||
thread_tasklet_data_ptr->nwk_if_id,
|
thread_tasklet_data_ptr->nwk_if_id,
|
||||||
thread_tasklet_data_ptr->operating_mode,
|
thread_tasklet_data_ptr->operating_mode,
|
||||||
NET_6LOWPAN_THREAD);
|
NET_6LOWPAN_THREAD);
|
||||||
|
|
||||||
thread_tasklet_data_ptr->channel_list.channel_page = (channel_page_e)MBED_CONF_MBED_MESH_API_THREAD_CONFIG_CHANNEL_PAGE;
|
thread_tasklet_data_ptr->channel_list.channel_page = (channel_page_e)MBED_CONF_MBED_MESH_API_THREAD_CONFIG_CHANNEL_PAGE;
|
||||||
thread_tasklet_data_ptr->channel_list.channel_mask[0] = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_CHANNEL_MASK;
|
thread_tasklet_data_ptr->channel_list.channel_mask[0] = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_CHANNEL_MASK;
|
||||||
|
|
||||||
TRACE_DETAIL("channel page: %d", thread_tasklet_data_ptr->channel_list.channel_page);
|
TRACE_DETAIL("channel page: %d", thread_tasklet_data_ptr->channel_list.channel_page);
|
||||||
TRACE_DETAIL("channel mask: 0x%.8lx", thread_tasklet_data_ptr->channel_list.channel_mask[0]);
|
TRACE_DETAIL("channel mask: 0x%.8lx", thread_tasklet_data_ptr->channel_list.channel_mask[0]);
|
||||||
|
|
||||||
// PSKd
|
// PSKd
|
||||||
const char PSKd[] = MBED_CONF_MBED_MESH_API_THREAD_PSKD;
|
const char PSKd[] = MBED_CONF_MBED_MESH_API_THREAD_PSKD;
|
||||||
if(device_configuration.PSKd_len==0) {
|
if (device_configuration.PSKd_len == 0) {
|
||||||
int ret = thread_tasklet_device_pskd_set(PSKd);
|
int ret = thread_tasklet_device_pskd_set(PSKd);
|
||||||
MBED_ASSERT(!ret);
|
MBED_ASSERT(!ret);
|
||||||
}
|
}
|
||||||
|
@ -334,11 +335,11 @@ void thread_tasklet_configure_and_connect_to_network(void)
|
||||||
read_link_configuration();
|
read_link_configuration();
|
||||||
temp_link_config = &thread_tasklet_data_ptr->link_config;
|
temp_link_config = &thread_tasklet_data_ptr->link_config;
|
||||||
}
|
}
|
||||||
|
|
||||||
thread_management_node_init(thread_tasklet_data_ptr->nwk_if_id,
|
thread_management_node_init(thread_tasklet_data_ptr->nwk_if_id,
|
||||||
&thread_tasklet_data_ptr->channel_list,
|
&thread_tasklet_data_ptr->channel_list,
|
||||||
&device_configuration,
|
&device_configuration,
|
||||||
temp_link_config);
|
temp_link_config);
|
||||||
|
|
||||||
status = arm_nwk_interface_up(thread_tasklet_data_ptr->nwk_if_id);
|
status = arm_nwk_interface_up(thread_tasklet_data_ptr->nwk_if_id);
|
||||||
|
|
||||||
|
@ -382,7 +383,7 @@ void thread_tasklet_trace_bootstrap_info()
|
||||||
tr_error("MAC Address read fail\n");
|
tr_error("MAC Address read fail\n");
|
||||||
} else {
|
} else {
|
||||||
uint8_t temp[2];
|
uint8_t temp[2];
|
||||||
common_write_16_bit(app_link_address_info.mac_short,temp);
|
common_write_16_bit(app_link_address_info.mac_short, temp);
|
||||||
tr_debug("MAC 16-bit: %s", trace_array(temp, 2));
|
tr_debug("MAC 16-bit: %s", trace_array(temp, 2));
|
||||||
common_write_16_bit(app_link_address_info.PANId, temp);
|
common_write_16_bit(app_link_address_info.PANId, temp);
|
||||||
tr_debug("PAN ID: %s", trace_array(temp, 2));
|
tr_debug("PAN ID: %s", trace_array(temp, 2));
|
||||||
|
@ -414,12 +415,12 @@ int8_t thread_tasklet_connect(mesh_interface_cb callback, int8_t nwk_interface_i
|
||||||
|
|
||||||
if (re_connecting == false) {
|
if (re_connecting == false) {
|
||||||
thread_tasklet_data_ptr->tasklet = eventOS_event_handler_create(&thread_tasklet_main,
|
thread_tasklet_data_ptr->tasklet = eventOS_event_handler_create(&thread_tasklet_main,
|
||||||
ARM_LIB_TASKLET_INIT_EVENT);
|
ARM_LIB_TASKLET_INIT_EVENT);
|
||||||
if (thread_tasklet_data_ptr->tasklet < 0) {
|
if (thread_tasklet_data_ptr->tasklet < 0) {
|
||||||
// -1 handler already used by other tasklet
|
// -1 handler already used by other tasklet
|
||||||
// -2 memory allocation failure
|
// -2 memory allocation failure
|
||||||
return thread_tasklet_data_ptr->tasklet;
|
return thread_tasklet_data_ptr->tasklet;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
thread_tasklet_data_ptr->tasklet = tasklet;
|
thread_tasklet_data_ptr->tasklet = tasklet;
|
||||||
mesh_system_send_connect_event(thread_tasklet_data_ptr->tasklet);
|
mesh_system_send_connect_event(thread_tasklet_data_ptr->tasklet);
|
||||||
|
@ -486,16 +487,16 @@ void thread_tasklet_device_eui64_get(uint8_t *eui64)
|
||||||
uint8_t thread_tasklet_device_pskd_set(const char *pskd)
|
uint8_t thread_tasklet_device_pskd_set(const char *pskd)
|
||||||
{
|
{
|
||||||
int len = strlen(pskd);
|
int len = strlen(pskd);
|
||||||
if(len < 6 || len > 32) {
|
if (len < 6 || len > 32) {
|
||||||
return MESH_ERROR_PARAM;
|
return MESH_ERROR_PARAM;
|
||||||
}
|
}
|
||||||
char *dyn_buf = ns_dyn_mem_alloc(strlen(pskd)+1);
|
char *dyn_buf = ns_dyn_mem_alloc(strlen(pskd) + 1);
|
||||||
if (!dyn_buf) {
|
if (!dyn_buf) {
|
||||||
return MESH_ERROR_MEMORY;
|
return MESH_ERROR_MEMORY;
|
||||||
}
|
}
|
||||||
strcpy(dyn_buf, pskd);
|
strcpy(dyn_buf, pskd);
|
||||||
ns_dyn_mem_free(device_configuration.PSKd_ptr);
|
ns_dyn_mem_free(device_configuration.PSKd_ptr);
|
||||||
device_configuration.PSKd_ptr = (uint8_t*)dyn_buf;
|
device_configuration.PSKd_ptr = (uint8_t *)dyn_buf;
|
||||||
device_configuration.PSKd_len = strlen(pskd);
|
device_configuration.PSKd_len = strlen(pskd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,8 +36,7 @@ static const fhss_api_t *fhss_active_handle = NULL;
|
||||||
static EventQueue *equeue;
|
static EventQueue *equeue;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct fhss_timeout_s
|
struct fhss_timeout_s {
|
||||||
{
|
|
||||||
void (*fhss_timer_callback)(const fhss_api_t *fhss_api, uint16_t);
|
void (*fhss_timer_callback)(const fhss_api_t *fhss_api, uint16_t);
|
||||||
uint32_t start_time;
|
uint32_t start_time;
|
||||||
uint32_t stop_time;
|
uint32_t stop_time;
|
||||||
|
|
|
@ -39,10 +39,10 @@ static uint8_t sys_irq_disable_counter;
|
||||||
|
|
||||||
static mbed_rtos_storage_mutex_t critical_mutex;
|
static mbed_rtos_storage_mutex_t critical_mutex;
|
||||||
static const osMutexAttr_t critical_mutex_attr = {
|
static const osMutexAttr_t critical_mutex_attr = {
|
||||||
.name = "nanostack_critical_mutex",
|
.name = "nanostack_critical_mutex",
|
||||||
.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust,
|
.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust,
|
||||||
.cb_mem = &critical_mutex,
|
.cb_mem = &critical_mutex,
|
||||||
.cb_size = sizeof critical_mutex,
|
.cb_size = sizeof critical_mutex,
|
||||||
};
|
};
|
||||||
static osMutexId_t critical_mutex_id;
|
static osMutexId_t critical_mutex_id;
|
||||||
|
|
||||||
|
|
|
@ -94,7 +94,7 @@ uint16_t platform_timer_get_remaining_slots(void)
|
||||||
{
|
{
|
||||||
uint32_t elapsed = timer->read_us();
|
uint32_t elapsed = timer->read_us();
|
||||||
if (elapsed < due) {
|
if (elapsed < due) {
|
||||||
return (uint16_t) ((due - elapsed) / 50);
|
return (uint16_t)((due - elapsed) / 50);
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,9 +99,9 @@ static void nvm_fsm_timer_cb(void *arg);
|
||||||
static void configuration_store_cb(int32_t status, ARM_CFSTORE_OPCODE cmd_code, void *ctx, ARM_CFSTORE_HANDLE handle)
|
static void configuration_store_cb(int32_t status, ARM_CFSTORE_OPCODE cmd_code, void *ctx, ARM_CFSTORE_HANDLE handle)
|
||||||
{
|
{
|
||||||
tr_debug("configuration_store_cb status=%d, cmd_code=%d, ctx=%x, hndl=%x", (int)status, (int)cmd_code, (unsigned int)ctx, (unsigned int)handle);
|
tr_debug("configuration_store_cb status=%d, cmd_code=%d, ctx=%x, hndl=%x", (int)status, (int)cmd_code, (unsigned int)ctx, (unsigned int)handle);
|
||||||
cs_context_t *cf_context = (cs_context_t*)ctx;
|
cs_context_t *cf_context = (cs_context_t *)ctx;
|
||||||
|
|
||||||
switch(cmd_code) {
|
switch (cmd_code) {
|
||||||
case CFSTORE_OPCODE_INITIALIZE:
|
case CFSTORE_OPCODE_INITIALIZE:
|
||||||
tr_debug("CFSTORE_OPCODE_INITIALIZE %d", (int)status);
|
tr_debug("CFSTORE_OPCODE_INITIALIZE %d", (int)status);
|
||||||
cf_context->state = NVM_STATE_INIT_DONE;
|
cf_context->state = NVM_STATE_INIT_DONE;
|
||||||
|
@ -229,8 +229,7 @@ static int nvm_fsm_update(cs_context_t *cs_context)
|
||||||
int ret_val = 0;
|
int ret_val = 0;
|
||||||
|
|
||||||
tr_debug("nvm_fsm_update() state=%d", (int)cs_context->state);
|
tr_debug("nvm_fsm_update() state=%d", (int)cs_context->state);
|
||||||
switch (cs_context->state)
|
switch (cs_context->state) {
|
||||||
{
|
|
||||||
case NVM_STATE_UNINIT_DONE:
|
case NVM_STATE_UNINIT_DONE:
|
||||||
cs_context->client_cb(cs_context->client_status, cs_context->client_context);
|
cs_context->client_cb(cs_context->client_status, cs_context->client_context);
|
||||||
cs_context->state = NVM_STATE_NONE;
|
cs_context->state = NVM_STATE_NONE;
|
||||||
|
@ -288,7 +287,7 @@ platform_nvm_status platform_nvm_init(nvm_callback *callback, void *context)
|
||||||
|
|
||||||
cs_context_ptr->capabilities = drv->GetCapabilities();
|
cs_context_ptr->capabilities = drv->GetCapabilities();
|
||||||
|
|
||||||
tr_debug("mode: %s", IS_SYNC_MODE(cs_context_ptr) ? "sync": "async" );
|
tr_debug("mode: %s", IS_SYNC_MODE(cs_context_ptr) ? "sync" : "async");
|
||||||
|
|
||||||
ret = drv->Initialize(configuration_store_cb, cs_context_ptr);
|
ret = drv->Initialize(configuration_store_cb, cs_context_ptr);
|
||||||
if (ret < ARM_DRIVER_OK) {
|
if (ret < ARM_DRIVER_OK) {
|
||||||
|
@ -367,14 +366,14 @@ platform_nvm_status platform_nvm_key_create(nvm_callback *callback, const char *
|
||||||
keydesc.drl = ARM_RETENTION_NVM;
|
keydesc.drl = ARM_RETENTION_NVM;
|
||||||
|
|
||||||
ret = drv->Create(key_name, value_len, &keydesc, cs_context_ptr->hkey);
|
ret = drv->Create(key_name, value_len, &keydesc, cs_context_ptr->hkey);
|
||||||
if(ret < ARM_DRIVER_OK) {
|
if (ret < ARM_DRIVER_OK) {
|
||||||
if (ret == ARM_CFSTORE_DRIVER_ERROR_PREEXISTING_KEY) {
|
if (ret == ARM_CFSTORE_DRIVER_ERROR_PREEXISTING_KEY) {
|
||||||
tr_debug("adjust value len to %d", value_len);
|
tr_debug("adjust value len to %d", value_len);
|
||||||
ret = drv->Create(key_name, value_len, NULL, cs_context_ptr->hkey);
|
ret = drv->Create(key_name, value_len, NULL, cs_context_ptr->hkey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ret < ARM_DRIVER_OK) {
|
if (ret < ARM_DRIVER_OK) {
|
||||||
tr_error("Key creation failed %d", (int)ret);
|
tr_error("Key creation failed %d", (int)ret);
|
||||||
cs_context_ptr->state = NVM_STATE_CREATE_DONE;
|
cs_context_ptr->state = NVM_STATE_CREATE_DONE;
|
||||||
cs_context_ptr->client_status = nvm_error_map(ret);
|
cs_context_ptr->client_status = nvm_error_map(ret);
|
||||||
|
@ -413,7 +412,7 @@ platform_nvm_status platform_nvm_key_delete(nvm_callback *callback, const char *
|
||||||
flags.write = 1;
|
flags.write = 1;
|
||||||
ret = drv->Open(key_name, flags, cs_context_ptr->hkey);
|
ret = drv->Open(key_name, flags, cs_context_ptr->hkey);
|
||||||
|
|
||||||
if(ret < ARM_DRIVER_OK) {
|
if (ret < ARM_DRIVER_OK) {
|
||||||
tr_error("Key delete, open failed %d", (int)ret);
|
tr_error("Key delete, open failed %d", (int)ret);
|
||||||
cs_context_ptr->state = NVM_STATE_DELETE_DONE;
|
cs_context_ptr->state = NVM_STATE_DELETE_DONE;
|
||||||
cs_context_ptr->client_status = nvm_error_map(ret);
|
cs_context_ptr->client_status = nvm_error_map(ret);
|
||||||
|
@ -455,7 +454,7 @@ platform_nvm_status platform_nvm_read(nvm_callback *callback, const char *key_na
|
||||||
flags.read = 1;
|
flags.read = 1;
|
||||||
ret = drv->Open(key_name, flags, cs_context_ptr->hkey);
|
ret = drv->Open(key_name, flags, cs_context_ptr->hkey);
|
||||||
|
|
||||||
if(ret < ARM_DRIVER_OK) {
|
if (ret < ARM_DRIVER_OK) {
|
||||||
tr_error("Read failed to open handle %d", (int)ret);
|
tr_error("Read failed to open handle %d", (int)ret);
|
||||||
cs_context_ptr->state = NVM_STATE_READ_DONE;
|
cs_context_ptr->state = NVM_STATE_READ_DONE;
|
||||||
cs_context_ptr->client_status = nvm_error_map(ret);
|
cs_context_ptr->client_status = nvm_error_map(ret);
|
||||||
|
@ -485,7 +484,7 @@ platform_nvm_status platform_nvm_write(nvm_callback *callback, const char *key_n
|
||||||
}
|
}
|
||||||
cs_context_ptr->client_cb = callback;
|
cs_context_ptr->client_cb = callback;
|
||||||
cs_context_ptr->client_context = context;
|
cs_context_ptr->client_context = context;
|
||||||
cs_context_ptr->client_buf = (void*)data;
|
cs_context_ptr->client_buf = (void *)data;
|
||||||
cs_context_ptr->client_buf_len = data_len;
|
cs_context_ptr->client_buf_len = data_len;
|
||||||
cs_context_ptr->data_len = *data_len;
|
cs_context_ptr->data_len = *data_len;
|
||||||
cs_context_ptr->client_status = PLATFORM_NVM_OK;
|
cs_context_ptr->client_status = PLATFORM_NVM_OK;
|
||||||
|
@ -496,7 +495,7 @@ platform_nvm_status platform_nvm_write(nvm_callback *callback, const char *key_n
|
||||||
flags.write = 1;
|
flags.write = 1;
|
||||||
ret = drv->Open(key_name, flags, cs_context_ptr->hkey);
|
ret = drv->Open(key_name, flags, cs_context_ptr->hkey);
|
||||||
|
|
||||||
if(ret < ARM_DRIVER_OK) {
|
if (ret < ARM_DRIVER_OK) {
|
||||||
tr_error("Write failed %d", (int)ret);
|
tr_error("Write failed %d", (int)ret);
|
||||||
cs_context_ptr->state = NVM_STATE_WRITE_DONE;
|
cs_context_ptr->state = NVM_STATE_WRITE_DONE;
|
||||||
cs_context_ptr->client_status = nvm_error_map(ret);
|
cs_context_ptr->client_status = nvm_error_map(ret);
|
||||||
|
@ -532,7 +531,7 @@ platform_nvm_status platform_nvm_flush(nvm_callback *callback, void *context)
|
||||||
|
|
||||||
ret = drv->Flush();
|
ret = drv->Flush();
|
||||||
|
|
||||||
if(ret < ARM_DRIVER_OK) {
|
if (ret < ARM_DRIVER_OK) {
|
||||||
cs_context_ptr->state = NVM_STATE_FLUSH_DONE;
|
cs_context_ptr->state = NVM_STATE_FLUSH_DONE;
|
||||||
cs_context_ptr->client_status = nvm_error_map(ret);
|
cs_context_ptr->client_status = nvm_error_map(ret);
|
||||||
}
|
}
|
||||||
|
@ -547,9 +546,9 @@ static bool nvm_write_internal(cs_context_t *cf_context)
|
||||||
{
|
{
|
||||||
int32_t ret;
|
int32_t ret;
|
||||||
cf_context->state = NVM_STATE_WRITING;
|
cf_context->state = NVM_STATE_WRITING;
|
||||||
ret = drv->Write(cf_context->hkey, (const char*)cf_context->client_buf, &cf_context->data_len);
|
ret = drv->Write(cf_context->hkey, (const char *)cf_context->client_buf, &cf_context->data_len);
|
||||||
|
|
||||||
if(ret >= ARM_DRIVER_OK) {
|
if (ret >= ARM_DRIVER_OK) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
tr_error("Write failed %d", (int)ret);
|
tr_error("Write failed %d", (int)ret);
|
||||||
|
@ -561,9 +560,9 @@ static bool nvm_read_internal(cs_context_t *cf_context)
|
||||||
{
|
{
|
||||||
int32_t ret;
|
int32_t ret;
|
||||||
cf_context->state = NVM_STATE_READING;
|
cf_context->state = NVM_STATE_READING;
|
||||||
ret = drv->Read(cf_context->hkey, (void*)cf_context->client_buf, &cf_context->data_len);
|
ret = drv->Read(cf_context->hkey, (void *)cf_context->client_buf, &cf_context->data_len);
|
||||||
|
|
||||||
if(ret >= ARM_DRIVER_OK) {
|
if (ret >= ARM_DRIVER_OK) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
tr_error("Read failed %d", (int)ret);
|
tr_error("Read failed %d", (int)ret);
|
||||||
|
@ -577,7 +576,7 @@ static bool nvm_delete_internal(cs_context_t *cf_context)
|
||||||
cf_context->state = NVM_STATE_DELETING;
|
cf_context->state = NVM_STATE_DELETING;
|
||||||
ret = drv->Delete(cf_context->hkey);
|
ret = drv->Delete(cf_context->hkey);
|
||||||
|
|
||||||
if(ret >= ARM_DRIVER_OK) {
|
if (ret >= ARM_DRIVER_OK) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
tr_error("Delete failed %d", (int)ret);
|
tr_error("Delete failed %d", (int)ret);
|
||||||
|
@ -591,7 +590,7 @@ static bool nvm_close_internal(cs_context_t *cf_context)
|
||||||
cf_context->state = NVM_STATE_CLOSING;
|
cf_context->state = NVM_STATE_CLOSING;
|
||||||
ret = drv->Close(cf_context->hkey);
|
ret = drv->Close(cf_context->hkey);
|
||||||
|
|
||||||
if(ret >= ARM_DRIVER_OK) {
|
if (ret >= ARM_DRIVER_OK) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
tr_error("Close failed %d", (int)ret);
|
tr_error("Close failed %d", (int)ret);
|
||||||
|
@ -626,7 +625,7 @@ static platform_nvm_status nvm_error_map(int32_t cs_error)
|
||||||
return PLATFORM_NVM_OK;
|
return PLATFORM_NVM_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(cs_error) {
|
switch (cs_error) {
|
||||||
case ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND:
|
case ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND:
|
||||||
client_error = PLATFORM_NVM_KEY_NOT_FOUND;
|
client_error = PLATFORM_NVM_KEY_NOT_FOUND;
|
||||||
break;
|
break;
|
||||||
|
@ -641,7 +640,7 @@ static platform_nvm_status nvm_error_map(int32_t cs_error)
|
||||||
static void nvm_fsm_timer_cb(void *args)
|
static void nvm_fsm_timer_cb(void *args)
|
||||||
{
|
{
|
||||||
(void) args;
|
(void) args;
|
||||||
switch(nvm_fsm_update(cs_context_ptr)) {
|
switch (nvm_fsm_update(cs_context_ptr)) {
|
||||||
case 0:
|
case 0:
|
||||||
// Nothing processed, restart timer
|
// Nothing processed, restart timer
|
||||||
tr_debug("nvm_fsm_timer_cb not handled event in () %d", (int)cs_context_ptr->state);
|
tr_debug("nvm_fsm_timer_cb not handled event in () %d", (int)cs_context_ptr->state);
|
||||||
|
|
|
@ -22,8 +22,7 @@ uint8_t buf[100];
|
||||||
uint16_t buf_len;
|
uint16_t buf_len;
|
||||||
uint16_t data_len;
|
uint16_t data_len;
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
platform_nvm_status status;
|
platform_nvm_status status;
|
||||||
void *ctx;
|
void *ctx;
|
||||||
} test_platform_nvm_api_callback_t;
|
} test_platform_nvm_api_callback_t;
|
||||||
|
@ -187,7 +186,7 @@ bool test_cs_nvm_init_finalize()
|
||||||
}
|
}
|
||||||
|
|
||||||
// finalize NVM - OK
|
// finalize NVM - OK
|
||||||
if (!test_nvm_finalize()){
|
if (!test_nvm_finalize()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,7 +299,7 @@ bool test_cs_nvm_key_create()
|
||||||
}
|
}
|
||||||
|
|
||||||
// finalize NVM - OK
|
// finalize NVM - OK
|
||||||
if (!test_nvm_finalize()){
|
if (!test_nvm_finalize()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -341,7 +340,7 @@ bool test_cs_nvm_key_delete()
|
||||||
ret = platform_nvm_key_delete(test_nvm_callback, NULL, TEST_NS_NVM_HELPER_CONTEXT1);
|
ret = platform_nvm_key_delete(test_nvm_callback, NULL, TEST_NS_NVM_HELPER_CONTEXT1);
|
||||||
if (ret != PLATFORM_NVM_ERROR) {
|
if (ret != PLATFORM_NVM_ERROR) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configuration-store returns error in OPEN directly
|
// Configuration-store returns error in OPEN directly
|
||||||
cfstore_stub.ret_val = ARM_DRIVER_ERROR;
|
cfstore_stub.ret_val = ARM_DRIVER_ERROR;
|
||||||
|
@ -389,7 +388,7 @@ bool test_cs_nvm_key_delete()
|
||||||
ret = platform_nvm_key_delete(test_nvm_callback, key_name, TEST_NS_NVM_HELPER_CONTEXT1);
|
ret = platform_nvm_key_delete(test_nvm_callback, key_name, TEST_NS_NVM_HELPER_CONTEXT1);
|
||||||
if (ret != PLATFORM_NVM_OK) {
|
if (ret != PLATFORM_NVM_OK) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// simulate open
|
// simulate open
|
||||||
cfstore_stub.cmd_code = CFSTORE_OPCODE_OPEN;
|
cfstore_stub.cmd_code = CFSTORE_OPCODE_OPEN;
|
||||||
|
|
|
@ -16,7 +16,7 @@ static int32_t test_cfstore_close(ARM_CFSTORE_HANDLE hkey)
|
||||||
return cfstore_stub.close_ret_val;
|
return cfstore_stub.close_ret_val;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t test_cfstore_create(const char* key_name, ARM_CFSTORE_SIZE value_len, const ARM_CFSTORE_KEYDESC* kdesc, ARM_CFSTORE_HANDLE hkey)
|
static int32_t test_cfstore_create(const char *key_name, ARM_CFSTORE_SIZE value_len, const ARM_CFSTORE_KEYDESC *kdesc, ARM_CFSTORE_HANDLE hkey)
|
||||||
{
|
{
|
||||||
return cfstore_stub.ret_val;
|
return cfstore_stub.ret_val;
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ static int32_t test_cfstore_delete(ARM_CFSTORE_HANDLE hkey)
|
||||||
return cfstore_stub.delete_ret_val;
|
return cfstore_stub.delete_ret_val;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t test_cfstore_find(const char* key_name_query, const ARM_CFSTORE_HANDLE previous, ARM_CFSTORE_HANDLE next)
|
static int32_t test_cfstore_find(const char *key_name_query, const ARM_CFSTORE_HANDLE previous, ARM_CFSTORE_HANDLE next)
|
||||||
{
|
{
|
||||||
return ARM_DRIVER_OK;
|
return ARM_DRIVER_OK;
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ ARM_CFSTORE_CAPABILITIES test_cfstore_get_capabilities(void)
|
||||||
return cfstore_caps_g;
|
return cfstore_caps_g;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t test_cfstore_get_key_name(ARM_CFSTORE_HANDLE hkey, char* key_name, uint8_t *key_name_len)
|
static int32_t test_cfstore_get_key_name(ARM_CFSTORE_HANDLE hkey, char *key_name, uint8_t *key_name_len)
|
||||||
{
|
{
|
||||||
return ARM_DRIVER_OK;
|
return ARM_DRIVER_OK;
|
||||||
}
|
}
|
||||||
|
@ -64,14 +64,14 @@ ARM_DRIVER_VERSION test_cfstore_get_version(void)
|
||||||
return cfstore_driver_version_g;
|
return cfstore_driver_version_g;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t test_cfstore_initialise(ARM_CFSTORE_CALLBACK callback, void* client_context)
|
static int32_t test_cfstore_initialise(ARM_CFSTORE_CALLBACK callback, void *client_context)
|
||||||
{
|
{
|
||||||
cfstore_stub.callback = callback;
|
cfstore_stub.callback = callback;
|
||||||
cfstore_stub.client_context = client_context;
|
cfstore_stub.client_context = client_context;
|
||||||
return cfstore_stub.ret_val;
|
return cfstore_stub.ret_val;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t test_cfstore_open(const char* key_name, ARM_CFSTORE_FMODE flags, ARM_CFSTORE_HANDLE hkey)
|
static int32_t test_cfstore_open(const char *key_name, ARM_CFSTORE_FMODE flags, ARM_CFSTORE_HANDLE hkey)
|
||||||
{
|
{
|
||||||
return cfstore_stub.ret_val;
|
return cfstore_stub.ret_val;
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ static int32_t test_cfstore_power_control(ARM_POWER_STATE state)
|
||||||
return ARM_DRIVER_OK;
|
return ARM_DRIVER_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t test_cfstore_read(ARM_CFSTORE_HANDLE hkey, void* data, ARM_CFSTORE_SIZE* len)
|
static int32_t test_cfstore_read(ARM_CFSTORE_HANDLE hkey, void *data, ARM_CFSTORE_SIZE *len)
|
||||||
{
|
{
|
||||||
return cfstore_stub.read_ret_val;
|
return cfstore_stub.read_ret_val;
|
||||||
}
|
}
|
||||||
|
@ -96,30 +96,29 @@ static int32_t test_cfstore_uninitialise(void)
|
||||||
return cfstore_stub.ret_val;
|
return cfstore_stub.ret_val;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t test_cfstore_write(ARM_CFSTORE_HANDLE hkey, const char* data, ARM_CFSTORE_SIZE* len)
|
static int32_t test_cfstore_write(ARM_CFSTORE_HANDLE hkey, const char *data, ARM_CFSTORE_SIZE *len)
|
||||||
{
|
{
|
||||||
return cfstore_stub.write_ret_val;
|
return cfstore_stub.write_ret_val;
|
||||||
}
|
}
|
||||||
|
|
||||||
ARM_CFSTORE_DRIVER cfstore_driver =
|
ARM_CFSTORE_DRIVER cfstore_driver = {
|
||||||
{
|
.Close = test_cfstore_close,
|
||||||
.Close = test_cfstore_close,
|
.Create = test_cfstore_create,
|
||||||
.Create = test_cfstore_create,
|
.Delete = test_cfstore_delete,
|
||||||
.Delete= test_cfstore_delete,
|
.Find = test_cfstore_find,
|
||||||
.Find = test_cfstore_find,
|
.Flush = test_cfstore_flush,
|
||||||
.Flush = test_cfstore_flush,
|
.GetCapabilities = test_cfstore_get_capabilities,
|
||||||
.GetCapabilities = test_cfstore_get_capabilities,
|
.GetKeyName = test_cfstore_get_key_name,
|
||||||
.GetKeyName = test_cfstore_get_key_name,
|
.GetStatus = test_cfstore_get_status,
|
||||||
.GetStatus = test_cfstore_get_status,
|
.GetValueLen = test_cfstore_get_value_len,
|
||||||
.GetValueLen = test_cfstore_get_value_len,
|
.GetVersion = test_cfstore_get_version,
|
||||||
.GetVersion = test_cfstore_get_version,
|
.Initialize = test_cfstore_initialise,
|
||||||
.Initialize = test_cfstore_initialise,
|
.Open = test_cfstore_open,
|
||||||
.Open = test_cfstore_open,
|
.PowerControl = test_cfstore_power_control,
|
||||||
.PowerControl = test_cfstore_power_control,
|
.Read = test_cfstore_read,
|
||||||
.Read = test_cfstore_read,
|
.Rseek = test_cfstore_rseek,
|
||||||
.Rseek = test_cfstore_rseek,
|
.Uninitialize = test_cfstore_uninitialise,
|
||||||
.Uninitialize = test_cfstore_uninitialise,
|
.Write = test_cfstore_write,
|
||||||
.Write = test_cfstore_write,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -190,7 +190,7 @@ void debug_int(int i)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void printf_array(const void *buf , uint16_t len)
|
void printf_array(const void *buf, uint16_t len)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,32 +17,26 @@ void ns_dyn_mem_init(uint8_t *heap, uint16_t h_size, void (*passed_fptr)(heap_fa
|
||||||
|
|
||||||
void *ns_dyn_mem_alloc(int16_t alloc_size)
|
void *ns_dyn_mem_alloc(int16_t alloc_size)
|
||||||
{
|
{
|
||||||
if (nsdynmemlib_stub.returnCounter > 0)
|
if (nsdynmemlib_stub.returnCounter > 0) {
|
||||||
{
|
|
||||||
nsdynmemlib_stub.returnCounter--;
|
nsdynmemlib_stub.returnCounter--;
|
||||||
return malloc(alloc_size);
|
return malloc(alloc_size);
|
||||||
}
|
} else {
|
||||||
else
|
return (nsdynmemlib_stub.expectedPointer);
|
||||||
{
|
|
||||||
return(nsdynmemlib_stub.expectedPointer);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void *ns_dyn_mem_temporary_alloc(int16_t alloc_size)
|
void *ns_dyn_mem_temporary_alloc(int16_t alloc_size)
|
||||||
{
|
{
|
||||||
if (nsdynmemlib_stub.returnCounter > 0)
|
if (nsdynmemlib_stub.returnCounter > 0) {
|
||||||
{
|
|
||||||
nsdynmemlib_stub.returnCounter--;
|
nsdynmemlib_stub.returnCounter--;
|
||||||
return malloc(alloc_size);
|
return malloc(alloc_size);
|
||||||
}
|
} else {
|
||||||
else
|
return (nsdynmemlib_stub.expectedPointer);
|
||||||
{
|
|
||||||
return(nsdynmemlib_stub.expectedPointer);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ns_dyn_mem_free(void *block)
|
void ns_dyn_mem_free(void *block)
|
||||||
{
|
{
|
||||||
free(block);
|
free(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ extern "C" {
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t returnCounter;
|
uint8_t returnCounter;
|
||||||
void* expectedPointer;
|
void *expectedPointer;
|
||||||
} nsdynmemlib_stub_data_t;
|
} nsdynmemlib_stub_data_t;
|
||||||
|
|
||||||
extern nsdynmemlib_stub_data_t nsdynmemlib_stub;
|
extern nsdynmemlib_stub_data_t nsdynmemlib_stub;
|
||||||
|
|
|
@ -19,7 +19,8 @@ void eventOS_timeout_cancel(timeout_t *t)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_eventOS_timeout_trigger() {
|
void test_eventOS_timeout_trigger()
|
||||||
|
{
|
||||||
test_callback(test_args);
|
test_callback(test_args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,11 +43,11 @@ static osEventFlagsId_t event_flag_id;
|
||||||
|
|
||||||
#ifndef MBED_TZ_DEFAULT_ACCESS
|
#ifndef MBED_TZ_DEFAULT_ACCESS
|
||||||
#define MBED_TZ_DEFAULT_ACCESS 0
|
#define MBED_TZ_DEFAULT_ACCESS 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void event_loop_thread(void *arg);
|
static void event_loop_thread(void *arg);
|
||||||
|
|
||||||
static uint64_t event_thread_stk[MBED_CONF_NANOSTACK_HAL_EVENT_LOOP_THREAD_STACK_SIZE/8];
|
static uint64_t event_thread_stk[MBED_CONF_NANOSTACK_HAL_EVENT_LOOP_THREAD_STACK_SIZE / 8];
|
||||||
static mbed_rtos_storage_thread_t event_thread_tcb;
|
static mbed_rtos_storage_thread_t event_thread_tcb;
|
||||||
static const osThreadAttr_t event_thread_attr = {
|
static const osThreadAttr_t event_thread_attr = {
|
||||||
.name = "nanostack_event_thread",
|
.name = "nanostack_event_thread",
|
||||||
|
|
|
@ -28,10 +28,10 @@
|
||||||
|
|
||||||
static mbed_rtos_storage_mutex_t event_mutex;
|
static mbed_rtos_storage_mutex_t event_mutex;
|
||||||
static const osMutexAttr_t event_mutex_attr = {
|
static const osMutexAttr_t event_mutex_attr = {
|
||||||
.name = "nanostack_event_mutex",
|
.name = "nanostack_event_mutex",
|
||||||
.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust,
|
.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust,
|
||||||
.cb_mem = &event_mutex,
|
.cb_mem = &event_mutex,
|
||||||
.cb_size = sizeof event_mutex,
|
.cb_size = sizeof event_mutex,
|
||||||
};
|
};
|
||||||
static osMutexId_t event_mutex_id;
|
static osMutexId_t event_mutex_id;
|
||||||
static osThreadId_t event_mutex_owner_id = NULL;
|
static osThreadId_t event_mutex_owner_id = NULL;
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Define flag IGNORE_SIMULATED_NVM_STORAGE to ignore usage of simulated NVM and use
|
* Define flag IGNORE_SIMULATED_NVM_STORAGE to ignore usage of simulated NVM and use
|
||||||
* platform specific NVM instead.
|
* platform specific NVM instead.
|
||||||
*/
|
*/
|
||||||
#ifndef IGNORE_SIMULATED_NVM_STORAGE
|
#ifndef IGNORE_SIMULATED_NVM_STORAGE
|
||||||
|
@ -143,7 +143,7 @@ platform_nvm_status platform_nvm_key_create(nvm_callback *callback, const char *
|
||||||
tr_debug("platform_nvm_key_create() %s len=%d", key_name, (int)value_len);
|
tr_debug("platform_nvm_key_create() %s len=%d", key_name, (int)value_len);
|
||||||
|
|
||||||
ns_list_foreach(nvm_data_entry_t, current_entry, &nvm_entry_list) {
|
ns_list_foreach(nvm_data_entry_t, current_entry, &nvm_entry_list) {
|
||||||
if (strcmp(current_entry->key, key_name)==0) {
|
if (strcmp(current_entry->key, key_name) == 0) {
|
||||||
// resizing existing key
|
// resizing existing key
|
||||||
ns_list_remove(&nvm_entry_list, current_entry);
|
ns_list_remove(&nvm_entry_list, current_entry);
|
||||||
nvm_ram_free_entry(current_entry);
|
nvm_ram_free_entry(current_entry);
|
||||||
|
@ -182,7 +182,7 @@ platform_nvm_status platform_nvm_key_delete(nvm_callback *callback, const char *
|
||||||
tr_debug("platform_nvm_key_delete() %s", key_name);
|
tr_debug("platform_nvm_key_delete() %s", key_name);
|
||||||
|
|
||||||
ns_list_foreach(nvm_data_entry_t, current_entry, &nvm_entry_list) {
|
ns_list_foreach(nvm_data_entry_t, current_entry, &nvm_entry_list) {
|
||||||
if (strcmp(current_entry->key, key_name)==0) {
|
if (strcmp(current_entry->key, key_name) == 0) {
|
||||||
client_status = PLATFORM_NVM_OK;
|
client_status = PLATFORM_NVM_OK;
|
||||||
ns_list_remove(&nvm_entry_list, current_entry);
|
ns_list_remove(&nvm_entry_list, current_entry);
|
||||||
nvm_ram_free_entry(current_entry);
|
nvm_ram_free_entry(current_entry);
|
||||||
|
@ -199,7 +199,7 @@ platform_nvm_status platform_nvm_write(nvm_callback *callback, const char *key_n
|
||||||
tr_debug("platform_nvm_write() %s len=%d", key_name, (int)*data_len);
|
tr_debug("platform_nvm_write() %s len=%d", key_name, (int)*data_len);
|
||||||
|
|
||||||
ns_list_foreach(nvm_data_entry_t, current_entry, &nvm_entry_list) {
|
ns_list_foreach(nvm_data_entry_t, current_entry, &nvm_entry_list) {
|
||||||
if (strcmp(current_entry->key, key_name)==0) {
|
if (strcmp(current_entry->key, key_name) == 0) {
|
||||||
if (current_entry->data_len >= *data_len) {
|
if (current_entry->data_len >= *data_len) {
|
||||||
memcpy(current_entry->data, data, *data_len);
|
memcpy(current_entry->data, data, *data_len);
|
||||||
} else {
|
} else {
|
||||||
|
@ -211,7 +211,7 @@ platform_nvm_status platform_nvm_write(nvm_callback *callback, const char *key_n
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return create_client_request(callback, context, (void*)data, data_len, client_status);
|
return create_client_request(callback, context, (void *)data, data_len, client_status);
|
||||||
}
|
}
|
||||||
|
|
||||||
platform_nvm_status platform_nvm_read(nvm_callback *callback, const char *key_name, void *buf, uint16_t *buf_len, void *context)
|
platform_nvm_status platform_nvm_read(nvm_callback *callback, const char *key_name, void *buf, uint16_t *buf_len, void *context)
|
||||||
|
@ -220,7 +220,7 @@ platform_nvm_status platform_nvm_read(nvm_callback *callback, const char *key_na
|
||||||
tr_debug("platform_nvm_read() %s len=%d", key_name, (int)*buf_len);
|
tr_debug("platform_nvm_read() %s len=%d", key_name, (int)*buf_len);
|
||||||
|
|
||||||
ns_list_foreach(nvm_data_entry_t, current_entry, &nvm_entry_list) {
|
ns_list_foreach(nvm_data_entry_t, current_entry, &nvm_entry_list) {
|
||||||
if (strcmp(current_entry->key, key_name)==0) {
|
if (strcmp(current_entry->key, key_name) == 0) {
|
||||||
if (*buf_len >= current_entry->data_len) {
|
if (*buf_len >= current_entry->data_len) {
|
||||||
memcpy(buf, current_entry->data, current_entry->data_len);
|
memcpy(buf, current_entry->data, current_entry->data_len);
|
||||||
*buf_len = current_entry->data_len;
|
*buf_len = current_entry->data_len;
|
||||||
|
|
|
@ -61,15 +61,18 @@ enum socket_mode_t {
|
||||||
class NanostackSocket {
|
class NanostackSocket {
|
||||||
public:
|
public:
|
||||||
static void socket_callback(void *cb);
|
static void socket_callback(void *cb);
|
||||||
static void* operator new(std::size_t sz);
|
static void *operator new (std::size_t sz);
|
||||||
static void operator delete(void* ptr);
|
static void operator delete (void *ptr);
|
||||||
|
|
||||||
NanostackSocket(int8_t protocol);
|
NanostackSocket(int8_t protocol);
|
||||||
~NanostackSocket(void);
|
~NanostackSocket(void);
|
||||||
bool open(void);
|
bool open(void);
|
||||||
int accept(NanostackSocket *accepted_socket, ns_address_t *addr);
|
int accept(NanostackSocket *accepted_socket, ns_address_t *addr);
|
||||||
void close(void);
|
void close(void);
|
||||||
bool closed(void) {return SOCKET_MODE_CLOSED == mode;}
|
bool closed(void)
|
||||||
|
{
|
||||||
|
return SOCKET_MODE_CLOSED == mode;
|
||||||
|
}
|
||||||
bool is_connecting(void);
|
bool is_connecting(void);
|
||||||
void set_connecting(ns_address_t *addr);
|
void set_connecting(ns_address_t *addr);
|
||||||
bool is_connected(void);
|
bool is_connected(void);
|
||||||
|
@ -101,21 +104,26 @@ private:
|
||||||
socket_mode_t mode;
|
socket_mode_t mode;
|
||||||
};
|
};
|
||||||
|
|
||||||
static NanostackSocket * socket_tbl[NS_INTERFACE_SOCKETS_MAX];
|
static NanostackSocket *socket_tbl[NS_INTERFACE_SOCKETS_MAX];
|
||||||
|
|
||||||
nsapi_error_t map_mesh_error(mesh_error_t err)
|
nsapi_error_t map_mesh_error(mesh_error_t err)
|
||||||
{
|
{
|
||||||
switch (err) {
|
switch (err) {
|
||||||
case MESH_ERROR_NONE: return 0;
|
case MESH_ERROR_NONE:
|
||||||
case MESH_ERROR_MEMORY: return NSAPI_ERROR_NO_MEMORY;
|
return 0;
|
||||||
case MESH_ERROR_PARAM: return NSAPI_ERROR_UNSUPPORTED;
|
case MESH_ERROR_MEMORY:
|
||||||
case MESH_ERROR_STATE: return NSAPI_ERROR_DEVICE_ERROR;
|
return NSAPI_ERROR_NO_MEMORY;
|
||||||
default: return NSAPI_ERROR_DEVICE_ERROR;
|
case MESH_ERROR_PARAM:
|
||||||
|
return NSAPI_ERROR_UNSUPPORTED;
|
||||||
|
case MESH_ERROR_STATE:
|
||||||
|
return NSAPI_ERROR_DEVICE_ERROR;
|
||||||
|
default:
|
||||||
|
return NSAPI_ERROR_DEVICE_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void convert_mbed_addr_to_ns(ns_address_t *ns_addr,
|
static void convert_mbed_addr_to_ns(ns_address_t *ns_addr,
|
||||||
const SocketAddress *s_addr)
|
const SocketAddress *s_addr)
|
||||||
{
|
{
|
||||||
ns_addr->type = ADDRESS_IPV6;
|
ns_addr->type = ADDRESS_IPV6;
|
||||||
ns_addr->identifier = s_addr->get_port();
|
ns_addr->identifier = s_addr->get_port();
|
||||||
|
@ -142,10 +150,12 @@ static int8_t find_interface_by_address(const uint8_t target_addr[16])
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* NanostackSocket::operator new(std::size_t sz) {
|
void *NanostackSocket::operator new (std::size_t sz)
|
||||||
|
{
|
||||||
return MALLOC(sz);
|
return MALLOC(sz);
|
||||||
}
|
}
|
||||||
void NanostackSocket::operator delete(void* ptr) {
|
void NanostackSocket::operator delete (void *ptr)
|
||||||
|
{
|
||||||
FREE(ptr);
|
FREE(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,7 +306,8 @@ void NanostackSocket::signal_event()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NanostackSocket::socket_callback(void *cb) {
|
void NanostackSocket::socket_callback(void *cb)
|
||||||
|
{
|
||||||
nanostack_assert_locked();
|
nanostack_assert_locked();
|
||||||
|
|
||||||
socket_callback_t *sock_cb = (socket_callback_t *) cb;
|
socket_callback_t *sock_cb = (socket_callback_t *) cb;
|
||||||
|
@ -304,7 +315,7 @@ void NanostackSocket::socket_callback(void *cb) {
|
||||||
MBED_ASSERT(socket != NULL);
|
MBED_ASSERT(socket != NULL);
|
||||||
|
|
||||||
tr_debug("socket_callback() sock=%d, event=%d, interface=%d, data len=%d",
|
tr_debug("socket_callback() sock=%d, event=%d, interface=%d, data len=%d",
|
||||||
sock_cb->socket_id, sock_cb->event_type, sock_cb->interface_id, sock_cb->d_len);
|
sock_cb->socket_id, sock_cb->event_type, sock_cb->interface_id, sock_cb->d_len);
|
||||||
|
|
||||||
switch (sock_cb->event_type) {
|
switch (sock_cb->event_type) {
|
||||||
case SOCKET_DATA:
|
case SOCKET_DATA:
|
||||||
|
@ -506,7 +517,7 @@ Nanostack::call_in_callback_cb_t Nanostack::get_call_in_callback()
|
||||||
return cb;
|
return cb;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * Nanostack::get_ip_address()
|
const char *Nanostack::get_ip_address()
|
||||||
{
|
{
|
||||||
NanostackLockGuard lock;
|
NanostackLockGuard lock;
|
||||||
|
|
||||||
|
@ -539,11 +550,11 @@ nsapi_error_t Nanostack::socket_open(void **handle, nsapi_protocol_t protocol)
|
||||||
MBED_ASSERT(false);
|
MBED_ASSERT(false);
|
||||||
return NSAPI_ERROR_UNSUPPORTED;
|
return NSAPI_ERROR_UNSUPPORTED;
|
||||||
}
|
}
|
||||||
*handle = (void*)NULL;
|
*handle = (void *)NULL;
|
||||||
|
|
||||||
NanostackLockGuard lock;
|
NanostackLockGuard lock;
|
||||||
|
|
||||||
NanostackSocket * socket = new NanostackSocket(ns_proto);
|
NanostackSocket *socket = new NanostackSocket(ns_proto);
|
||||||
if (socket == NULL) {
|
if (socket == NULL) {
|
||||||
tr_debug("socket_open() ret=%i", NSAPI_ERROR_NO_MEMORY);
|
tr_debug("socket_open() ret=%i", NSAPI_ERROR_NO_MEMORY);
|
||||||
return NSAPI_ERROR_NO_MEMORY;
|
return NSAPI_ERROR_NO_MEMORY;
|
||||||
|
@ -553,7 +564,7 @@ nsapi_error_t Nanostack::socket_open(void **handle, nsapi_protocol_t protocol)
|
||||||
tr_debug("socket_open() ret=%i", NSAPI_ERROR_NO_MEMORY);
|
tr_debug("socket_open() ret=%i", NSAPI_ERROR_NO_MEMORY);
|
||||||
return NSAPI_ERROR_NO_MEMORY;
|
return NSAPI_ERROR_NO_MEMORY;
|
||||||
}
|
}
|
||||||
*handle = (void*)socket;
|
*handle = (void *)socket;
|
||||||
|
|
||||||
tr_debug("socket_open() socket=%p, sock_id=%d, ret=0", socket, socket->socket_id);
|
tr_debug("socket_open() socket=%p, sock_id=%d, ret=0", socket, socket->socket_id);
|
||||||
|
|
||||||
|
@ -564,7 +575,7 @@ nsapi_error_t Nanostack::socket_close(void *handle)
|
||||||
{
|
{
|
||||||
NanostackLockGuard lock;
|
NanostackLockGuard lock;
|
||||||
// Validate parameters
|
// Validate parameters
|
||||||
NanostackSocket * socket = static_cast<NanostackSocket *>(handle);
|
NanostackSocket *socket = static_cast<NanostackSocket *>(handle);
|
||||||
if (NULL == handle) {
|
if (NULL == handle) {
|
||||||
MBED_ASSERT(false);
|
MBED_ASSERT(false);
|
||||||
return NSAPI_ERROR_NO_SOCKET;
|
return NSAPI_ERROR_NO_SOCKET;
|
||||||
|
@ -580,7 +591,7 @@ nsapi_error_t Nanostack::socket_close(void *handle)
|
||||||
nsapi_size_or_error_t Nanostack::do_sendto(void *handle, const ns_address_t *address, const void *data, nsapi_size_t size)
|
nsapi_size_or_error_t Nanostack::do_sendto(void *handle, const ns_address_t *address, const void *data, nsapi_size_t size)
|
||||||
{
|
{
|
||||||
// Validate parameters
|
// Validate parameters
|
||||||
NanostackSocket * socket = static_cast<NanostackSocket *>(handle);
|
NanostackSocket *socket = static_cast<NanostackSocket *>(handle);
|
||||||
if (handle == NULL) {
|
if (handle == NULL) {
|
||||||
MBED_ASSERT(false);
|
MBED_ASSERT(false);
|
||||||
return NSAPI_ERROR_NO_SOCKET;
|
return NSAPI_ERROR_NO_SOCKET;
|
||||||
|
@ -604,7 +615,7 @@ nsapi_size_or_error_t Nanostack::do_sendto(void *handle, const ns_address_t *add
|
||||||
int retcode;
|
int retcode;
|
||||||
#if 0
|
#if 0
|
||||||
retcode = ::socket_sendto(socket->socket_id, address,
|
retcode = ::socket_sendto(socket->socket_id, address,
|
||||||
data, size);
|
data, size);
|
||||||
#else
|
#else
|
||||||
// Use sendmsg purely to get the new return style
|
// Use sendmsg purely to get the new return style
|
||||||
// of returning data written rather than 0 on success,
|
// of returning data written rather than 0 on success,
|
||||||
|
@ -616,7 +627,7 @@ nsapi_size_or_error_t Nanostack::do_sendto(void *handle, const ns_address_t *add
|
||||||
iov.iov_base = const_cast<void *>(data);
|
iov.iov_base = const_cast<void *>(data);
|
||||||
iov.iov_len = size;
|
iov.iov_len = size;
|
||||||
msg.msg_name = const_cast<ns_address_t *>(address);
|
msg.msg_name = const_cast<ns_address_t *>(address);
|
||||||
msg.msg_namelen = address ? sizeof *address : 0;
|
msg.msg_namelen = address ? sizeof * address : 0;
|
||||||
msg.msg_iov = &iov;
|
msg.msg_iov = &iov;
|
||||||
msg.msg_iovlen = 1;
|
msg.msg_iovlen = 1;
|
||||||
msg.msg_control = NULL;
|
msg.msg_control = NULL;
|
||||||
|
@ -771,7 +782,7 @@ nsapi_error_t Nanostack::setsockopt(void *handle, int level, int optname, const
|
||||||
|
|
||||||
/* Check address types are IPv6, or unspecified for interface */
|
/* Check address types are IPv6, or unspecified for interface */
|
||||||
if (imr->imr_multiaddr.version != NSAPI_IPv6 ||
|
if (imr->imr_multiaddr.version != NSAPI_IPv6 ||
|
||||||
(imr->imr_interface.version != NSAPI_UNSPEC && imr->imr_interface.version != NSAPI_IPv6)) {
|
(imr->imr_interface.version != NSAPI_UNSPEC && imr->imr_interface.version != NSAPI_IPv6)) {
|
||||||
return NSAPI_ERROR_PARAMETER;
|
return NSAPI_ERROR_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -841,7 +852,7 @@ nsapi_error_t Nanostack::socket_listen(void *handle, int backlog)
|
||||||
|
|
||||||
NanostackLockGuard lock;
|
NanostackLockGuard lock;
|
||||||
|
|
||||||
if(::socket_listen(socket->socket_id, backlog) < 0) {
|
if (::socket_listen(socket->socket_id, backlog) < 0) {
|
||||||
ret = NSAPI_ERROR_PARAMETER;
|
ret = NSAPI_ERROR_PARAMETER;
|
||||||
} else {
|
} else {
|
||||||
socket->set_listening();
|
socket->set_listening();
|
||||||
|
@ -904,7 +915,7 @@ out:
|
||||||
|
|
||||||
nsapi_error_t Nanostack::socket_accept(void *server, void **handle, SocketAddress *address)
|
nsapi_error_t Nanostack::socket_accept(void *server, void **handle, SocketAddress *address)
|
||||||
{
|
{
|
||||||
NanostackSocket * socket = static_cast<NanostackSocket *>(server);
|
NanostackSocket *socket = static_cast<NanostackSocket *>(server);
|
||||||
NanostackSocket *accepted_sock = NULL;
|
NanostackSocket *accepted_sock = NULL;
|
||||||
nsapi_error_t ret;
|
nsapi_error_t ret;
|
||||||
|
|
||||||
|
@ -965,7 +976,7 @@ nsapi_size_or_error_t Nanostack::socket_recv(void *handle, void *data, nsapi_siz
|
||||||
void Nanostack::socket_attach(void *handle, void (*callback)(void *), void *id)
|
void Nanostack::socket_attach(void *handle, void (*callback)(void *), void *id)
|
||||||
{
|
{
|
||||||
// Validate parameters
|
// Validate parameters
|
||||||
NanostackSocket * socket = static_cast<NanostackSocket *>(handle);
|
NanostackSocket *socket = static_cast<NanostackSocket *>(handle);
|
||||||
if (handle == NULL) {
|
if (handle == NULL) {
|
||||||
MBED_ASSERT(false);
|
MBED_ASSERT(false);
|
||||||
return;
|
return;
|
||||||
|
@ -979,7 +990,8 @@ void Nanostack::socket_attach(void *handle, void (*callback)(void *), void *id)
|
||||||
tr_debug("socket_attach(socket=%p) sock_id=%d", socket, socket->socket_id);
|
tr_debug("socket_attach(socket=%p) sock_id=%d", socket, socket->socket_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
Nanostack &Nanostack::get_instance() {
|
Nanostack &Nanostack::get_instance()
|
||||||
|
{
|
||||||
static Nanostack nanostack;
|
static Nanostack nanostack;
|
||||||
return nanostack;
|
return nanostack;
|
||||||
}
|
}
|
||||||
|
@ -989,7 +1001,8 @@ Nanostack &Nanostack::get_instance() {
|
||||||
#define NANOSTACK 0x99119911
|
#define NANOSTACK 0x99119911
|
||||||
#if MBED_CONF_NSAPI_DEFAULT_STACK == NANOSTACK
|
#if MBED_CONF_NSAPI_DEFAULT_STACK == NANOSTACK
|
||||||
#undef NANOSTACK
|
#undef NANOSTACK
|
||||||
OnboardNetworkStack &OnboardNetworkStack::get_default_instance() {
|
OnboardNetworkStack &OnboardNetworkStack::get_default_instance()
|
||||||
|
{
|
||||||
return Nanostack::get_instance();
|
return Nanostack::get_instance();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -27,17 +27,19 @@
|
||||||
|
|
||||||
class NanostackLockGuard {
|
class NanostackLockGuard {
|
||||||
public:
|
public:
|
||||||
NanostackLockGuard() {
|
NanostackLockGuard()
|
||||||
|
{
|
||||||
eventOS_scheduler_mutex_wait();
|
eventOS_scheduler_mutex_wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
~NanostackLockGuard() {
|
~NanostackLockGuard()
|
||||||
|
{
|
||||||
eventOS_scheduler_mutex_release();
|
eventOS_scheduler_mutex_release();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NanostackLockGuard(const NanostackLockGuard&);
|
NanostackLockGuard(const NanostackLockGuard &);
|
||||||
NanostackLockGuard& operator=(const NanostackLockGuard&);
|
NanostackLockGuard &operator=(const NanostackLockGuard &);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* NANOSTACK_LOCK_GUARD_H_ */
|
#endif /* NANOSTACK_LOCK_GUARD_H_ */
|
||||||
|
|
|
@ -48,12 +48,18 @@ public:
|
||||||
* @return Device driver ID or a negative error
|
* @return Device driver ID or a negative error
|
||||||
* code on failure
|
* code on failure
|
||||||
*/
|
*/
|
||||||
virtual int8_t phy_register() { return rf_register();}
|
virtual int8_t phy_register()
|
||||||
|
{
|
||||||
|
return rf_register();
|
||||||
|
}
|
||||||
|
|
||||||
/** Unregister this physical interface
|
/** Unregister this physical interface
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
virtual void unregister() { rf_unregister(); }
|
virtual void unregister()
|
||||||
|
{
|
||||||
|
rf_unregister();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* NANOSTACK_RF_PHY_H_ */
|
#endif /* NANOSTACK_RF_PHY_H_ */
|
||||||
|
|
|
@ -78,14 +78,16 @@ static timeout_t *eventOS_timeout_at_(void (*callback)(void *), void *arg, uint3
|
||||||
.data_ptr = timeout
|
.data_ptr = timeout
|
||||||
};
|
};
|
||||||
|
|
||||||
if (period)
|
if (period) {
|
||||||
storage = eventOS_event_timer_request_every(&event, period);
|
storage = eventOS_event_timer_request_every(&event, period);
|
||||||
else
|
} else {
|
||||||
storage = eventOS_event_timer_request_at(&event, at);
|
storage = eventOS_event_timer_request_at(&event, at);
|
||||||
|
}
|
||||||
|
|
||||||
timeout->event = storage;
|
timeout->event = storage;
|
||||||
if (storage)
|
if (storage) {
|
||||||
return timeout;
|
return timeout;
|
||||||
|
}
|
||||||
FAIL:
|
FAIL:
|
||||||
ns_dyn_mem_free(timeout);
|
ns_dyn_mem_free(timeout);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -93,7 +95,7 @@ FAIL:
|
||||||
|
|
||||||
timeout_t *eventOS_timeout_ms(void (*callback)(void *), uint32_t ms, void *arg)
|
timeout_t *eventOS_timeout_ms(void (*callback)(void *), uint32_t ms, void *arg)
|
||||||
{
|
{
|
||||||
return eventOS_timeout_at_(callback, arg, eventOS_event_timer_ms_to_ticks(ms)+eventOS_event_timer_ticks(), 0);
|
return eventOS_timeout_at_(callback, arg, eventOS_event_timer_ms_to_ticks(ms) + eventOS_event_timer_ticks(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
timeout_t *eventOS_timeout_every_ms(void (*callback)(void *), uint32_t every, void *arg)
|
timeout_t *eventOS_timeout_every_ms(void (*callback)(void *), uint32_t every, void *arg)
|
||||||
|
@ -103,8 +105,9 @@ timeout_t *eventOS_timeout_every_ms(void (*callback)(void *), uint32_t every, vo
|
||||||
|
|
||||||
void eventOS_timeout_cancel(timeout_t *t)
|
void eventOS_timeout_cancel(timeout_t *t)
|
||||||
{
|
{
|
||||||
if (!t)
|
if (!t) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
eventOS_cancel(t->event);
|
eventOS_cancel(t->event);
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ static int8_t platform_tick_timer_start(uint32_t period_ms);
|
||||||
/* Implement platform tick timer using eventOS timer */
|
/* Implement platform tick timer using eventOS timer */
|
||||||
// platform tick timer callback function
|
// platform tick timer callback function
|
||||||
static void (*tick_timer_callback)(void);
|
static void (*tick_timer_callback)(void);
|
||||||
static int8_t tick_timer_id = -1; // eventOS timer id for tick timer
|
static int8_t tick_timer_id = -1; // eventOS timer id for tick timer
|
||||||
|
|
||||||
// EventOS timer callback function
|
// EventOS timer callback function
|
||||||
static void tick_timer_eventOS_callback(int8_t timer_id, uint16_t slots)
|
static void tick_timer_eventOS_callback(int8_t timer_id, uint16_t slots)
|
||||||
|
@ -299,7 +299,7 @@ int8_t eventOS_event_timer_request(uint8_t event_id, uint8_t event_type, int8_t
|
||||||
platform_enter_critical();
|
platform_enter_critical();
|
||||||
arm_event_storage_t *ret = eventOS_event_timer_request_at_(&event, timer_sys_ticks + time, 0);
|
arm_event_storage_t *ret = eventOS_event_timer_request_at_(&event, timer_sys_ticks + time, 0);
|
||||||
platform_exit_critical();
|
platform_exit_critical();
|
||||||
return ret?0:-1;
|
return ret ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t eventOS_event_timer_cancel(uint8_t event_id, int8_t tasklet_id)
|
int8_t eventOS_event_timer_cancel(uint8_t event_id, int8_t tasklet_id)
|
||||||
|
|
|
@ -20,32 +20,69 @@
|
||||||
#ifdef CELLULAR_DEVICE
|
#ifdef CELLULAR_DEVICE
|
||||||
using namespace mbed;
|
using namespace mbed;
|
||||||
MBED_DEPRECATED_SINCE("mbed-os-5.9", "This API will be deprecated, use CellularBase::get_default_instance() instead.")
|
MBED_DEPRECATED_SINCE("mbed-os-5.9", "This API will be deprecated, use CellularBase::get_default_instance() instead.")
|
||||||
class OnboardCellularInterface : public CellularBase
|
class OnboardCellularInterface : public CellularBase {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
OnboardCellularInterface() {
|
OnboardCellularInterface()
|
||||||
|
{
|
||||||
context = CellularContext::get_default_instance();
|
context = CellularContext::get_default_instance();
|
||||||
MBED_ASSERT(context != NULL);
|
MBED_ASSERT(context != NULL);
|
||||||
}
|
}
|
||||||
public: // from NetworkInterface
|
public: // from NetworkInterface
|
||||||
virtual nsapi_error_t set_blocking(bool blocking) {return context->set_blocking(blocking);}
|
virtual nsapi_error_t set_blocking(bool blocking)
|
||||||
virtual NetworkStack *get_stack() {return context->get_stack();}
|
{
|
||||||
virtual const char *get_ip_address() {return context->get_ip_address();}
|
return context->set_blocking(blocking);
|
||||||
virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb) {context->attach(status_cb);}
|
}
|
||||||
virtual nsapi_error_t connect() {return context->connect();}
|
virtual NetworkStack *get_stack()
|
||||||
virtual nsapi_error_t disconnect() {return context->disconnect();}
|
{
|
||||||
|
return context->get_stack();
|
||||||
|
}
|
||||||
|
virtual const char *get_ip_address()
|
||||||
|
{
|
||||||
|
return context->get_ip_address();
|
||||||
|
}
|
||||||
|
virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb)
|
||||||
|
{
|
||||||
|
context->attach(status_cb);
|
||||||
|
}
|
||||||
|
virtual nsapi_error_t connect()
|
||||||
|
{
|
||||||
|
return context->connect();
|
||||||
|
}
|
||||||
|
virtual nsapi_error_t disconnect()
|
||||||
|
{
|
||||||
|
return context->disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
// from CellularBase
|
// from CellularBase
|
||||||
virtual void set_plmn(const char *plmn) {context->set_plmn(plmn);}
|
virtual void set_plmn(const char *plmn)
|
||||||
virtual void set_sim_pin(const char *sim_pin) {context->set_sim_pin(sim_pin);}
|
{
|
||||||
|
context->set_plmn(plmn);
|
||||||
|
}
|
||||||
|
virtual void set_sim_pin(const char *sim_pin)
|
||||||
|
{
|
||||||
|
context->set_sim_pin(sim_pin);
|
||||||
|
}
|
||||||
virtual nsapi_error_t connect(const char *sim_pin, const char *apn = 0, const char *uname = 0,
|
virtual nsapi_error_t connect(const char *sim_pin, const char *apn = 0, const char *uname = 0,
|
||||||
const char *pwd = 0)
|
const char *pwd = 0)
|
||||||
{return context->connect(sim_pin, apn, uname, pwd);}
|
{
|
||||||
|
return context->connect(sim_pin, apn, uname, pwd);
|
||||||
|
}
|
||||||
virtual void set_credentials(const char *apn, const char *uname = 0, const char *pwd = 0)
|
virtual void set_credentials(const char *apn, const char *uname = 0, const char *pwd = 0)
|
||||||
{context->set_credentials(apn, uname, pwd);}
|
{
|
||||||
virtual const char *get_netmask() {return context->get_netmask();}
|
context->set_credentials(apn, uname, pwd);
|
||||||
virtual const char *get_gateway() {return context->get_gateway();}
|
}
|
||||||
virtual bool is_connected() {return context->is_connected();}
|
virtual const char *get_netmask()
|
||||||
|
{
|
||||||
|
return context->get_netmask();
|
||||||
|
}
|
||||||
|
virtual const char *get_gateway()
|
||||||
|
{
|
||||||
|
return context->get_gateway();
|
||||||
|
}
|
||||||
|
virtual bool is_connected()
|
||||||
|
{
|
||||||
|
return context->is_connected();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CellularContext *context;
|
CellularContext *context;
|
||||||
|
|
|
@ -253,16 +253,16 @@ void test_get_erase_value()
|
||||||
utest_printf("\nstart_address=0x%016" PRIx64, start_address);
|
utest_printf("\nstart_address=0x%016" PRIx64, start_address);
|
||||||
|
|
||||||
// Allocate buffer for read test data
|
// Allocate buffer for read test data
|
||||||
uint8_t *data_buf = (uint8_t*)malloc(data_buf_size);
|
uint8_t *data_buf = (uint8_t *)malloc(data_buf_size);
|
||||||
TEST_ASSERT_NOT_NULL(data_buf);
|
TEST_ASSERT_NOT_NULL(data_buf);
|
||||||
|
|
||||||
// Write random data to selected region to make sure data is not accidentally set to "erased" value.
|
// Write random data to selected region to make sure data is not accidentally set to "erased" value.
|
||||||
// With this pre-write, the test case will fail even if block_device->erase() is broken.
|
// With this pre-write, the test case will fail even if block_device->erase() is broken.
|
||||||
for (bd_size_t i=0; i<data_buf_size; i++) {
|
for (bd_size_t i = 0; i < data_buf_size; i++) {
|
||||||
data_buf[i] = (uint8_t) rand();
|
data_buf[i] = (uint8_t) rand();
|
||||||
}
|
}
|
||||||
utest_printf("\nwriting given memory region");
|
utest_printf("\nwriting given memory region");
|
||||||
err = block_device->program((const void*)data_buf, start_address, data_buf_size);
|
err = block_device->program((const void *)data_buf, start_address, data_buf_size);
|
||||||
TEST_ASSERT_EQUAL(0, err);
|
TEST_ASSERT_EQUAL(0, err);
|
||||||
|
|
||||||
// Erase given memory region
|
// Erase given memory region
|
||||||
|
@ -272,12 +272,12 @@ void test_get_erase_value()
|
||||||
|
|
||||||
// Read erased memory region
|
// Read erased memory region
|
||||||
utest_printf("\nreading erased memory region");
|
utest_printf("\nreading erased memory region");
|
||||||
err = block_device->read((void*)data_buf, start_address, data_buf_size);
|
err = block_device->read((void *)data_buf, start_address, data_buf_size);
|
||||||
TEST_ASSERT_EQUAL(0, err);
|
TEST_ASSERT_EQUAL(0, err);
|
||||||
|
|
||||||
// Verify erased memory region
|
// Verify erased memory region
|
||||||
utest_printf("\nverifying erased memory region");
|
utest_printf("\nverifying erased memory region");
|
||||||
for (bd_size_t i=0; i<data_buf_size; i++) {
|
for (bd_size_t i = 0; i < data_buf_size; i++) {
|
||||||
TEST_ASSERT_EQUAL(erase_value, data_buf[i]);
|
TEST_ASSERT_EQUAL(erase_value, data_buf[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,8 +323,8 @@ void test_contiguous_erase_write_read()
|
||||||
write_read_buf_size = 10000;
|
write_read_buf_size = 10000;
|
||||||
}
|
}
|
||||||
// 2 program_size blocks is minimum for contiguous write/read test
|
// 2 program_size blocks is minimum for contiguous write/read test
|
||||||
if (write_read_buf_size < program_size*2) {
|
if (write_read_buf_size < program_size * 2) {
|
||||||
write_read_buf_size = program_size*2; // going over 10k
|
write_read_buf_size = program_size * 2; // going over 10k
|
||||||
}
|
}
|
||||||
bd_size_t contiguous_write_read_blocks_per_region = write_read_buf_size / program_size; // 2 is minimum to test contiguous write
|
bd_size_t contiguous_write_read_blocks_per_region = write_read_buf_size / program_size; // 2 is minimum to test contiguous write
|
||||||
write_read_buf_size = contiguous_write_read_blocks_per_region * program_size;
|
write_read_buf_size = contiguous_write_read_blocks_per_region * program_size;
|
||||||
|
@ -352,7 +352,7 @@ void test_contiguous_erase_write_read()
|
||||||
utest_printf("\nstop_address=0x%016" PRIx64, stop_address);
|
utest_printf("\nstop_address=0x%016" PRIx64, stop_address);
|
||||||
|
|
||||||
// Allocate write/read buffer
|
// Allocate write/read buffer
|
||||||
uint8_t *write_read_buf = (uint8_t*)malloc(write_read_buf_size);
|
uint8_t *write_read_buf = (uint8_t *)malloc(write_read_buf_size);
|
||||||
if (write_read_buf == NULL) {
|
if (write_read_buf == NULL) {
|
||||||
block_device->deinit();
|
block_device->deinit();
|
||||||
TEST_SKIP_MESSAGE("\nnot enough memory for test");
|
TEST_SKIP_MESSAGE("\nnot enough memory for test");
|
||||||
|
@ -361,12 +361,12 @@ void test_contiguous_erase_write_read()
|
||||||
|
|
||||||
// Pre-fill the to-be-erased region. By pre-filling the region,
|
// Pre-fill the to-be-erased region. By pre-filling the region,
|
||||||
// we can be sure the test will not pass if the erase doesn't work.
|
// we can be sure the test will not pass if the erase doesn't work.
|
||||||
for (bd_size_t offset=0; start_address+offset < stop_address; offset+=write_read_buf_size) {
|
for (bd_size_t offset = 0; start_address + offset < stop_address; offset += write_read_buf_size) {
|
||||||
for (size_t i=0; i<write_read_buf_size; i++) {
|
for (size_t i = 0; i < write_read_buf_size; i++) {
|
||||||
write_read_buf[i] = (uint8_t)rand();
|
write_read_buf[i] = (uint8_t)rand();
|
||||||
}
|
}
|
||||||
utest_printf("\npre-filling memory, from 0x%" PRIx64 " of size 0x%" PRIx64, start_address+offset, write_read_buf_size);
|
utest_printf("\npre-filling memory, from 0x%" PRIx64 " of size 0x%" PRIx64, start_address + offset, write_read_buf_size);
|
||||||
err = block_device->program((const void*)write_read_buf, start_address+offset, write_read_buf_size);
|
err = block_device->program((const void *)write_read_buf, start_address + offset, write_read_buf_size);
|
||||||
TEST_ASSERT_EQUAL(0, err);
|
TEST_ASSERT_EQUAL(0, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -377,20 +377,20 @@ void test_contiguous_erase_write_read()
|
||||||
|
|
||||||
// Loop through all write/read regions
|
// Loop through all write/read regions
|
||||||
int region = 0;
|
int region = 0;
|
||||||
for (; start_address < stop_address; start_address+=write_read_buf_size) {
|
for (; start_address < stop_address; start_address += write_read_buf_size) {
|
||||||
utest_printf("\n\nregion #%d start_address=0x%016" PRIx64, region++, start_address);
|
utest_printf("\n\nregion #%d start_address=0x%016" PRIx64, region++, start_address);
|
||||||
|
|
||||||
// Generate test data
|
// Generate test data
|
||||||
unsigned int seed = rand();
|
unsigned int seed = rand();
|
||||||
utest_printf("\ngenerating test data, seed=%u", seed);
|
utest_printf("\ngenerating test data, seed=%u", seed);
|
||||||
srand(seed);
|
srand(seed);
|
||||||
for (size_t i=0; i<write_read_buf_size; i++) {
|
for (size_t i = 0; i < write_read_buf_size; i++) {
|
||||||
write_read_buf[i] = (uint8_t)rand();
|
write_read_buf[i] = (uint8_t)rand();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write test data
|
// Write test data
|
||||||
utest_printf("\nwriting test data");
|
utest_printf("\nwriting test data");
|
||||||
err = block_device->program((const void*)write_read_buf, start_address, write_read_buf_size);
|
err = block_device->program((const void *)write_read_buf, start_address, write_read_buf_size);
|
||||||
TEST_ASSERT_EQUAL(0, err);
|
TEST_ASSERT_EQUAL(0, err);
|
||||||
|
|
||||||
// Read test data
|
// Read test data
|
||||||
|
@ -402,11 +402,11 @@ void test_contiguous_erase_write_read()
|
||||||
// Verify read data
|
// Verify read data
|
||||||
utest_printf("\nverifying test data");
|
utest_printf("\nverifying test data");
|
||||||
srand(seed);
|
srand(seed);
|
||||||
for (size_t i=0; i<write_read_buf_size; i++) {
|
for (size_t i = 0; i < write_read_buf_size; i++) {
|
||||||
uint8_t expected_value = (uint8_t)rand();
|
uint8_t expected_value = (uint8_t)rand();
|
||||||
if (write_read_buf[i] != expected_value) {
|
if (write_read_buf[i] != expected_value) {
|
||||||
utest_printf("\ndata verify failed, write_read_buf[%d]=%" PRIu8 " and not %" PRIu8 "\n",
|
utest_printf("\ndata verify failed, write_read_buf[%d]=%" PRIu8 " and not %" PRIu8 "\n",
|
||||||
i, write_read_buf[i], expected_value);
|
i, write_read_buf[i], expected_value);
|
||||||
}
|
}
|
||||||
TEST_ASSERT_EQUAL(write_read_buf[i], expected_value);
|
TEST_ASSERT_EQUAL(write_read_buf[i], expected_value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,7 +104,7 @@ public:
|
||||||
|
|
||||||
inline void context(uint32_t context)
|
inline void context(uint32_t context)
|
||||||
{
|
{
|
||||||
_context = (void*)context;
|
_context = (void *)context;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline uint32_t entry(void)
|
inline uint32_t entry(void)
|
||||||
|
|
|
@ -61,28 +61,28 @@ MBED_STATIC_ASSERT(MBED_CONF_PLATFORM_CTHUNK_COUNT_MAX > 0, "MBED_CONF_PLATFORM_
|
||||||
|
|
||||||
const CThunkEntry CThunkBase::_thunk_table[MBED_CONF_PLATFORM_CTHUNK_COUNT_MAX] = {
|
const CThunkEntry CThunkBase::_thunk_table[MBED_CONF_PLATFORM_CTHUNK_COUNT_MAX] = {
|
||||||
#if ENABLE_N(128)
|
#if ENABLE_N(128)
|
||||||
DECLARE_THUNK128(START_128),
|
DECLARE_THUNK128(START_128),
|
||||||
#endif
|
#endif
|
||||||
#if ENABLE_N(64)
|
#if ENABLE_N(64)
|
||||||
DECLARE_THUNK64(START_64),
|
DECLARE_THUNK64(START_64),
|
||||||
#endif
|
#endif
|
||||||
#if ENABLE_N(32)
|
#if ENABLE_N(32)
|
||||||
DECLARE_THUNK32(START_32),
|
DECLARE_THUNK32(START_32),
|
||||||
#endif
|
#endif
|
||||||
#if ENABLE_N(16)
|
#if ENABLE_N(16)
|
||||||
DECLARE_THUNK16(START_16),
|
DECLARE_THUNK16(START_16),
|
||||||
#endif
|
#endif
|
||||||
#if ENABLE_N(8)
|
#if ENABLE_N(8)
|
||||||
DECLARE_THUNK8(START_8),
|
DECLARE_THUNK8(START_8),
|
||||||
#endif
|
#endif
|
||||||
#if ENABLE_N(4)
|
#if ENABLE_N(4)
|
||||||
DECLARE_THUNK4(START_4),
|
DECLARE_THUNK4(START_4),
|
||||||
#endif
|
#endif
|
||||||
#if ENABLE_N(2)
|
#if ENABLE_N(2)
|
||||||
DECLARE_THUNK2(START_2),
|
DECLARE_THUNK2(START_2),
|
||||||
#endif
|
#endif
|
||||||
#if ENABLE_N(1)
|
#if ENABLE_N(1)
|
||||||
DECLARE_THUNK1(START_1)
|
DECLARE_THUNK1(START_1)
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ typedef void (*CThunkEntry)(void);
|
||||||
|
|
||||||
class CThunkBase {
|
class CThunkBase {
|
||||||
protected:
|
protected:
|
||||||
typedef void (*Trampoline)(CThunkBase*);
|
typedef void (*Trampoline)(CThunkBase *);
|
||||||
|
|
||||||
Trampoline _trampoline;
|
Trampoline _trampoline;
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ namespace mbed {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/** Represents a directory stream. An opendir function returns
|
/** Represents a directory stream. An opendir function returns
|
||||||
* objects of this type. The core functions are read and seek,
|
* objects of this type. The core functions are read and seek,
|
||||||
* but only a subset needs to be provided.
|
* but only a subset needs to be provided.
|
||||||
*
|
*
|
||||||
|
|
|
@ -31,96 +31,96 @@ namespace mbed {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prevents generation of copy constructor and copy assignment operator in
|
* Prevents generation of copy constructor and copy assignment operator in
|
||||||
* derived classes.
|
* derived classes.
|
||||||
*
|
*
|
||||||
* @par Usage
|
* @par Usage
|
||||||
*
|
*
|
||||||
* To prevent generation of copy constructor and copy assignment operator,
|
* To prevent generation of copy constructor and copy assignment operator,
|
||||||
* inherit privately from the NonCopyable class.
|
* inherit privately from the NonCopyable class.
|
||||||
*
|
*
|
||||||
* @code
|
* @code
|
||||||
* class Resource : NonCopyable<Resource> { };
|
* class Resource : NonCopyable<Resource> { };
|
||||||
*
|
*
|
||||||
* Resource r;
|
* Resource r;
|
||||||
* // generates compile time error:
|
* // generates compile time error:
|
||||||
* Resource r2 = r;
|
* Resource r2 = r;
|
||||||
* @endcode
|
* @endcode
|
||||||
*
|
*
|
||||||
* @par Background information
|
* @par Background information
|
||||||
*
|
*
|
||||||
* Instances of polymorphic classes are not meant to be copied. The
|
* Instances of polymorphic classes are not meant to be copied. The
|
||||||
* C++ standards generate a default copy constructor and copy assignment
|
* C++ standards generate a default copy constructor and copy assignment
|
||||||
* function if these functions have not been defined in the class.
|
* function if these functions have not been defined in the class.
|
||||||
*
|
*
|
||||||
* Consider the following example:
|
* Consider the following example:
|
||||||
*
|
*
|
||||||
* @code
|
* @code
|
||||||
* // base class representing a connection
|
* // base class representing a connection
|
||||||
* struct Connection {
|
* struct Connection {
|
||||||
* Connection();
|
* Connection();
|
||||||
* virtual ~Connection();
|
* virtual ~Connection();
|
||||||
* virtual void open() = 0;
|
* virtual void open() = 0;
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* class SerialConnection : public Connection {
|
* class SerialConnection : public Connection {
|
||||||
* public:
|
* public:
|
||||||
* SerialConnection(Serial*);
|
* SerialConnection(Serial*);
|
||||||
*
|
*
|
||||||
* private:
|
* private:
|
||||||
* Serial* _serial;
|
* Serial* _serial;
|
||||||
* };
|
* };
|
||||||
*
|
*
|
||||||
* Connection& get_connection() {
|
* Connection& get_connection() {
|
||||||
* static SerialConnection serial_connection;
|
* static SerialConnection serial_connection;
|
||||||
* return serial_connection;
|
* return serial_connection;
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* Connection connection = get_connection();
|
* Connection connection = get_connection();
|
||||||
* @endcode
|
* @endcode
|
||||||
*
|
*
|
||||||
* There is a subtle bug in this code, the function get_connection returns a
|
* There is a subtle bug in this code, the function get_connection returns a
|
||||||
* reference to a Connection which is captured by value instead of reference.
|
* reference to a Connection which is captured by value instead of reference.
|
||||||
*
|
*
|
||||||
* When `get_connection` returns a reference to serial_connection it is copied into
|
* When `get_connection` returns a reference to serial_connection it is copied into
|
||||||
* the local variable connection. The vtable and others members defined in Connection
|
* the local variable connection. The vtable and others members defined in Connection
|
||||||
* are copied, but members defined in SerialConnection are left apart. This can cause
|
* are copied, but members defined in SerialConnection are left apart. This can cause
|
||||||
* severe crashes or bugs if the virtual functions captured use members not present
|
* severe crashes or bugs if the virtual functions captured use members not present
|
||||||
* in the base declaration.
|
* in the base declaration.
|
||||||
*
|
*
|
||||||
* To solve that problem, the copy constructor and assignment operator have to
|
* To solve that problem, the copy constructor and assignment operator have to
|
||||||
* be declared (but don't need to be defined) in the private section of the
|
* be declared (but don't need to be defined) in the private section of the
|
||||||
* Connection class:
|
* Connection class:
|
||||||
*
|
*
|
||||||
* @code
|
* @code
|
||||||
* struct Connection {
|
* struct Connection {
|
||||||
* private:
|
* private:
|
||||||
* Connection(const Connection&);
|
* Connection(const Connection&);
|
||||||
* Connection& operator=(const Connection&);
|
* Connection& operator=(const Connection&);
|
||||||
* }
|
* }
|
||||||
* @endcode
|
* @endcode
|
||||||
*
|
*
|
||||||
* Although manually declaring private copy constructor and assignment functions
|
* Although manually declaring private copy constructor and assignment functions
|
||||||
* works, it is not ideal. These declarations are usually easy to forget,
|
* works, it is not ideal. These declarations are usually easy to forget,
|
||||||
* not immediately visible, and may be obscure to uninformed programmers.
|
* not immediately visible, and may be obscure to uninformed programmers.
|
||||||
*
|
*
|
||||||
* Using the NonCopyable class reduces the boilerplate required and expresses
|
* Using the NonCopyable class reduces the boilerplate required and expresses
|
||||||
* the intent because class inheritance appears right after the class name
|
* the intent because class inheritance appears right after the class name
|
||||||
* declaration.
|
* declaration.
|
||||||
*
|
*
|
||||||
* @code
|
* @code
|
||||||
* struct Connection : private NonCopyable<Connection> {
|
* struct Connection : private NonCopyable<Connection> {
|
||||||
* // regular declarations
|
* // regular declarations
|
||||||
* }
|
* }
|
||||||
* @endcode
|
* @endcode
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @par Implementation details
|
* @par Implementation details
|
||||||
*
|
*
|
||||||
* Using a template type prevents cases where the empty base optimization cannot
|
* Using a template type prevents cases where the empty base optimization cannot
|
||||||
* be applied and therefore ensures that the cost of the NonCopyable semantic
|
* be applied and therefore ensures that the cost of the NonCopyable semantic
|
||||||
* sugar is null.
|
* sugar is null.
|
||||||
*
|
*
|
||||||
* As an example, the empty base optimization is prohibited if one of the empty
|
* As an example, the empty base optimization is prohibited if one of the empty
|
||||||
* base classes is also a base type of the first nonstatic data member:
|
* base classes is also a base type of the first nonstatic data member:
|
||||||
*
|
*
|
||||||
|
@ -157,7 +157,7 @@ namespace mbed {
|
||||||
* // kind of A. sizeof(C) == sizeof(B) == sizeof(int).
|
* // kind of A. sizeof(C) == sizeof(B) == sizeof(int).
|
||||||
* @endcode
|
* @endcode
|
||||||
*
|
*
|
||||||
* @tparam T The type that should be made noncopyable.
|
* @tparam T The type that should be made noncopyable.
|
||||||
*
|
*
|
||||||
* @note Compile time errors are disabled if you use the develop or release profile.
|
* @note Compile time errors are disabled if you use the develop or release profile.
|
||||||
* To override this behavior and force compile time errors in all profiles,
|
* To override this behavior and force compile time errors in all profiles,
|
||||||
|
@ -222,7 +222,7 @@ private:
|
||||||
*/
|
*/
|
||||||
NonCopyable &operator=(const NonCopyable &);
|
NonCopyable &operator=(const NonCopyable &);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
/**@}*/
|
/**@}*/
|
||||||
|
|
|
@ -39,12 +39,13 @@ namespace span_detail {
|
||||||
// If From type is convertible to To type, then the compilation constant value is
|
// If From type is convertible to To type, then the compilation constant value is
|
||||||
// true; otherwise, it is false.
|
// true; otherwise, it is false.
|
||||||
template<typename From, typename To>
|
template<typename From, typename To>
|
||||||
class is_convertible
|
class is_convertible {
|
||||||
{
|
struct true_type {
|
||||||
struct true_type { char x[512]; };
|
char x[512];
|
||||||
|
};
|
||||||
struct false_type { };
|
struct false_type { };
|
||||||
|
|
||||||
static const From& generator();
|
static const From &generator();
|
||||||
static true_type sink(const To &);
|
static true_type sink(const To &);
|
||||||
static false_type sink(...);
|
static false_type sink(...);
|
||||||
|
|
||||||
|
@ -59,11 +60,11 @@ public:
|
||||||
* Special value for the Extent parameter of Span.
|
* Special value for the Extent parameter of Span.
|
||||||
* If the type uses this value, then the size of the array is stored in the object
|
* If the type uses this value, then the size of the array is stored in the object
|
||||||
* at runtime.
|
* at runtime.
|
||||||
*
|
*
|
||||||
* @relates Span
|
* @relates Span
|
||||||
*/
|
*/
|
||||||
const ptrdiff_t SPAN_DYNAMIC_EXTENT = -1;
|
const ptrdiff_t SPAN_DYNAMIC_EXTENT = -1;
|
||||||
#else
|
#else
|
||||||
#define SPAN_DYNAMIC_EXTENT -1
|
#define SPAN_DYNAMIC_EXTENT -1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -293,6 +294,8 @@ struct Span {
|
||||||
MBED_ASSERT(Extent == 0 || first != NULL);
|
MBED_ASSERT(Extent == 0 || first != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AStyle ignore, not handling correctly below
|
||||||
|
// *INDENT-OFF*
|
||||||
/**
|
/**
|
||||||
* Construct a Span from the reference to an array.
|
* Construct a Span from the reference to an array.
|
||||||
*
|
*
|
||||||
|
@ -322,6 +325,7 @@ struct Span {
|
||||||
"OtherElementType(*)[] should be convertible to ElementType (*)[]"
|
"OtherElementType(*)[] should be convertible to ElementType (*)[]"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
// *INDENT-ON*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the size of the sequence viewed.
|
* Return the size of the sequence viewed.
|
||||||
|
@ -409,6 +413,8 @@ struct Span {
|
||||||
return Span<element_type, Count>(_data + (Extent - Count), Count);
|
return Span<element_type, Count>(_data + (Extent - Count), Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AStyle ignore, not handling correctly below
|
||||||
|
// *INDENT-OFF*
|
||||||
/**
|
/**
|
||||||
* Create a subspan that is a view of other Count elements; the view starts at
|
* Create a subspan that is a view of other Count elements; the view starts at
|
||||||
* element Offset.
|
* element Offset.
|
||||||
|
@ -439,6 +445,7 @@ struct Span {
|
||||||
Count == SPAN_DYNAMIC_EXTENT ? Extent - Offset : Count
|
Count == SPAN_DYNAMIC_EXTENT ? Extent - Offset : Count
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
// *INDENT-ON*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new Span over the first @p count elements of the existing view.
|
* Create a new Span over the first @p count elements of the existing view.
|
||||||
|
@ -464,9 +471,9 @@ struct Span {
|
||||||
{
|
{
|
||||||
MBED_ASSERT(0 <= count && count <= Extent);
|
MBED_ASSERT(0 <= count && count <= Extent);
|
||||||
return Span<element_type, SPAN_DYNAMIC_EXTENT>(
|
return Span<element_type, SPAN_DYNAMIC_EXTENT>(
|
||||||
_data + (Extent - count),
|
_data + (Extent - count),
|
||||||
count
|
count
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -491,9 +498,9 @@ struct Span {
|
||||||
(0 <= count && (count + offset) <= Extent)
|
(0 <= count && (count + offset) <= Extent)
|
||||||
);
|
);
|
||||||
return Span<element_type, SPAN_DYNAMIC_EXTENT>(
|
return Span<element_type, SPAN_DYNAMIC_EXTENT>(
|
||||||
_data + offset,
|
_data + offset,
|
||||||
count == SPAN_DYNAMIC_EXTENT ? Extent - offset : count
|
count == SPAN_DYNAMIC_EXTENT ? Extent - offset : count
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -579,6 +586,8 @@ struct Span<ElementType, SPAN_DYNAMIC_EXTENT> {
|
||||||
MBED_ASSERT(first != NULL || (last - first) == 0);
|
MBED_ASSERT(first != NULL || (last - first) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AStyle ignore, not handling correctly below
|
||||||
|
// *INDENT-OFF*
|
||||||
/**
|
/**
|
||||||
* Construct a Span from the reference to an array.
|
* Construct a Span from the reference to an array.
|
||||||
*
|
*
|
||||||
|
@ -611,6 +620,7 @@ struct Span<ElementType, SPAN_DYNAMIC_EXTENT> {
|
||||||
"OtherElementType(*)[] should be convertible to ElementType (*)[]"
|
"OtherElementType(*)[] should be convertible to ElementType (*)[]"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
// *INDENT-ON*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the size of the array viewed.
|
* Return the size of the array viewed.
|
||||||
|
@ -713,9 +723,9 @@ struct Span<ElementType, SPAN_DYNAMIC_EXTENT> {
|
||||||
(0 <= Count && (Count + Offset) <= _size)
|
(0 <= Count && (Count + Offset) <= _size)
|
||||||
);
|
);
|
||||||
return Span<element_type, Count>(
|
return Span<element_type, Count>(
|
||||||
_data + Offset,
|
_data + Offset,
|
||||||
Count == SPAN_DYNAMIC_EXTENT ? _size - Offset : Count
|
Count == SPAN_DYNAMIC_EXTENT ? _size - Offset : Count
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -742,9 +752,9 @@ struct Span<ElementType, SPAN_DYNAMIC_EXTENT> {
|
||||||
{
|
{
|
||||||
MBED_ASSERT(0 <= count && count <= _size);
|
MBED_ASSERT(0 <= count && count <= _size);
|
||||||
return Span<element_type, SPAN_DYNAMIC_EXTENT>(
|
return Span<element_type, SPAN_DYNAMIC_EXTENT>(
|
||||||
_data + (_size - count),
|
_data + (_size - count),
|
||||||
count
|
count
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -769,9 +779,9 @@ struct Span<ElementType, SPAN_DYNAMIC_EXTENT> {
|
||||||
(0 <= count && (count + offset) <= _size)
|
(0 <= count && (count + offset) <= _size)
|
||||||
);
|
);
|
||||||
return Span<element_type, SPAN_DYNAMIC_EXTENT>(
|
return Span<element_type, SPAN_DYNAMIC_EXTENT>(
|
||||||
_data + offset,
|
_data + offset,
|
||||||
count == SPAN_DYNAMIC_EXTENT ? _size - offset : count
|
count == SPAN_DYNAMIC_EXTENT ? _size - offset : count
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -787,7 +797,7 @@ private:
|
||||||
*
|
*
|
||||||
* @return True if Spans in input have the same size and the same content and
|
* @return True if Spans in input have the same size and the same content and
|
||||||
* false otherwise.
|
* false otherwise.
|
||||||
*
|
*
|
||||||
* @relates Span
|
* @relates Span
|
||||||
*/
|
*/
|
||||||
template<typename T, typename U, ptrdiff_t LhsExtent, ptrdiff_t RhsExtent>
|
template<typename T, typename U, ptrdiff_t LhsExtent, ptrdiff_t RhsExtent>
|
||||||
|
@ -804,6 +814,8 @@ bool operator==(const Span<T, LhsExtent> &lhs, const Span<U, RhsExtent> &rhs)
|
||||||
return std::equal(lhs.data(), lhs.data() + lhs.size(), rhs.data());
|
return std::equal(lhs.data(), lhs.data() + lhs.size(), rhs.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AStyle ignore, not handling correctly below
|
||||||
|
// *INDENT-OFF*
|
||||||
/**
|
/**
|
||||||
* Equality operation between a Span and a reference to a C++ array.
|
* Equality operation between a Span and a reference to a C++ array.
|
||||||
*
|
*
|
||||||
|
@ -842,7 +854,7 @@ bool operator==(T (&lhs)[LhsExtent], const Span<T, RhsExtent> &rhs)
|
||||||
*
|
*
|
||||||
* @return True if arrays in input do not have the same size or the same content
|
* @return True if arrays in input do not have the same size or the same content
|
||||||
* and false otherwise.
|
* and false otherwise.
|
||||||
*
|
*
|
||||||
* @relates Span
|
* @relates Span
|
||||||
*/
|
*/
|
||||||
template<typename T, typename U, ptrdiff_t LhsExtent, ptrdiff_t RhsExtent>
|
template<typename T, typename U, ptrdiff_t LhsExtent, ptrdiff_t RhsExtent>
|
||||||
|
@ -893,7 +905,7 @@ bool operator!=(T (&lhs)[LhsExtent], const Span<T, RhsExtent> &rhs)
|
||||||
*
|
*
|
||||||
* @note This helper avoids the typing of template parameter when Span is
|
* @note This helper avoids the typing of template parameter when Span is
|
||||||
* created 'inline'.
|
* created 'inline'.
|
||||||
*
|
*
|
||||||
* @relates Span
|
* @relates Span
|
||||||
*/
|
*/
|
||||||
template<typename T, size_t Size>
|
template<typename T, size_t Size>
|
||||||
|
@ -959,7 +971,7 @@ Span<const T, Extent> make_const_Span(const T (&elements)[Extent])
|
||||||
{
|
{
|
||||||
return Span<const T, Extent>(elements);
|
return Span<const T, Extent>(elements);
|
||||||
}
|
}
|
||||||
|
// *INDENT-ON*
|
||||||
/**
|
/**
|
||||||
* Generate a Span to a const content from a pointer to a C/C++ array.
|
* Generate a Span to a const content from a pointer to a C/C++ array.
|
||||||
*
|
*
|
||||||
|
@ -972,7 +984,7 @@ Span<const T, Extent> make_const_Span(const T (&elements)[Extent])
|
||||||
*
|
*
|
||||||
* @note This helper avoids the typing of template parameter when Span is
|
* @note This helper avoids the typing of template parameter when Span is
|
||||||
* created 'inline'.
|
* created 'inline'.
|
||||||
*
|
*
|
||||||
* @relates Span
|
* @relates Span
|
||||||
*/
|
*/
|
||||||
template<size_t Extent, typename T>
|
template<size_t Extent, typename T>
|
||||||
|
@ -994,7 +1006,7 @@ Span<const T, Extent> make_const_Span(const T *elements)
|
||||||
*
|
*
|
||||||
* @note This helper avoids the typing of template parameter when Span is
|
* @note This helper avoids the typing of template parameter when Span is
|
||||||
* created 'inline'.
|
* created 'inline'.
|
||||||
*
|
*
|
||||||
* @relates Span
|
* @relates Span
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
|
@ -783,7 +783,7 @@ typedef enum _mbed_error_code {
|
||||||
MBED_DEFINE_SYSTEM_ERROR(BLE_BACKEND_CREATION_FAILED, 66), /* 322 BLE Backend creation failed */
|
MBED_DEFINE_SYSTEM_ERROR(BLE_BACKEND_CREATION_FAILED, 66), /* 322 BLE Backend creation failed */
|
||||||
MBED_DEFINE_SYSTEM_ERROR(BLE_BACKEND_NOT_INITIALIZED, 67), /* 323 BLE Backend not initialized */
|
MBED_DEFINE_SYSTEM_ERROR(BLE_BACKEND_NOT_INITIALIZED, 67), /* 323 BLE Backend not initialized */
|
||||||
MBED_DEFINE_SYSTEM_ERROR(ASSERTION_FAILED, 68), /* 324 Assertion Failed */
|
MBED_DEFINE_SYSTEM_ERROR(ASSERTION_FAILED, 68), /* 324 Assertion Failed */
|
||||||
|
|
||||||
//Everytime you add a new system error code, you must update
|
//Everytime you add a new system error code, you must update
|
||||||
//Error documentation under Handbook to capture the info on
|
//Error documentation under Handbook to capture the info on
|
||||||
//the new error status/codes
|
//the new error status/codes
|
||||||
|
|
|
@ -168,7 +168,7 @@ void mbed_error_puts(const char *str);
|
||||||
|
|
||||||
/** @deprecated Renamed to mbed_error_vprintf to match functionality */
|
/** @deprecated Renamed to mbed_error_vprintf to match functionality */
|
||||||
MBED_DEPRECATED_SINCE("mbed-os-5.11",
|
MBED_DEPRECATED_SINCE("mbed-os-5.11",
|
||||||
"Renamed to mbed_error_vprintf to match functionality.")
|
"Renamed to mbed_error_vprintf to match functionality.")
|
||||||
void mbed_error_vfprintf(const char *format, va_list arg) MBED_PRINTF(1, 0);
|
void mbed_error_vfprintf(const char *format, va_list arg) MBED_PRINTF(1, 0);
|
||||||
/** @}*/
|
/** @}*/
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ extern "C" {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* enum Memory operation types for tracer
|
* enum Memory operation types for tracer
|
||||||
*/
|
*/
|
||||||
enum {
|
enum {
|
||||||
MBED_MEM_TRACE_MALLOC, /**< Identifier for malloc operation */
|
MBED_MEM_TRACE_MALLOC, /**< Identifier for malloc operation */
|
||||||
MBED_MEM_TRACE_REALLOC, /**< Identifier for realloc operation */
|
MBED_MEM_TRACE_REALLOC, /**< Identifier for realloc operation */
|
||||||
|
|
|
@ -57,9 +57,9 @@ struct Waiter;
|
||||||
* `ConditionVariable::notify_all` is called.
|
* `ConditionVariable::notify_all` is called.
|
||||||
* At least one thread waiting on the condition variable wakes
|
* At least one thread waiting on the condition variable wakes
|
||||||
* when `ConditionVariable::notify_one` is called.
|
* when `ConditionVariable::notify_one` is called.
|
||||||
*
|
*
|
||||||
* While a thread is waiting for notification of a
|
* While a thread is waiting for notification of a
|
||||||
* ConditionVariable, it releases the lock held on the mutex.
|
* ConditionVariable, it releases the lock held on the mutex.
|
||||||
* The ConditionVariable reacquires the mutex lock before exiting the wait
|
* The ConditionVariable reacquires the mutex lock before exiting the wait
|
||||||
* function.
|
* function.
|
||||||
*
|
*
|
||||||
|
|
17
rtos/Mail.h
17
rtos/Mail.h
|
@ -42,7 +42,7 @@ namespace rtos {
|
||||||
* \defgroup rtos_Mail Mail class
|
* \defgroup rtos_Mail Mail class
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** The Mail class allows you to control, send, receive or wait for mail.
|
/** The Mail class allows you to control, send, receive or wait for mail.
|
||||||
* A mail is a memory block that is sent to a thread or interrupt service routine (ISR).
|
* A mail is a memory block that is sent to a thread or interrupt service routine (ISR).
|
||||||
* @tparam T Data type of a single mail message element.
|
* @tparam T Data type of a single mail message element.
|
||||||
|
@ -96,7 +96,8 @@ public:
|
||||||
*
|
*
|
||||||
* @note You may call this function from ISR context.
|
* @note You may call this function from ISR context.
|
||||||
*/
|
*/
|
||||||
T* alloc(uint32_t millisec=0) {
|
T *alloc(uint32_t millisec = 0)
|
||||||
|
{
|
||||||
return _pool.alloc();
|
return _pool.alloc();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +109,8 @@ public:
|
||||||
*
|
*
|
||||||
* @note You may call this function from ISR context.
|
* @note You may call this function from ISR context.
|
||||||
*/
|
*/
|
||||||
T* calloc(uint32_t millisec=0) {
|
T *calloc(uint32_t millisec = 0)
|
||||||
|
{
|
||||||
return _pool.calloc();
|
return _pool.calloc();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +122,8 @@ public:
|
||||||
*
|
*
|
||||||
* @note You may call this function from ISR context.
|
* @note You may call this function from ISR context.
|
||||||
*/
|
*/
|
||||||
osStatus put(T *mptr) {
|
osStatus put(T *mptr)
|
||||||
|
{
|
||||||
return _queue.put(mptr);
|
return _queue.put(mptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,7 +139,8 @@ public:
|
||||||
*
|
*
|
||||||
* @note You may call this function from ISR context if the millisec parameter is set to 0.
|
* @note You may call this function from ISR context if the millisec parameter is set to 0.
|
||||||
*/
|
*/
|
||||||
osEvent get(uint32_t millisec=osWaitForever) {
|
osEvent get(uint32_t millisec = osWaitForever)
|
||||||
|
{
|
||||||
osEvent evt = _queue.get(millisec);
|
osEvent evt = _queue.get(millisec);
|
||||||
if (evt.status == osEventMessage) {
|
if (evt.status == osEventMessage) {
|
||||||
evt.status = osEventMail;
|
evt.status = osEventMail;
|
||||||
|
@ -152,7 +156,8 @@ public:
|
||||||
*
|
*
|
||||||
* @note You may call this function from ISR context.
|
* @note You may call this function from ISR context.
|
||||||
*/
|
*/
|
||||||
osStatus free(T *mptr) {
|
osStatus free(T *mptr)
|
||||||
|
{
|
||||||
return _pool.free(mptr);
|
return _pool.free(mptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,7 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Wait until a Mutex becomes available.
|
Wait until a Mutex becomes available.
|
||||||
|
|
||||||
@deprecated Do not use this function. This function has been replaced with lock(), trylock() and trylock_for() functions.
|
@deprecated Do not use this function. This function has been replaced with lock(), trylock() and trylock_for() functions.
|
||||||
|
|
||||||
@param millisec timeout value or 0 in case of no time-out.
|
@param millisec timeout value or 0 in case of no time-out.
|
||||||
|
|
|
@ -143,7 +143,8 @@ public:
|
||||||
* parameter is set to 0.
|
* parameter is set to 0.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
osStatus put(T* data, uint32_t millisec=0, uint8_t prio=0) {
|
osStatus put(T *data, uint32_t millisec = 0, uint8_t prio = 0)
|
||||||
|
{
|
||||||
return osMessageQueuePut(_id, &data, prio, millisec);
|
return osMessageQueuePut(_id, &data, prio, millisec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,7 +183,8 @@ public:
|
||||||
* @note You may call this function from ISR context if the millisec
|
* @note You may call this function from ISR context if the millisec
|
||||||
* parameter is set to 0.
|
* parameter is set to 0.
|
||||||
*/
|
*/
|
||||||
osEvent get(uint32_t millisec=osWaitForever) {
|
osEvent get(uint32_t millisec = osWaitForever)
|
||||||
|
{
|
||||||
osEvent event;
|
osEvent event;
|
||||||
T *data = NULL;
|
T *data = NULL;
|
||||||
osStatus_t res = osMessageQueueGet(_id, &data, NULL, millisec);
|
osStatus_t res = osMessageQueueGet(_id, &data, NULL, millisec);
|
||||||
|
|
|
@ -33,131 +33,131 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "rtx_lib.h"
|
#include "rtx_lib.h"
|
||||||
|
|
||||||
using namespace mbed;
|
using namespace mbed;
|
||||||
|
|
||||||
#if (defined(MBED_TICKLESS) && defined(DEVICE_LPTICKER))
|
#if (defined(MBED_TICKLESS) && defined(DEVICE_LPTICKER))
|
||||||
|
|
||||||
#include "rtos/TARGET_CORTEX/SysTimer.h"
|
#include "rtos/TARGET_CORTEX/SysTimer.h"
|
||||||
|
|
||||||
static rtos::internal::SysTimer *os_timer;
|
static rtos::internal::SysTimer *os_timer;
|
||||||
static uint64_t os_timer_data[sizeof(rtos::internal::SysTimer) / 8];
|
static uint64_t os_timer_data[sizeof(rtos::internal::SysTimer) / 8];
|
||||||
|
|
||||||
/// Enable System Timer.
|
// Enable System Timer.
|
||||||
void OS_Tick_Enable(void)
|
void OS_Tick_Enable(void)
|
||||||
{
|
{
|
||||||
// Do not use SingletonPtr since this relies on the RTOS
|
// Do not use SingletonPtr since this relies on the RTOS
|
||||||
if (NULL == os_timer) {
|
if (NULL == os_timer) {
|
||||||
os_timer = new (os_timer_data) rtos::internal::SysTimer();
|
os_timer = new (os_timer_data) rtos::internal::SysTimer();
|
||||||
os_timer->setup_irq();
|
os_timer->setup_irq();
|
||||||
}
|
|
||||||
|
|
||||||
// set to fire interrupt on next tick
|
|
||||||
os_timer->schedule_tick();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Disable System Timer.
|
|
||||||
void OS_Tick_Disable(void)
|
|
||||||
{
|
|
||||||
os_timer->cancel_tick();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Acknowledge System Timer IRQ.
|
|
||||||
void OS_Tick_AcknowledgeIRQ(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get System Timer count.
|
|
||||||
uint32_t OS_Tick_GetCount(void)
|
|
||||||
{
|
|
||||||
return os_timer->get_time() & 0xFFFFFFFF;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get OS Tick IRQ number.
|
|
||||||
int32_t OS_Tick_GetIRQn(void)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get OS Tick overflow status.
|
|
||||||
uint32_t OS_Tick_GetOverflow(void)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get OS Tick interval.
|
|
||||||
uint32_t OS_Tick_GetInterval(void)
|
|
||||||
{
|
|
||||||
return 1000;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void default_idle_hook(void)
|
|
||||||
{
|
|
||||||
uint32_t ticks_to_sleep = osKernelSuspend();
|
|
||||||
const bool block_deep_sleep = ticks_to_sleep <= MBED_CONF_TARGET_DEEP_SLEEP_LATENCY;
|
|
||||||
|
|
||||||
if (block_deep_sleep) {
|
|
||||||
sleep_manager_lock_deep_sleep();
|
|
||||||
} else {
|
|
||||||
ticks_to_sleep -= MBED_CONF_TARGET_DEEP_SLEEP_LATENCY;
|
|
||||||
}
|
|
||||||
os_timer->suspend(ticks_to_sleep);
|
|
||||||
|
|
||||||
bool event_pending = false;
|
|
||||||
while (!os_timer->suspend_time_passed() && !event_pending) {
|
|
||||||
|
|
||||||
core_util_critical_section_enter();
|
|
||||||
if (osRtxInfo.kernel.pendSV) {
|
|
||||||
event_pending = true;
|
|
||||||
} else {
|
|
||||||
sleep();
|
|
||||||
}
|
}
|
||||||
core_util_critical_section_exit();
|
|
||||||
|
|
||||||
// Ensure interrupts get a chance to fire
|
// set to fire interrupt on next tick
|
||||||
__ISB();
|
os_timer->schedule_tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (block_deep_sleep) {
|
// Disable System Timer.
|
||||||
sleep_manager_unlock_deep_sleep();
|
void OS_Tick_Disable(void)
|
||||||
|
{
|
||||||
|
os_timer->cancel_tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
osKernelResume(os_timer->resume());
|
// Acknowledge System Timer IRQ.
|
||||||
}
|
void OS_Tick_AcknowledgeIRQ(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get System Timer count.
|
||||||
|
uint32_t OS_Tick_GetCount(void)
|
||||||
|
{
|
||||||
|
return os_timer->get_time() & 0xFFFFFFFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get OS Tick IRQ number.
|
||||||
|
int32_t OS_Tick_GetIRQn(void)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get OS Tick overflow status.
|
||||||
|
uint32_t OS_Tick_GetOverflow(void)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get OS Tick interval.
|
||||||
|
uint32_t OS_Tick_GetInterval(void)
|
||||||
|
{
|
||||||
|
return 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void default_idle_hook(void)
|
||||||
|
{
|
||||||
|
uint32_t ticks_to_sleep = osKernelSuspend();
|
||||||
|
const bool block_deep_sleep = ticks_to_sleep <= MBED_CONF_TARGET_DEEP_SLEEP_LATENCY;
|
||||||
|
|
||||||
|
if (block_deep_sleep) {
|
||||||
|
sleep_manager_lock_deep_sleep();
|
||||||
|
} else {
|
||||||
|
ticks_to_sleep -= MBED_CONF_TARGET_DEEP_SLEEP_LATENCY;
|
||||||
|
}
|
||||||
|
os_timer->suspend(ticks_to_sleep);
|
||||||
|
|
||||||
|
bool event_pending = false;
|
||||||
|
while (!os_timer->suspend_time_passed() && !event_pending) {
|
||||||
|
|
||||||
|
core_util_critical_section_enter();
|
||||||
|
if (osRtxInfo.kernel.pendSV) {
|
||||||
|
event_pending = true;
|
||||||
|
} else {
|
||||||
|
sleep();
|
||||||
|
}
|
||||||
|
core_util_critical_section_exit();
|
||||||
|
|
||||||
|
// Ensure interrupts get a chance to fire
|
||||||
|
__ISB();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (block_deep_sleep) {
|
||||||
|
sleep_manager_unlock_deep_sleep();
|
||||||
|
}
|
||||||
|
|
||||||
|
osKernelResume(os_timer->resume());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
static void default_idle_hook(void)
|
static void default_idle_hook(void)
|
||||||
{
|
{
|
||||||
// critical section to complete sleep with locked deepsleep
|
// critical section to complete sleep with locked deepsleep
|
||||||
core_util_critical_section_enter();
|
core_util_critical_section_enter();
|
||||||
sleep_manager_lock_deep_sleep();
|
sleep_manager_lock_deep_sleep();
|
||||||
sleep();
|
sleep();
|
||||||
sleep_manager_unlock_deep_sleep();
|
sleep_manager_unlock_deep_sleep();
|
||||||
core_util_critical_section_exit();
|
core_util_critical_section_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // (defined(MBED_TICKLESS) && defined(DEVICE_LPTICKER))
|
#endif // (defined(MBED_TICKLESS) && defined(DEVICE_LPTICKER))
|
||||||
|
|
||||||
static void (*idle_hook_fptr)(void) = &default_idle_hook;
|
static void (*idle_hook_fptr)(void) = &default_idle_hook;
|
||||||
|
|
||||||
void rtos_attach_idle_hook(void (*fptr)(void))
|
void rtos_attach_idle_hook(void (*fptr)(void))
|
||||||
{
|
{
|
||||||
//Attach the specified idle hook, or the default idle hook in case of a NULL pointer
|
//Attach the specified idle hook, or the default idle hook in case of a NULL pointer
|
||||||
if (fptr != NULL) {
|
if (fptr != NULL) {
|
||||||
idle_hook_fptr = fptr;
|
idle_hook_fptr = fptr;
|
||||||
} else {
|
} else {
|
||||||
idle_hook_fptr = default_idle_hook;
|
idle_hook_fptr = default_idle_hook;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
MBED_NORETURN void rtos_idle_loop(void)
|
MBED_NORETURN void rtos_idle_loop(void)
|
||||||
{
|
{
|
||||||
//Continuously call the idle hook function pointer
|
//Continuously call the idle hook function pointer
|
||||||
while (1) {
|
while (1) {
|
||||||
idle_hook_fptr();
|
idle_hook_fptr();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
|
Loading…
Reference in New Issue