You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/10/16 17:48:29 UTC
[GitHub] utzig commented on a change in pull request #1444: spiflash: Add
support for multiple chips
utzig commented on a change in pull request #1444: spiflash: Add support for multiple chips
URL: https://github.com/apache/mynewt-core/pull/1444#discussion_r225643618
##########
File path: hw/drivers/flash/spiflash/src/spiflash.c
##########
@@ -319,14 +841,93 @@ spiflash_sector_info(const struct hal_flash *hal_flash_dev, int idx,
return 0;
}
+int
+spiflash_identify(struct spiflash_dev *dev)
+{
+ int i;
+ int j;
+ uint8_t manufacturer = 0;
+ uint8_t memory_type = 0;
+ uint8_t capacity = 0;
+ int release_power_down_count = 0;
+ /* Table with unique release power down functions */
+ void (*rpd[3])(struct spiflash_dev *);
+
+ /* List of supported spi flash chips can be found in:
+ * hw/drivers/flash/spiflash/chips/sysconfig.yml
+ */
+ _Static_assert((sizeof(supported_chips) / sizeof(supported_chips[0])) > 1,
+ "At lease one spiflash chip must be specified in sysconfig with SPIFLASH_<chipid>:1");
+
+ /* Only one chip specified, no need for search*/
+ if ((sizeof(supported_chips) / sizeof(supported_chips[0])) == 2) {
+ spiflash_release_power_down(dev);
+ spiflash_read_jedec_id(dev, &manufacturer, &memory_type, &capacity);
+ /* If BSP defined SpiFlash manufacturer or memory type does not
+ * match SpiFlash is most likely not connected, connected to
+ * different pins, or of different type.
+ * It is unlikely that flash depended packaged will work correctly.
+ */
+ assert(manufacturer == supported_chips[0].fc_jedec_id.ji_manufacturer &&
+ memory_type == supported_chips[0].fc_jedec_id.ji_type &&
+ capacity == supported_chips[0].fc_jedec_id.ji_capacity);
+ if (manufacturer != supported_chips[0].fc_jedec_id.ji_manufacturer ||
+ memory_type != supported_chips[0].fc_jedec_id.ji_type ||
+ capacity != supported_chips[0].fc_jedec_id.ji_capacity) {
+ return -1;
+ }
+ dev->flash_chip = &supported_chips[0];
+ } else {
+ for (i = 0; supported_chips[i].fc_jedec_id.ji_manufacturer != 0; ++i) {
+ for (j = 0; j < release_power_down_count; ++j) {
+ if (rpd[j] == supported_chips[i].fc_release_power_down) {
+ /* release power down function same as already execute one
+ * no need check more.
+ */
+ break;
+ }
+ }
+ /* New function found, add to function table and call */
+ if (j == release_power_down_count) {
+ rpd[j] = supported_chips[i].fc_release_power_down;
+ rpd[j](dev);
+ spiflash_read_jedec_id(dev, &manufacturer, &memory_type, &capacity);
+ if ((manufacturer == 0xFF && memory_type == 0xFF && capacity == 0xFF) ||
+ (manufacturer == 0 && memory_type == 0 && capacity == 0)) {
+ /* Most likely release did not work or device is not
+ * correctly configured (wrong pins).
+ * Try another release power down method if found.
+ */
+ continue;
+ }
+ /* Something was read from flash, do not try another power up
+ * just check if chip should be supported */
+ break;
+ }
+ }
+ for (i = 0; supported_chips[i].fc_jedec_id.ji_manufacturer != 0; ++i) {
Review comment:
So this `for` loop is reusing `i` from the external `for` loop with the same test, which is not really clear to me why it's being done. Would you mind adding a comment saying why this `supported_chips[i].fc_jedec_id.ji_manufacturer` is being used again here just to make it clearer? (unless it was not supposed to be this way!)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services