rom.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // Headers to the various functions in the rom (as we discover them)
  2. #ifndef _ROM_H_
  3. #define _ROM_H_
  4. #include <stdint.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 void ets_isr_mask (unsigned intr);
  39. extern void ets_isr_unmask (unsigned intr);
  40. // Cycle-counter
  41. extern unsigned int xthal_get_ccount (void);
  42. extern int xthal_set_ccompare (unsigned int timer_number, unsigned int compare_value);
  43. // 2, 3 = reset (module dependent?), 4 = wdt
  44. int rtc_get_reset_reason (void);
  45. // Hardware exception handling
  46. struct exception_frame
  47. {
  48. uint32_t epc;
  49. uint32_t ps;
  50. uint32_t sar;
  51. uint32_t unused;
  52. union {
  53. struct {
  54. uint32_t a0;
  55. // note: no a1 here!
  56. uint32_t a2;
  57. uint32_t a3;
  58. uint32_t a4;
  59. uint32_t a5;
  60. uint32_t a6;
  61. uint32_t a7;
  62. uint32_t a8;
  63. uint32_t a9;
  64. uint32_t a10;
  65. uint32_t a11;
  66. uint32_t a12;
  67. uint32_t a13;
  68. uint32_t a14;
  69. uint32_t a15;
  70. };
  71. uint32_t a_reg[15];
  72. };
  73. uint32_t cause;
  74. };
  75. /**
  76. * C-level exception handler callback prototype.
  77. *
  78. * Does not need an RFE instruction - it is called through a wrapper which
  79. * performs state capture & restore, as well as the actual RFE.
  80. *
  81. * @param ef An exception frame containing the relevant state from the
  82. * exception triggering. This state may be manipulated and will
  83. * be applied on return.
  84. * @param cause The exception cause number.
  85. */
  86. typedef void (*exception_handler_fn) (struct exception_frame *ef, uint32_t cause);
  87. /**
  88. * Sets the exception handler function for a particular exception cause.
  89. * @param handler The exception handler to install.
  90. * If NULL, reverts to the XTOS default handler.
  91. * @returns The previous exception handler, or NULL if none existed prior.
  92. */
  93. exception_handler_fn _xtos_set_exception_handler (uint32_t cause, exception_handler_fn handler);
  94. void ets_update_cpu_frequency (uint32_t mhz);
  95. uint32_t ets_get_cpu_frequency (void);
  96. void *ets_memcpy (void *dst, const void *src, size_t n);
  97. void *ets_memmove (void *dst, const void *src, size_t n);
  98. void *ets_memset (void *dst, int c, size_t n);
  99. int ets_memcmp (const void *s1, const void *s2, size_t n);
  100. char *ets_strcpy (char *dst, const char *src);
  101. int ets_strcmp (const char *s1, const char *s2);
  102. int ets_strncmp (const char *s1, const char *s2, size_t n);
  103. char *ets_strncpy(char *dest, const char *src, size_t n);
  104. char *ets_strstr(const char *haystack, const char *needle);
  105. int ets_printf(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
  106. void ets_str2macaddr (uint8_t *dst, const char *str);
  107. void ets_timer_disarm (ETSTimer *a);
  108. void ets_timer_setfn (ETSTimer *t, ETSTimerFunc *fn, void *parg);
  109. void Cache_Read_Enable(uint32_t b0, uint32_t b1, uint32_t use_40108000);
  110. void Cache_Read_Disable(void);
  111. void ets_intr_lock(void);
  112. void ets_intr_unlock(void);
  113. int rand(void);
  114. void srand(unsigned int);
  115. /* Returns 0 on success, 1 on failure */
  116. uint8_t SPIRead(uint32_t src_addr, uint32_t *des_addr, uint32_t size);
  117. uint8_t SPIWrite(uint32_t dst_addr, const uint32_t *src, uint32_t size);
  118. uint8_t SPIEraseSector(uint32_t sector);
  119. #endif