can_api.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /** \addtogroup hal */
  2. /** @{*/
  3. /* mbed Microcontroller Library
  4. * Copyright (c) 2006-2016 ARM Limited
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #ifndef MBED_CAN_API_H
  19. #define MBED_CAN_API_H
  20. #include "device.h"
  21. #if DEVICE_CAN
  22. #include "PinNames.h"
  23. #include "PeripheralNames.h"
  24. #include "hal/can_helper.h"
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. typedef enum {
  29. IRQ_RX,
  30. IRQ_TX,
  31. IRQ_ERROR,
  32. IRQ_OVERRUN,
  33. IRQ_WAKEUP,
  34. IRQ_PASSIVE,
  35. IRQ_ARB,
  36. IRQ_BUS,
  37. IRQ_READY
  38. } CanIrqType;
  39. typedef enum {
  40. MODE_RESET,
  41. MODE_NORMAL,
  42. MODE_SILENT,
  43. MODE_TEST_LOCAL,
  44. MODE_TEST_GLOBAL,
  45. MODE_TEST_SILENT
  46. } CanMode;
  47. typedef void (*can_irq_handler)(uint32_t id, CanIrqType type);
  48. typedef struct can_s can_t;
  49. void can_init(can_t *obj, PinName rd, PinName td);
  50. void can_init_freq(can_t *obj, PinName rd, PinName td, int hz);
  51. void can_free(can_t *obj);
  52. int can_frequency(can_t *obj, int hz);
  53. void can_irq_init(can_t *obj, can_irq_handler handler, uint32_t id);
  54. void can_irq_free(can_t *obj);
  55. void can_irq_set(can_t *obj, CanIrqType irq, uint32_t enable);
  56. int can_write(can_t *obj, CAN_Message, int cc);
  57. int can_read(can_t *obj, CAN_Message *msg, int handle);
  58. int can_mode(can_t *obj, CanMode mode);
  59. int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t handle);
  60. void can_reset(can_t *obj);
  61. unsigned char can_rderror(can_t *obj);
  62. unsigned char can_tderror(can_t *obj);
  63. void can_monitor(can_t *obj, int silent);
  64. #ifdef __cplusplus
  65. };
  66. #endif
  67. #endif // MBED_CAN_API_H
  68. #endif
  69. /** @}*/