Board Dataflash driver now allows for dataflash ICs which use different shifts for...
authorDean Camera <dean@fourwalledcubicle.com>
Tue, 17 Mar 2009 04:43:34 +0000 (04:43 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Tue, 17 Mar 2009 04:43:34 +0000 (04:43 +0000)
LUFA/ChangeLog.txt
LUFA/DriverStubs/Dataflash.h
LUFA/Drivers/Board/Dataflash.h
LUFA/Drivers/Board/STK525/Dataflash.h
LUFA/Drivers/Board/STK526/Dataflash.h
LUFA/Drivers/Board/USBKEY/Dataflash.h
LUFA/MigrationInformation.txt

index 58bd9d2..27cbca8 100644 (file)
@@ -33,6 +33,8 @@
   *  - The NO_CLEARSET_FEATURE_REQUEST compile time token has been renamed to NO_FEATURELESS_CONTROL_ONLY_DEVICE, and its function expanded\r
   *    to also remove parts of the Get Status chapter 9 request to further reduce code usage\r
   *  - Makefile updated to include output giving the currently selected BOARD parameter value\r
+  *  - Board Dataflash driver now allows for dataflash ICs which use different shifts for setting the current page/byte address (thanks\r
+  *    to Kenneth Clubb)\r
   *\r
   *  \section Sec_ChangeLog090209 Version 090209\r
   *\r
index 0bef94e..41581a7 100644 (file)
                        /** Total number of pages inside each of the board's dataflash ICs. */\r
                        #define DATAFLASH_PAGES                      // TODO: Replace with the total number of pages inside one of the Dataflash ICs\r
 \r
+               /* Inline Functions: */\r
+                       /** Selects a dataflash IC from the given page number, which should range from 0 to\r
+                        *  ((DATAFLASH_PAGES * DATAFLASH_TOTALCHIPS) - 1). For boards containing only one\r
+                        *  dataflash IC, this will select DATAFLASH_CHIP1. If the given page number is outside\r
+                        *  the total number of pages contained in the boards dataflash ICs, all dataflash ICs\r
+                        *  are deselected.\r
+                        *\r
+                        *  \param PageAddress  Address of the page to manipulate, ranging from\r
+                        *                      ((DATAFLASH_PAGES * DATAFLASH_TOTALCHIPS) - 1).\r
+                        */\r
+                       static inline void Dataflash_SelectChipFromPage(const uint16_t PageAddress)\r
+                       {\r
+                               Dataflash_DeselectChip();\r
+                               \r
+                               if (PageAddress >= (DATAFLASH_PAGES * DATAFLASH_TOTALCHIPS))\r
+                                 return;\r
+\r
+                               // TODO: If more than one dataflash chip, select the correct chip from the page address here\r
+                               Dataflash_SelectChip(DATAFLASH_CHIP1);\r
+                       }\r
+\r
+                       /** Sends a set of page and buffer address bytes to the currently selected dataflash IC, for use with\r
+                        *  dataflash commands which require a complete 24-byte address.\r
+                        *\r
+                        *  \param PageAddress  Page address within the selected dataflash IC\r
+                        *  \param BufferByte   Address within the dataflash's buffer\r
+                        */\r
+                       static inline void Dataflash_SendAddressBytes(uint16_t PageAddress, const uint16_t BufferByte)\r
+                       {       \r
+                               // TODO: If more than one dataflash chip, adjust absolute page address to be correct for the current chip,\r
+                               //       also the shifts may need to be altered to suit the dataflash model being used                          \r
+                               Dataflash_SendByte(PageAddress >> 5);\r
+                               Dataflash_SendByte((PageAddress << 3) | (BufferByte >> 8));\r
+                               Dataflash_SendByte(BufferByte);\r
+                       }\r
+                       \r
 #endif\r
index 2b682d7..aa0c089 100644 (file)
        /* Includes: */\r
        #include "../AT90USBXXX/SPI.h"\r
        #include "../../Common/Common.h"\r
-       \r
-       #if !defined(BOARD)\r
-               #error BOARD must be set in makefile to a value specified in BoardTypes.h.\r
-       #elif (BOARD == BOARD_USBKEY)\r
-               #include "USBKEY/Dataflash.h"\r
-       #elif (BOARD == BOARD_STK525)\r
-               #include "STK525/Dataflash.h"\r
-       #elif (BOARD == BOARD_STK526)\r
-               #include "STK526/Dataflash.h"\r
-       #elif (BOARD == BOARD_USER)\r
-               #include "Board/Dataflash.h"\r
-       #else\r
-               #error The selected board does not contain a dataflash IC.\r
-       #endif\r
-       \r
+               \r
        /* Enable C linkage for C++ Compilers: */\r
                #if defined(__cplusplus)\r
                        extern "C" {\r
                        #define Dataflash_DeselectChip()             Dataflash_SelectChip(DATAFLASH_NO_CHIP)\r
 \r
                /* Inline Functions: */\r
-                       /** Initializes the dataflash driver (including the SPI driver) so that commands and data may be\r
-                        *  sent to an attached dataflash IC.\r
-                        *\r
-                        *  \param PrescalerMask  SPI prescaler mask, see SPI.h documentation\r
-                        */\r
-                       static inline void Dataflash_Init(const uint8_t PrescalerMask)\r
-                       {\r
-                               DATAFLASH_CHIPCS_DDR  |= DATAFLASH_CHIPCS_MASK;\r
-                               DATAFLASH_CHIPCS_PORT |= DATAFLASH_CHIPCS_MASK;\r
-\r
-                               SPI_Init(PrescalerMask, true);\r
-                       }\r
-\r
                        /** Sends a byte to the currently selected dataflash IC, and returns a byte from the dataflash.\r
                         *\r
                         *  \param Byte of data to send to the dataflash\r
                        {\r
                                return SPI_ReceiveByte();\r
                        }\r
+\r
+               /* Includes: */\r
+                       #if !defined(BOARD)\r
+                               #error BOARD must be set in makefile to a value specified in BoardTypes.h.\r
+                       #elif (BOARD == BOARD_USBKEY)\r
+                               #include "USBKEY/Dataflash.h"\r
+                       #elif (BOARD == BOARD_STK525)\r
+                               #include "STK525/Dataflash.h"\r
+                       #elif (BOARD == BOARD_STK526)\r
+                               #include "STK526/Dataflash.h"\r
+                       #elif (BOARD == BOARD_USER)\r
+                               #include "Board/Dataflash.h"\r
+                       #else\r
+                               #error The selected board does not contain a dataflash IC.\r
+                       #endif\r
+\r
+               /* Inline Functions: */\r
+                       /** Initializes the dataflash driver (including the SPI driver) so that commands and data may be\r
+                        *  sent to an attached dataflash IC.\r
+                        *\r
+                        *  \param PrescalerMask  SPI prescaler mask, see SPI.h documentation\r
+                        */\r
+                       static inline void Dataflash_Init(const uint8_t PrescalerMask)\r
+                       {\r
+                               DATAFLASH_CHIPCS_DDR  |= DATAFLASH_CHIPCS_MASK;\r
+                               DATAFLASH_CHIPCS_PORT |= DATAFLASH_CHIPCS_MASK;\r
+\r
+                               SPI_Init(PrescalerMask, true);\r
+                       }\r
                        \r
                        /** Toggles the select line of the currently selected dataflash IC, so that it is ready to receive\r
                         *  a new command.\r
                         */\r
                        static inline void Dataflash_ToggleSelectedChipCS(void)\r
                        {\r
-                               #if (DATAFLASH_TOTALCHIPS == 2)\r
-                                       uint8_t SelectedChipMask = Dataflash_GetSelectedChip();\r
+                               uint8_t SelectedChipMask = Dataflash_GetSelectedChip();\r
                                        \r
-                                       Dataflash_DeselectChip();\r
-                                       Dataflash_SelectChip(SelectedChipMask);\r
-                               #else\r
-                                       Dataflash_DeselectChip();\r
-                                       Dataflash_SelectChip(DATAFLASH_CHIP1);  \r
-                               #endif\r
+                               Dataflash_DeselectChip();\r
+                               Dataflash_SelectChip(SelectedChipMask);\r
                        }\r
 \r
                        /** Spinloops while the currently selected dataflash is busy executing a command, such as a main\r
 \r
                        /** Selects a dataflash IC from the given page number, which should range from 0 to\r
                         *  ((DATAFLASH_PAGES * DATAFLASH_TOTALCHIPS) - 1). For boards containing only one\r
-                        *  dataflash IC, this will select DATAFLASH_CHIP1. If the given page number is outside the total number\r
-                        *  of pages contained in the boards dataflash ICs, all dataflash ICs are deselected.\r
+                        *  dataflash IC, this will select DATAFLASH_CHIP1. If the given page number is outside\r
+                        *  the total number of pages contained in the boards dataflash ICs, all dataflash ICs\r
+                        *  are deselected.\r
                         *\r
                         *  \param PageAddress  Address of the page to manipulate, ranging from\r
                         *                      ((DATAFLASH_PAGES * DATAFLASH_TOTALCHIPS) - 1).\r
                         */\r
-                       static inline void Dataflash_SelectChipFromPage(const uint16_t PageAddress)\r
-                       {\r
-                               Dataflash_DeselectChip();\r
-                               \r
-                               if (PageAddress >= (DATAFLASH_PAGES * DATAFLASH_TOTALCHIPS))\r
-                                 return;\r
-\r
-                               #if (DATAFLASH_TOTALCHIPS == 2)\r
-                                       if (PageAddress & 0x01)\r
-                                         Dataflash_SelectChip(DATAFLASH_CHIP2);\r
-                                       else\r
-                                         Dataflash_SelectChip(DATAFLASH_CHIP1);\r
-                               #else\r
-                                       Dataflash_SelectChip(DATAFLASH_CHIP1);\r
-                               #endif\r
-                       }\r
+                       static inline void Dataflash_SelectChipFromPage(const uint16_t PageAddress);\r
 \r
                        /** Sends a set of page and buffer address bytes to the currently selected dataflash IC, for use with\r
                         *  dataflash commands which require a complete 24-byte address.\r
                         *  \param PageAddress  Page address within the selected dataflash IC\r
                         *  \param BufferByte   Address within the dataflash's buffer\r
                         */\r
-                       static inline void Dataflash_SendAddressBytes(uint16_t PageAddress, const uint16_t BufferByte)\r
-                       {       \r
-                               #if (DATAFLASH_TOTALCHIPS == 2)\r
-                                       PageAddress >>= 1;\r
-                               #endif\r
-\r
-                               Dataflash_SendByte(PageAddress >> 5);\r
-                               Dataflash_SendByte((PageAddress << 3) | (BufferByte >> 8));\r
-                               Dataflash_SendByte(BufferByte);\r
-                       }\r
+                       static inline void Dataflash_SendAddressBytes(uint16_t PageAddress, const uint16_t BufferByte);\r
 \r
        /* Disable C linkage for C++ Compilers: */\r
                #if defined(__cplusplus)\r
index 3f30f97..e4e2f52 100644 (file)
                        /** Total number of pages inside the board's dataflash IC. */\r
                        #define DATAFLASH_PAGES                      8192\r
 \r
+               /* Inline Functions: */\r
+                       /** Selects a dataflash IC from the given page number, which should range from 0 to\r
+                        *  ((DATAFLASH_PAGES * DATAFLASH_TOTALCHIPS) - 1). For boards containing only one\r
+                        *  dataflash IC, this will select DATAFLASH_CHIP1. If the given page number is outside\r
+                        *  the total number of pages contained in the boards dataflash ICs, all dataflash ICs\r
+                        *  are deselected.\r
+                        *\r
+                        *  \param PageAddress  Address of the page to manipulate, ranging from\r
+                        *                      ((DATAFLASH_PAGES * DATAFLASH_TOTALCHIPS) - 1).\r
+                        */\r
+                       static inline void Dataflash_SelectChipFromPage(const uint16_t PageAddress)\r
+                       {\r
+                               Dataflash_DeselectChip();\r
+                               \r
+                               if (PageAddress >= (DATAFLASH_PAGES * DATAFLASH_TOTALCHIPS))\r
+                                 return;\r
+\r
+                               Dataflash_SelectChip(DATAFLASH_CHIP1);\r
+                       }\r
+\r
+                       /** Sends a set of page and buffer address bytes to the currently selected dataflash IC, for use with\r
+                        *  dataflash commands which require a complete 24-byte address.\r
+                        *\r
+                        *  \param PageAddress  Page address within the selected dataflash IC\r
+                        *  \param BufferByte   Address within the dataflash's buffer\r
+                        */\r
+                       static inline void Dataflash_SendAddressBytes(uint16_t PageAddress, const uint16_t BufferByte)\r
+                       {       \r
+                               Dataflash_SendByte(PageAddress >> 5);\r
+                               Dataflash_SendByte((PageAddress << 3) | (BufferByte >> 8));\r
+                               Dataflash_SendByte(BufferByte);\r
+                       }\r
+                       \r
 #endif\r
index 177fefa..443c1a7 100644 (file)
                        /** Total number of pages inside the board's dataflash IC. */\r
                        #define DATAFLASH_PAGES                      8192\r
 \r
+               /* Inline Functions: */\r
+                       /** Selects a dataflash IC from the given page number, which should range from 0 to\r
+                        *  ((DATAFLASH_PAGES * DATAFLASH_TOTALCHIPS) - 1). For boards containing only one\r
+                        *  dataflash IC, this will select DATAFLASH_CHIP1. If the given page number is outside\r
+                        *  the total number of pages contained in the boards dataflash ICs, all dataflash ICs\r
+                        *  are deselected.\r
+                        *\r
+                        *  \param PageAddress  Address of the page to manipulate, ranging from\r
+                        *                      ((DATAFLASH_PAGES * DATAFLASH_TOTALCHIPS) - 1).\r
+                        */\r
+                       static inline void Dataflash_SelectChipFromPage(const uint16_t PageAddress)\r
+                       {\r
+                               Dataflash_DeselectChip();\r
+                               \r
+                               if (PageAddress >= (DATAFLASH_PAGES * DATAFLASH_TOTALCHIPS))\r
+                                 return;\r
+\r
+                               Dataflash_SelectChip(DATAFLASH_CHIP1);\r
+                       }\r
+\r
+                       /** Sends a set of page and buffer address bytes to the currently selected dataflash IC, for use with\r
+                        *  dataflash commands which require a complete 24-byte address.\r
+                        *\r
+                        *  \param PageAddress  Page address within the selected dataflash IC\r
+                        *  \param BufferByte   Address within the dataflash's buffer\r
+                        */\r
+                       static inline void Dataflash_SendAddressBytes(uint16_t PageAddress, const uint16_t BufferByte)\r
+                       {       \r
+                               Dataflash_SendByte(PageAddress >> 5);\r
+                               Dataflash_SendByte((PageAddress << 3) | (BufferByte >> 8));\r
+                               Dataflash_SendByte(BufferByte);\r
+                       }\r
+                       \r
 #endif\r
index 848ae32..2b3956f 100644 (file)
 \r
                        /** Total number of pages inside each of the board's dataflash ICs. */\r
                        #define DATAFLASH_PAGES                      8192\r
+                       \r
+               /* Inline Functions: */\r
+                       /** Selects a dataflash IC from the given page number, which should range from 0 to\r
+                        *  ((DATAFLASH_PAGES * DATAFLASH_TOTALCHIPS) - 1). For boards containing only one\r
+                        *  dataflash IC, this will select DATAFLASH_CHIP1. If the given page number is outside\r
+                        *  the total number of pages contained in the boards dataflash ICs, all dataflash ICs\r
+                        *  are deselected.\r
+                        *\r
+                        *  \param PageAddress  Address of the page to manipulate, ranging from\r
+                        *                      ((DATAFLASH_PAGES * DATAFLASH_TOTALCHIPS) - 1).\r
+                        */\r
+                       static inline void Dataflash_SelectChipFromPage(const uint16_t PageAddress)\r
+                       {\r
+                               Dataflash_DeselectChip();\r
+                               \r
+                               if (PageAddress >= (DATAFLASH_PAGES * DATAFLASH_TOTALCHIPS))\r
+                                 return;\r
+\r
+                               if (PageAddress & 0x01)\r
+                                 Dataflash_SelectChip(DATAFLASH_CHIP2);\r
+                               else\r
+                                 Dataflash_SelectChip(DATAFLASH_CHIP1);\r
+                       }\r
+\r
+                       /** Sends a set of page and buffer address bytes to the currently selected dataflash IC, for use with\r
+                        *  dataflash commands which require a complete 24-byte address.\r
+                        *\r
+                        *  \param PageAddress  Page address within the selected dataflash IC\r
+                        *  \param BufferByte   Address within the dataflash's buffer\r
+                        */\r
+                       static inline void Dataflash_SendAddressBytes(uint16_t PageAddress, const uint16_t BufferByte)\r
+                       {       \r
+                               PageAddress >>= 1;\r
+                               \r
+                               Dataflash_SendByte(PageAddress >> 5);\r
+                               Dataflash_SendByte((PageAddress << 3) | (BufferByte >> 8));\r
+                               Dataflash_SendByte(BufferByte);\r
+                       }               \r
 \r
 #endif\r
index 25bf782..a04b1b0 100644 (file)
@@ -28,6 +28,7 @@
  *\r
  *  <b>Non-USB Library Components</b>\r
  *    - The ATTR_ALWAYSINLINE function attribute macro has been renamed to ATTR_ALWAYS_INLINE.\r
+ *    - Custom board Dataflash drivers now require the implementation of Dataflash_SelectChipFromPage() and Dataflash_SendAddressBytes().\r
  *\r
  *  <b>Device Mode</b>\r
  *    - The NO_CLEARSET_FEATURE_REQUEST compile time token has been renamed to NO_FEATURELESS_CONTROL_ONLY_DEVICE, and its function expanded\r