2
0

fw.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #ifndef FW_H
  2. #define FW_H
  3. #include <stdarg.h>
  4. #include <stddef.h>
  5. #include <stdint.h>
  6. #include <stdbool.h>
  7. #include "picorv32.h"
  8. #include "irq.h"
  9. /* Use builtin memcpy and memset optimizations */
  10. #define memset(s,c,n) __builtin_memset(s,c,n)
  11. #define memcpy(d,s,n) __builtin_memcpy(d,s,n)
  12. #define memmove(d,s,n) __builtin_memmove(d,s,n)
  13. extern void *
  14. __memcpy_aligned(void * __restrict, const void * __restrict, size_t);
  15. #define likely(x) __builtin_expect(!!(x), 1)
  16. #define unlikely(x) __builtin_expect(!!(x), 0)
  17. /* Handy composite pointer types */
  18. typedef union xptr {
  19. uint32_t *l;
  20. uint16_t *w;
  21. uint8_t *b;
  22. void *v;
  23. size_t a;
  24. } xptr_t;
  25. typedef union xcptr {
  26. const uint32_t *l;
  27. const uint16_t *w;
  28. const uint8_t *b;
  29. const void *v;
  30. size_t a;
  31. } xcptr_t;
  32. /* The container_of construct: if p is a pointer to member m of
  33. container class c, then return a pointer to the container of which
  34. *p is a member. */
  35. #ifndef container_of
  36. # define container_of(p, c, m) ((c *)((char *)(p) - offsetof(c,m)))
  37. #endif
  38. #define offset_diff(c, m1, m2) ((ptrdiff_t)offsetof(c,m2) - (ptrdiff_t)offsetof(c,m1))
  39. #define min(a,b) (((a) < (b)) ? (a) : (b))
  40. #define max(a,b) (((a) > (b)) ? (a) : (b))
  41. #define ARRAY_SIZE (sizeof(a)/sizeof(a[0]))
  42. #define no_return void __attribute__((noreturn))
  43. #define __dram_text __attribute__((section(".dram.text")))
  44. #define __dram_rodata __attribute__((section(".dram.rodata")))
  45. #define __dram_data __attribute__((section(".dram.data")))
  46. #define __dram_bss __attribute__((section(".dram.bss")))
  47. #define __dram_noinit __attribute__((section(".dram.noinit")))
  48. extern const size_t __rom_offset;
  49. extern no_return _die(void);
  50. extern no_return exit(int);
  51. extern no_return _exit(int);
  52. extern const uint8_t _end[];
  53. extern void *_sbrk(size_t);
  54. extern uint32_t timer_irq_start;
  55. static inline uint32_t timer_count(void)
  56. {
  57. extern volatile uint32_t timer_irq_count;
  58. return timer_irq_count;
  59. }
  60. extern void init(void);
  61. extern void mount_abcdrives(void);
  62. extern void read_rtc(void);
  63. extern void write_rtc(void);
  64. extern bool do_write_rtc;
  65. extern void rtc_abc_init(void);
  66. extern void rtc_abc_io_poll(void);
  67. extern uint32_t romcopy_time[2];
  68. extern void run_test_image(void);
  69. #endif /* FW_H */