1 #ifndef __COMMUNICATION_SYSAPI_H__ 2 #define __COMMUNICATION_SYSAPI_H__ 3 4 #ifdef __cplusplus 5 extern "C" { 6 #endif 7 8 #ifdef _WIN32 9 #include "stdio.h" 10 11 #define TRACE(str, ...) do { printf("%s/" str "\n", __FUNCTION__, __VA_ARGS__); } while (0) 12 #define ASSERT(cond, str, ...) \ 13 do { if (!(cond)) { printf("[ASSERT]%s/" str, __FUNCTION__, __VA_ARGS__); while (1); } } while (0) 14 #define TRACE_TIME(str, ...) TRACE(str, __VA_ARGS__) 15 16 int write_sig_data(const unsigned char *data, unsigned int len); 17 int write_code_data(const unsigned char *data, unsigned int len); 18 void programmer_main(void); 19 #else 20 #include "hal_trace.h" 21 #include "hal_timer.h" 22 23 #define TRACE_TIME(str, ...) TRACE("[%05u] " str, TICKS_TO_MS(hal_sys_timer_get()), ##__VA_ARGS__) 24 #endif 25 26 #define UART_OUT_SIGNAL_ID 0x19 27 enum DOWNLOAD_TRANSPORT { 28 TRANSPORT_USB, 29 TRANSPORT_UART, 30 }; 31 32 enum XFER_TIMEOUT { 33 XFER_TIMEOUT_SHORT, 34 XFER_TIMEOUT_MEDIUM, 35 XFER_TIMEOUT_LONG, 36 XFER_TIMEOUT_IDLE, 37 38 XFER_TIMEOUT_QTY 39 }; 40 41 enum UART_DMA_STATE { 42 UART_DMA_IDLE, 43 UART_DMA_START, 44 UART_DMA_DONE, 45 UART_DMA_ERROR, 46 }; 47 48 void init_transport(void); 49 void deinit_transport(void); 50 void reinit_transport(void); 51 void set_send_timeout(uint32_t timeout); 52 int secure_settings_valid(void); 53 int secure_boot_enabled(void); 54 int usb_enabled(void); 55 int usb_connected(void); 56 unsigned short get_boot_security_value(void); 57 unsigned int get_boot_key_index(void); 58 int send_data(const unsigned char *buf, unsigned int len); 59 int recv_data(unsigned char *buf, unsigned int len); 60 int recv_data_dma(unsigned char *buf, unsigned int len, unsigned int expect); 61 void recv_data_state_get(enum UART_DMA_STATE *state); 62 void recv_data_reset(void); 63 int handle_error(void); 64 int cancel_input(void); 65 66 int verify_signature(const unsigned char *key, const unsigned char *sig, const unsigned char *data, unsigned int len); 67 68 int debug_read_enabled(void); 69 int debug_write_enabled(void); 70 71 int get_flash_boot_flag(void); 72 void set_flash_boot_flag(int flag); 73 void system_reboot(void); 74 void system_shutdown(void); 75 void system_flash_boot(void); 76 void system_set_bootmode(unsigned int bootmode); 77 void system_clear_bootmode(unsigned int bootmode); 78 unsigned int system_get_bootmode(void); 79 80 void wait_trace_finished(void); 81 82 unsigned int get_current_time(void); 83 uint32_t ama_uart_get_fifo_data(uint8_t *buf); 84 uint32_t avil_len_of_the_fifo(); 85 void send_message(); 86 87 #ifdef __cplusplus 88 } 89 #endif 90 91 #endif 92 93