forked from u-blox/ubxlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New network/device API, next phase of introduction. (#554)
New network/device API, next phase of introduction. Lots of changes in this commit unfortunately. The meat of it is: - what was u_device_internal.c/u_device_internal.h is now: - src/u_device.c: contains the implementation of the public device API functions, - src/u_device_shared.c/.h: contains the functions that the device API shares with other ubxlib modules but are NOT part of the public device API, - src/u_device_private_xxx.c/.h: contains the device-specific parts of the device open/close calls for each xxx device type, not shared with anyone/anything, - src/u_device_shared_xxx.h: defines a structure, for each device type, of the data which is known to the device API but needs to be shared with the network API; this data is hooked into the pContext pointer of the device instance so that network can get at it, - src/u_device_private_xxx_stub.c: stubs to permit compilation without a given device type; note that this doesn't work _FULLY_ (see u-blox#36) but until we have actually implemented the new "stubbing" mechanism we should maintain it, since a customer is known to be using it, - made naming consistent (only one spelling of "Cfg", variables that are of thingType_t have "Type" on the end of the variable name), intended to make it easier for a user to know what to write for a variable name or a type without having to think about it, - as suggested, moved to the new network structure names for the new code, so uDeviceNetworkCfgxxx_t -> uNetworkCfgxxx_t. - implemented the new bits of the device API for all device types, - moved the initialisation stuff from being in the uNetwork API to the uDevice API, i.e. uNetworkInit()/Deinit() -> uDeviceInit()/Deinit(), - implemented the remaining new bits of the network API, - implemented the new dynamic behaviours, specifically: - taking down a network no longer performs the power off, that is done only by closing the device, - deinitialising the device/network API does NOT do a clean-up (need to decide whether we think this is a good idea or not 'cos it could be made to do so), - "up" function parameter renamed to "upNotDown"; a bit more to grab hold of for my eyes, I couldn't find it easily when reading the code, - all the old APIs still work. But I'm afraid I've not tested _any_ of the new stuff yet :-(.
- Loading branch information
Showing
54 changed files
with
2,258 additions
and
679 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
/* | ||
* Copyright 2022 u-blox | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** @file | ||
* @brief Functions for initializing a u-blox device (chip or module). | ||
*/ | ||
|
||
#ifdef U_CFG_OVERRIDE | ||
# include "u_cfg_override.h" // For a customer's configuration override | ||
#endif | ||
|
||
#include "stddef.h" // NULL, size_t etc. | ||
#include "stdint.h" // int32_t etc. | ||
#include "stdbool.h" // | ||
|
||
#include "u_error_common.h" | ||
|
||
#include "u_device.h" | ||
#include "u_device_shared.h" | ||
#include "u_device_private_cell.h" | ||
#include "u_device_private_gnss.h" | ||
#include "u_device_private_short_range.h" | ||
|
||
/* ---------------------------------------------------------------- | ||
* COMPILE-TIME MACROS | ||
* -------------------------------------------------------------- */ | ||
|
||
/* ---------------------------------------------------------------- | ||
* TYPES | ||
* -------------------------------------------------------------- */ | ||
|
||
/* ---------------------------------------------------------------- | ||
* STATIC VARIABLES | ||
* -------------------------------------------------------------- */ | ||
|
||
/* ---------------------------------------------------------------- | ||
* STATIC FUNCTIONS | ||
* -------------------------------------------------------------- */ | ||
|
||
/* ---------------------------------------------------------------- | ||
* PUBLIC FUNCTIONS | ||
* -------------------------------------------------------------- */ | ||
|
||
int32_t uDeviceInit() | ||
{ | ||
int32_t errorCode = uDeviceMutexCreate(); | ||
|
||
if (errorCode == 0) { | ||
errorCode = uDevicePrivateCellInit(); | ||
if (errorCode == (int32_t) U_ERROR_COMMON_NOT_IMPLEMENTED) { | ||
errorCode = 0; | ||
} | ||
} | ||
if (errorCode == 0) { | ||
errorCode = uDevicePrivateGnssInit(); | ||
if (errorCode == (int32_t) U_ERROR_COMMON_NOT_IMPLEMENTED) { | ||
errorCode = 0; | ||
} | ||
} | ||
if (errorCode == 0) { | ||
errorCode = uDevicePrivateShortRangeInit(); | ||
if (errorCode == (int32_t) U_ERROR_COMMON_NOT_IMPLEMENTED) { | ||
errorCode = 0; | ||
} | ||
} | ||
|
||
// Clean up on error | ||
if (errorCode != 0) { | ||
uDevicePrivateShortRangeDeinit(); | ||
uDevicePrivateCellDeinit(); | ||
uDevicePrivateGnssDeinit(); | ||
uDeviceMutexDestroy(); | ||
} | ||
|
||
return errorCode; | ||
} | ||
|
||
int32_t uDeviceDeinit() | ||
{ | ||
uDevicePrivateShortRangeDeinit(); | ||
uDevicePrivateGnssDeinit(); | ||
uDevicePrivateCellDeinit(); | ||
uDeviceMutexDestroy(); | ||
return (int32_t) U_ERROR_COMMON_SUCCESS; | ||
} | ||
|
||
int32_t uDeviceOpen(const uDeviceCfg_t *pDeviceCfg, uDeviceHandle_t *pDeviceHandle) | ||
{ | ||
// Lock the API | ||
int32_t errorCode = uDeviceLock(); | ||
|
||
if (errorCode == 0) { | ||
errorCode = (int32_t) U_ERROR_COMMON_INVALID_PARAMETER; | ||
if ((pDeviceCfg != NULL) && (pDeviceCfg->version == 0) && (pDeviceHandle != NULL)) { | ||
switch (pDeviceCfg->deviceType) { | ||
case U_DEVICE_TYPE_CELL: | ||
errorCode = uDevicePrivateCellAdd(pDeviceCfg, pDeviceHandle); | ||
if (errorCode == 0) { | ||
U_DEVICE_INSTANCE(*pDeviceHandle)->moduleType = pDeviceCfg->deviceCfg.cfgCell.moduleType; | ||
} | ||
break; | ||
case U_DEVICE_TYPE_GNSS: | ||
errorCode = uDevicePrivateGnssAdd(pDeviceCfg, pDeviceHandle); | ||
if (errorCode == 0) { | ||
U_DEVICE_INSTANCE(*pDeviceHandle)->moduleType = pDeviceCfg->deviceCfg.cfgGnss.moduleType; | ||
} | ||
break; | ||
case U_DEVICE_TYPE_SHORT_RANGE: | ||
errorCode = uDevicePrivateShortRangeAdd(pDeviceCfg, pDeviceHandle); | ||
if (errorCode == 0) { | ||
U_DEVICE_INSTANCE(*pDeviceHandle)->moduleType = pDeviceCfg->deviceCfg.cfgSho.moduleType; | ||
} | ||
break; | ||
case U_DEVICE_TYPE_SHORT_RANGE_OPEN_CPU: | ||
errorCode = uDevicePrivateShortRangeOpenCpuAdd(pDeviceCfg, pDeviceHandle); | ||
if (errorCode == 0) { | ||
U_DEVICE_INSTANCE(*pDeviceHandle)->moduleType = pDeviceCfg->deviceCfg.cfgSho.moduleType; | ||
} | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
// ...and done | ||
uDeviceUnlock(); | ||
} | ||
|
||
return errorCode; | ||
} | ||
|
||
int32_t uDeviceClose(uDeviceHandle_t devHandle) | ||
{ | ||
// Lock the API | ||
int32_t errorCode = uDeviceLock(); | ||
|
||
if (errorCode == 0) { | ||
errorCode = (int32_t) U_ERROR_COMMON_INVALID_PARAMETER; | ||
switch (uDeviceGetDeviceType(devHandle)) { | ||
case U_DEVICE_TYPE_CELL: | ||
errorCode = uDevicePrivateCellRemove(devHandle); | ||
break; | ||
case U_DEVICE_TYPE_GNSS: | ||
errorCode = uDevicePrivateGnssRemove(devHandle); | ||
break; | ||
case U_DEVICE_TYPE_SHORT_RANGE: | ||
errorCode = uDevicePrivateShortRangeRemove(devHandle); | ||
break; | ||
case U_DEVICE_TYPE_SHORT_RANGE_OPEN_CPU: | ||
errorCode = uDevicePrivateShortRangeOpenCpuRemove(devHandle); | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
// ...and done | ||
uDeviceUnlock(); | ||
} | ||
|
||
return errorCode; | ||
} | ||
|
||
// End of file |
Oops, something went wrong.