大理水控初始版本
diff --git a/supwisdom/sp_flash.c b/supwisdom/sp_flash.c
new file mode 100644
index 0000000..0788aed
--- /dev/null
+++ b/supwisdom/sp_flash.c
@@ -0,0 +1,123 @@
+#include "sp_constant.h"
+#include "sp_util.h"
+
+#include "sp_flash.h"
+
+uint16 sp_flash_read(uint32 addr,uint8 buf[],uint32 len)
+{
+  return HW_Flash_Read(addr,len,buf);
+}
+uint16 sp_flash_write(uint32 addr,uint8 buf[],uint32 len)
+{
+  if(addr < DEF_IAP_BASE_ADDR)
+  {
+    return RC_FLASH_NO_RIGHT;
+  }
+  return HW_Flash_NotEraseWrite(addr,len,buf);
+}
+uint16 sp_flash_erase(uint32 addr)
+{
+  if(addr < DEF_IAP_BASE_ADDR)
+  {
+    return RC_FLASH_NO_RIGHT;
+  }
+  return HW_Flash_PageErase(addr / FLASH_PAGE_SIZE);
+}
+
+/**
+**¶ÁȡһҳÊý¾Ý,È«FF±íʾÎÞÊý¾Ý
+**@param len > 128 error
+**@return ·µ»Ø0±íʾ²éÕÒÊý¾Ý³É¹¦
+**@return ·µ»Ø·Ç0±íʾÎÞÓÐЧÊý¾Ý
+**/
+uint16 sp_flash_page_read(uint32 addr,uint8 buf[],uint32 len)
+{
+  uint32 i;
+  uint32 offset = 0;
+  uint8 temp[128];
+
+  if(len > sizeof(temp))
+  {
+    return 1;
+  }
+
+  while(1)
+  {
+    i = 0;
+    sp_flash_read(addr +offset,temp, len);
+    while(i < len)
+    {
+      if(0xFF == temp[i])
+      {
+        ++i;
+      }
+      else
+      {
+        break;
+      }
+    }
+    if(len == i)
+    {
+      if(0 == offset)
+      {
+        //ÎÞÊý¾Ý
+        return 1;
+      }
+      else
+      {
+        sp_flash_read(addr +offset -len,buf, len);
+        return 0;
+      }
+    }
+    offset += len;
+    if(DEF_FLASH_PageSize < (offset +len)) //  ³¬¹ýµ±Ò³Î´ÕÒµ½·µ»Ø1
+    {
+      return 1;
+    }
+  }
+}
+/**
+**дһҳÊý¾Ý
+**@param len > 32 error
+**@return ·µ»Ø0±íʾ¼Ç¼Êý¾Ý³É¹¦
+**@return ·µ»Ø·Ç0±íʾдFLASHʧ°Ü
+**/
+uint16 sp_flash_page_write(uint32 addr,uint8 buf[],uint32 len)
+{
+  uint32 i;
+  uint32 offset = 0;
+  uint8 temp[64];
+
+  if(len > 64)
+  {
+    return 1;
+  }
+  while(1)
+  {
+    i = 0;
+    sp_flash_read(addr +offset,temp, len);
+    while(i < len)
+    {
+      if(0xFF == temp[i])
+      {
+        ++i;
+      }
+      else
+      {
+        break;
+      }
+    }
+    if(DEF_FLASH_PageSize < (offset +len)) //  ³¬¹ýµ±Ò³±íʾÒÑдÂú,²Á³ýÖØÐ´
+    {
+      sp_flash_erase(addr);
+      return sp_flash_write(addr,buf, len);
+    }
+    if(len == i)
+    {
+      //ÎÞÊý¾Ý
+      return sp_flash_write(addr +offset,buf, len);
+    }
+    offset += len;
+  }
+}
+