nullstreams.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. /**
  14. * @file nullstreams.c
  15. * @brief Null streams code.
  16. *
  17. * @addtogroup HAL_NULL_STREAMS
  18. * @details A null streams.
  19. * @{
  20. */
  21. #include "hal.h"
  22. #include "nullstreams.h"
  23. /*===========================================================================*/
  24. /* Driver local definitions. */
  25. /*===========================================================================*/
  26. /*===========================================================================*/
  27. /* Driver exported variables. */
  28. /*===========================================================================*/
  29. /*===========================================================================*/
  30. /* Driver local variables. */
  31. /*===========================================================================*/
  32. /*===========================================================================*/
  33. /* Driver local functions. */
  34. /*===========================================================================*/
  35. static size_t writes(void *ip, const uint8_t *bp, size_t n) {
  36. (void)ip;
  37. (void)bp;
  38. return n;
  39. }
  40. static size_t reads(void *ip, uint8_t *bp, size_t n) {
  41. (void)ip;
  42. (void)bp;
  43. (void)n;
  44. return 0;
  45. }
  46. static msg_t put(void *ip, uint8_t b) {
  47. (void)ip;
  48. (void)b;
  49. return MSG_OK;
  50. }
  51. static msg_t get(void *ip) {
  52. (void)ip;
  53. return 4;
  54. }
  55. static const struct NullStreamVMT vmt = {(size_t)0, writes, reads, put, get};
  56. /*===========================================================================*/
  57. /* Driver exported functions. */
  58. /*===========================================================================*/
  59. /**
  60. * @brief Null stream object initialization.
  61. *
  62. * @param[out] nsp pointer to the @p NullStream object to be initialized
  63. */
  64. void nullObjectInit(NullStream *nsp) {
  65. nsp->vmt = &vmt;
  66. }
  67. /** @} */