00001
00029
00030
00031 #include "71x_lib.h"
00032
00033 #include "roboot_if_comm.h"
00034 #include "config.h"
00035
00036
00037 #if BOOTLOADER_USART == USART_0
00038 #define USARTx UART0
00039 #define BOOTLOADER_USART_RX_PORT GPIO0
00040 #define BOOTLOADER_USART_RX_PIN (0x0001<<8)
00041 #define BOOTLOADER_USART_TX_PORT GPIO0
00042 #define BOOTLOADER_USART_TX_PIN (0x0001<<9)
00043 #elif BOOTLOADER_USART == USART_1
00044 #define USARTx UART1
00045 #define BOOTLOADER_USART_RX_PORT GPIO0
00046 #define BOOTLOADER_USART_RX_PIN (0x0001<<10)
00047 #define BOOTLOADER_USART_TX_PORT GPIO0
00048 #define BOOTLOADER_USART_TX_PIN (0x0001<<11)
00049 #elif BOOTLOADER_USART == USART_2
00050 #define USARTx UART2
00051 #define BOOTLOADER_USART_RX_PORT GPIO0
00052 #define BOOTLOADER_USART_RX_PIN (0x0001<<13)
00053 #define BOOTLOADER_USART_TX_PORT GPIO0
00054 #define BOOTLOADER_USART_TX_PIN (0x0001<<14)
00055 #elif BOOTLOADER_USART == USART_3
00056 #define USARTx UART3
00057 #define BOOTLOADER_USART_RX_PORT GPIO0
00058 #define BOOTLOADER_USART_RX_PIN (0x0001<<1)
00059 #define BOOTLOADER_USART_TX_PORT GPIO0
00060 #define BOOTLOADER_USART_TX_PIN (0x0001<<0)
00061 #else
00062 #error "Wrong USART configured"
00063 #endif
00064
00065
00066
00067
00068
00069 void CommHwInit(void)
00070 {
00071 GPIO_Config(BOOTLOADER_USART_TX_PORT, BOOTLOADER_USART_TX_PIN, GPIO_AF_PP);
00072 GPIO_Config(BOOTLOADER_USART_RX_PORT, BOOTLOADER_USART_RX_PIN, GPIO_IN_TRI_CMOS);
00073
00074 UART_Init(USARTx);
00075 UART_OnOffConfig(USARTx, ENABLE);
00076 UART_Config(USARTx, BOOTLOADER_USART_SPEED, BOOTLOADER_USART_PARITY, BOOTLOADER_USART_STOPBITS, UARTM_8D);
00077 UART_FifoConfig (USARTx, ENABLE);
00078 UART_RxConfig(USARTx , ENABLE);
00079 }
00080
00081
00082
00083
00084 void CommHwDeinit(void)
00085 {
00086 UART_Init(USARTx);
00087 }
00088
00089
00090
00091 void CommHwSendByte(uint8_t c)
00092 {
00093 UART_ByteSend(USARTx, &c);
00094 }
00095
00096
00097
00098
00099 int16_t CommHwGetByte(void)
00100 {
00101 if (USARTx->SR & UART_RxBufNotEmpty)
00102 {
00103 return (int16_t)(USARTx->RxBUFR & 0x00FFU);
00104 }
00105 else
00106 {
00107 return -1;
00108 }
00109 }
00110
00111
00112
00113 void MCUBusyDelay(void)
00114 {
00115 volatile uint32_t delay;
00116
00117 delay = 80UL;
00118
00119 while (delay--)
00120 {
00121 __asm volatile
00122 (
00123 " nop \n"
00124 " nop \n"
00125 " nop \n"
00126 " nop \n"
00127 " nop \n"
00128 " nop \n"
00129 " nop \n"
00130 " nop \n"
00131 " nop \n"
00132 " nop \n"
00133 );
00134 }
00135 }
00136