bch.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /****************************************************************************
  2. * drivers/bch/bch.h
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one or more
  5. * contributor license agreements. See the NOTICE file distributed with
  6. * this work for additional information regarding copyright ownership. The
  7. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance with the
  9. * License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. * License for the specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. ****************************************************************************/
  20. #ifndef __DRIVERS_BCH_BCH_H
  21. #define __DRIVERS_BCH_BCH_H
  22. /****************************************************************************
  23. * Included Files
  24. ****************************************************************************/
  25. #include <nuttx/config.h>
  26. #include <sys/types.h>
  27. #include <stdint.h>
  28. #include <stdbool.h>
  29. #include <nuttx/semaphore.h>
  30. #include <nuttx/fs/fs.h>
  31. /****************************************************************************
  32. * Pre-processor Definitions
  33. ****************************************************************************/
  34. #define bchlib_semgive(d) nxsem_post(&(d)->sem) /* To match bchlib_semtake */
  35. #define MAX_OPENCNT (255) /* Limit of uint8_t */
  36. /****************************************************************************
  37. * Public Types
  38. ****************************************************************************/
  39. struct bchlib_s
  40. {
  41. FAR struct inode *inode; /* I-node of the block driver */
  42. uint32_t sectsize; /* The size of one sector on the device */
  43. size_t nsectors; /* Number of sectors supported by the device */
  44. size_t sector; /* The current sector in the buffer */
  45. sem_t sem; /* For atomic accesses to this structure */
  46. uint8_t refs; /* Number of references */
  47. bool dirty; /* true: Data has been written to the buffer */
  48. bool readonly; /* true: Only read operations are supported */
  49. bool unlinked; /* true: The driver has been unlinked */
  50. FAR uint8_t *buffer; /* One sector buffer */
  51. #if defined(CONFIG_BCH_ENCRYPTION)
  52. uint8_t key[CONFIG_BCH_ENCRYPTION_KEY_SIZE]; /* Encryption key */
  53. #endif
  54. };
  55. /****************************************************************************
  56. * Public Data
  57. ****************************************************************************/
  58. #undef EXTERN
  59. #if defined(__cplusplus)
  60. #define EXTERN extern "C"
  61. extern "C"
  62. {
  63. #else
  64. #define EXTERN extern
  65. #endif
  66. EXTERN const struct file_operations bch_fops;
  67. /****************************************************************************
  68. * Public Function Prototypes
  69. ****************************************************************************/
  70. EXTERN int bchlib_semtake(FAR struct bchlib_s *bch);
  71. EXTERN int bchlib_flushsector(FAR struct bchlib_s *bch);
  72. EXTERN int bchlib_readsector(FAR struct bchlib_s *bch, size_t sector);
  73. #undef EXTERN
  74. #if defined(__cplusplus)
  75. }
  76. #endif
  77. #endif /* __DRIVERS_BCH_BCH_H */