io.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* Copyright 2018 Canaan Inc.
  2. *
  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. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. #ifndef _DRIVER_IO_H
  16. #define _DRIVER_IO_H
  17. #include <stdint.h>
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. #define readb(addr) (*(volatile uint8_t *)(addr))
  22. #define readw(addr) (*(volatile uint16_t *)(addr))
  23. #define readl(addr) (*(volatile uint32_t *)(addr))
  24. #define readq(addr) (*(volatile uint64_t *)(addr))
  25. #define writeb(v, addr) \
  26. { \
  27. (*(volatile uint8_t *)(addr)) = (v); \
  28. }
  29. #define writew(v, addr) \
  30. { \
  31. (*(volatile uint16_t *)(addr)) = (v); \
  32. }
  33. #define writel(v, addr) \
  34. { \
  35. (*(volatile uint32_t *)(addr)) = (v); \
  36. }
  37. #define writeq(v, addr) \
  38. { \
  39. (*(volatile uint64_t *)(addr)) = (v); \
  40. }
  41. #ifdef __cplusplus
  42. }
  43. #endif
  44. #endif /* _DRIVER_IO_H */