mtd_nor.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * File : mtd_nor.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2012, Shanghai Real-Thread Technology Co., Ltd
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2012-5-30 Bernard the first version
  23. */
  24. #include <drivers/mtd_nor.h>
  25. #ifdef RT_USING_MTD_NOR
  26. /**
  27. * RT-Thread Generic Device Interface
  28. */
  29. static rt_err_t _mtd_init(rt_device_t dev)
  30. {
  31. return RT_EOK;
  32. }
  33. static rt_err_t _mtd_open(rt_device_t dev, rt_uint16_t oflag)
  34. {
  35. return RT_EOK;
  36. }
  37. static rt_err_t _mtd_close(rt_device_t dev)
  38. {
  39. return RT_EOK;
  40. }
  41. static rt_size_t _mtd_read(rt_device_t dev,
  42. rt_off_t pos,
  43. void *buffer,
  44. rt_size_t size)
  45. {
  46. return size;
  47. }
  48. static rt_size_t _mtd_write(rt_device_t dev,
  49. rt_off_t pos,
  50. const void *buffer,
  51. rt_size_t size)
  52. {
  53. return size;
  54. }
  55. static rt_err_t _mtd_control(rt_device_t dev, int cmd, void *args)
  56. {
  57. return RT_EOK;
  58. }
  59. #ifdef RT_USING_DEVICE_OPS
  60. const static struct rt_device_ops mtd_nor_ops =
  61. {
  62. _mtd_init,
  63. _mtd_open,
  64. _mtd_close,
  65. _mtd_read,
  66. _mtd_write,
  67. _mtd_control
  68. };
  69. #endif
  70. rt_err_t rt_mtd_nor_register_device(const char *name,
  71. struct rt_mtd_nor_device *device)
  72. {
  73. rt_device_t dev;
  74. dev = RT_DEVICE(device);
  75. RT_ASSERT(dev != RT_NULL);
  76. /* set device class and generic device interface */
  77. dev->type = RT_Device_Class_MTD;
  78. #ifdef RT_USING_DEVICE_OPS
  79. dev->ops = &mtd_nor_ops;
  80. #else
  81. dev->init = _mtd_init;
  82. dev->open = _mtd_open;
  83. dev->read = _mtd_read;
  84. dev->write = _mtd_write;
  85. dev->close = _mtd_close;
  86. dev->control = _mtd_control;
  87. #endif
  88. dev->rx_indicate = RT_NULL;
  89. dev->tx_complete = RT_NULL;
  90. /* register to RT-Thread device system */
  91. return rt_device_register(dev, name, RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STANDALONE);
  92. }
  93. #endif