rom.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // Headers to the various functions in the rom (as we discover them)
  2. #ifndef _ROM_H_
  3. #define _ROM_H_
  4. #include "c_types.h"
  5. #include "ets_sys.h"
  6. // SHA1 is assumed to match the netbsd sha1.h headers
  7. #define SHA1_DIGEST_LENGTH 20
  8. #define SHA1_DIGEST_STRING_LENGTH 41
  9. typedef struct {
  10. uint32_t state[5];
  11. uint32_t count[2];
  12. uint8_t buffer[64];
  13. } SHA1_CTX;
  14. extern void SHA1Transform(uint32_t[5], const uint8_t[64]);
  15. extern void SHA1Init(SHA1_CTX *);
  16. extern void SHA1Final(uint8_t[SHA1_DIGEST_LENGTH], SHA1_CTX *);
  17. extern void SHA1Update(SHA1_CTX *, const uint8_t *, unsigned int);
  18. // MD5 is assumed to match the NetBSD md5.h header
  19. #define MD5_DIGEST_LENGTH 16
  20. typedef struct
  21. {
  22. uint32_t state[5];
  23. uint32_t count[2];
  24. uint8_t buffer[64];
  25. } MD5_CTX;
  26. extern void MD5Init(MD5_CTX *);
  27. extern void MD5Update(MD5_CTX *, const unsigned char *, unsigned int);
  28. extern void MD5Final(unsigned char[MD5_DIGEST_LENGTH], MD5_CTX *);
  29. // base64_encode/decode derived by Cal
  30. // Appears to match base64.h from netbsd wpa utils.
  31. extern unsigned char * base64_encode(const unsigned char *src, size_t len, size_t *out_len);
  32. extern unsigned char * base64_decode(const unsigned char *src, size_t len, size_t *out_len);
  33. // Unfortunately it that seems to require the ROM memory management to be
  34. // initialized because it uses mem_malloc
  35. extern void mem_init(void * start_addr);
  36. // Interrupt Service Routine functions
  37. typedef void (*ets_isr_fn) (void *arg);
  38. extern int ets_isr_attach (unsigned int interrupt, ets_isr_fn, void *arg);
  39. extern void ets_isr_mask (unsigned intr);
  40. extern void ets_isr_unmask (unsigned intr);
  41. // Cycle-counter
  42. extern unsigned int xthal_get_ccount (void);
  43. extern int xthal_set_ccompare (unsigned int timer_number, unsigned int compare_value);
  44. // 2, 3 = reset (module dependent?), 4 = wdt
  45. int rtc_get_reset_reason (void);
  46. // Hardware exception handling
  47. struct exception_frame
  48. {
  49. uint32_t epc;
  50. uint32_t ps;
  51. uint32_t sar;
  52. uint32_t unused;
  53. union {
  54. struct {
  55. uint32_t a0;
  56. // note: no a1 here!
  57. uint32_t a2;
  58. uint32_t a3;
  59. uint32_t a4;
  60. uint32_t a5;
  61. uint32_t a6;
  62. uint32_t a7;
  63. uint32_t a8;
  64. uint32_t a9;
  65. uint32_t a10;
  66. uint32_t a11;
  67. uint32_t a12;
  68. uint32_t a13;
  69. uint32_t a14;
  70. uint32_t a15;
  71. };
  72. uint32_t a_reg[15];
  73. };
  74. uint32_t cause;
  75. };
  76. /**
  77. * C-level exception handler callback prototype.
  78. *
  79. * Does not need an RFE instruction - it is called through a wrapper which
  80. * performs state capture & restore, as well as the actual RFE.
  81. *
  82. * @param ef An exception frame containing the relevant state from the
  83. * exception triggering. This state may be manipulated and will
  84. * be applied on return.
  85. * @param cause The exception cause number.
  86. */
  87. typedef void (*exception_handler_fn) (struct exception_frame *ef, uint32_t cause);
  88. /**
  89. * Sets the exception handler function for a particular exception cause.
  90. * @param handler The exception handler to install.
  91. * If NULL, reverts to the XTOS default handler.
  92. * @returns The previous exception handler, or NULL if none existed prior.
  93. */
  94. exception_handler_fn _xtos_set_exception_handler (uint32_t cause, exception_handler_fn handler);
  95. void ets_update_cpu_frequency (uint32_t mhz);
  96. uint32_t ets_get_cpu_frequency (void);
  97. void *ets_memcpy (void *dst, const void *src, size_t n);
  98. void *ets_memmove (void *dst, const void *src, size_t n);
  99. void *ets_memset (void *dst, int c, size_t n);
  100. int ets_memcmp (const void *s1, const void *s2, size_t n);
  101. char *ets_strcpy (char *dst, const char *src);
  102. size_t ets_strlen (const char *s);
  103. int ets_strcmp (const char *s1, const char *s2);
  104. int ets_strncmp (const char *s1, const char *s2, size_t n);
  105. char *ets_strncpy(char *dest, const char *src, size_t n);
  106. char *ets_strstr(const char *haystack, const char *needle);
  107. void ets_delay_us (uint32_t us);
  108. int ets_printf(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
  109. void ets_str2macaddr (uint8_t *dst, const char *str);
  110. void ets_timer_disarm (ETSTimer *a);
  111. void ets_timer_setfn (ETSTimer *t, ETSTimerFunc *fn, void *parg);
  112. void Cache_Read_Enable(uint32_t b0, uint32_t b1, uint32_t use_40108000);
  113. void Cache_Read_Disable(void);
  114. void ets_intr_lock(void);
  115. void ets_intr_unlock(void);
  116. void ets_install_putc1(void *routine);
  117. int rand(void);
  118. void srand(unsigned int);
  119. void uart_div_modify(int no, unsigned int freq);
  120. /* Returns 0 on success, 1 on failure */
  121. uint8_t SPIRead(uint32_t src_addr, uint32_t *des_addr, uint32_t size);
  122. #endif