-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
183 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#include "platform.h" | ||
|
||
#include <string.h> | ||
#include <nrf.h> | ||
|
||
static const char *defaultDeviceType = "0;CF20;R=D"; | ||
|
||
static char *deviceTypeStringLocation = (void*)PLATFORM_DEVICE_DATA_FLASH_POS; | ||
|
||
static bool has_rfx2411n = false; | ||
|
||
void platformGetDeviceTypeString(char *deviceTypeString) | ||
{ | ||
if (deviceTypeStringLocation[0] == 0xffu) { | ||
strncpy(deviceTypeString, defaultDeviceType, 32); | ||
deviceTypeString[32] = 0; | ||
} else { | ||
strncpy(deviceTypeString, deviceTypeStringLocation, 32); | ||
deviceTypeString[32] = 0; | ||
} | ||
} | ||
|
||
/** | ||
* Parse deviceType string to extract the deviceType | ||
* | ||
* Ignores the key=value sections. | ||
* | ||
* \param [in] deviceTypeString deviceTypeString extracted from the hardware | ||
* \param [out] deviceType Buffer of at least PLATFORM_DEVICE_TYPE_MAX_LEN | ||
* bytes where the device type will be stored | ||
* \return 0 in case of success, 1 in case of failure. | ||
*/ | ||
static int platformParseDeviceTypeString(char* deviceTypeString, char* deviceType) { | ||
// char *state; | ||
|
||
memcpy(deviceType, deviceTypeString+2, 4); | ||
deviceType[4] = '\0'; | ||
|
||
return 0; | ||
} | ||
|
||
// This function configures the platform in runtime based on the device type. | ||
// The main reason to not move it into the platform files is that if a user | ||
// flashes the wrong binary in the NRF we still want it to start up. | ||
int platformInitByDeviceType() { | ||
static char deviceTypeString[PLATFORM_DEVICE_TYPE_STRING_MAX_LEN]; | ||
static char deviceType[PLATFORM_DEVICE_TYPE_MAX_LEN]; | ||
|
||
platformGetDeviceTypeString(deviceTypeString); | ||
if (platformParseDeviceTypeString(deviceTypeString, deviceType) != 0) { | ||
return 1; | ||
} | ||
|
||
if (0 == strcmp(deviceType, "CF20")) { | ||
has_rfx2411n = false; | ||
|
||
} else if (0 == strcmp(deviceType, "CF21")) { | ||
has_rfx2411n = true; | ||
|
||
} else if (0 == strcmp(deviceType, "RR10")) { | ||
has_rfx2411n = true; | ||
|
||
} else if ((0 == strcmp(deviceType, "RZ10")) || | ||
(0 == strcmp(deviceType, "CB10")) || | ||
(0 == strcmp(deviceType, "CB11"))) { | ||
has_rfx2411n = true; | ||
|
||
} else { | ||
has_rfx2411n = false; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
bool platformHasRfx2411n() { | ||
return has_rfx2411n; | ||
} |
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,67 @@ | ||
/** | ||
* || ____ _ __ | ||
* +------+ / __ )(_) /_______________ _____ ___ | ||
* | 0xBC | / __ / / __/ ___/ ___/ __ `/_ / / _ \ | ||
* +------+ / /_/ / / /_/ /__/ / / /_/ / / /_/ __/ | ||
* || || /_____/_/\__/\___/_/ \__,_/ /___/\___/ | ||
* | ||
* Crazyflie 2.0 NRF Firmware | ||
* Copyright (c) 2024, Bitcraze AB, All rights reserved. | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3.0 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library. | ||
*/ | ||
#pragma once | ||
|
||
#include <stdint.h> | ||
#include <stdbool.h> | ||
|
||
#define PLATFORM_DEVICE_DATA_FLASH_POS 0x3FFE0 | ||
#define PLATFORM_DEVICE_TYPE_STRING_MAX_LEN 33 | ||
#define PLATFORM_DEVICE_TYPE_MAX_LEN 31 | ||
|
||
/** | ||
* Fetch deviceType string from flash | ||
* | ||
* This function defaults to "0;CF20;R=D" if no string is present in the | ||
* hardware | ||
* | ||
* \param [out] deviceTypeString Buffer of at least | ||
* PLATFORM_DEVICE_TYPE_STRING_MAX_LEN bytes | ||
* where the platform string will be stored | ||
*/ | ||
void platformGetDeviceTypeString(char *deviceTypeString); | ||
|
||
/** | ||
* Initialize the platform | ||
* | ||
* Initialize the platform discovering capabilities and returns if it has been successful | ||
* | ||
* \return 0 in case of success, 1 in case of failure. | ||
*/ | ||
int platformInit(); | ||
|
||
/** | ||
* Initialize the platform based on device type | ||
* | ||
* Generic initialization based on device type | ||
* | ||
* \return 0 in case of success, 1 in case of failure. | ||
*/ | ||
int platformInitByDeviceType(); | ||
|
||
// ************** Capabilities functions ************** | ||
// The following functions can be implemented by different platform to give | ||
// access to the current device capabilities. Not all platform has to implement | ||
// all functions | ||
bool platformHasRfx2411n(); |