[X9D] Serial debug now uses a FIFO, RTC fixed

This commit is contained in:
bernet.andre@gmail.com
2013-02-24 15:48:03 +00:00
parent 5def4849fe
commit 98100708d6
8 changed files with 54 additions and 41 deletions
+11 -3
View File
@@ -40,7 +40,8 @@
#if !defined(SIMU)
Fifo32 debugFifo;
Fifo512 debugRxFifo;
Fifo512 debugTxFifo;
// Outputs a string to the UART
void debugPuts(const char *format, ...)
@@ -54,7 +55,7 @@ void debugPuts(const char *format, ...)
const char *t = tmp;
while (*t) {
debugPutc(*t++);
debugTxFifo.push(*t++);
}
}
@@ -78,10 +79,17 @@ void debugTask(void* pdata)
uint8_t rxchar ;
for (;;) {
while (!debugFifo.pop(rxchar))
while (!debugRxFifo.pop(rxchar))
CoTickDelay(5); // 10ms
}
}
void debugTx(void)
{
uint8_t txchar;
if(debugTxFifo.pop(txchar))
debugPutc(txchar);
}
#endif
+1
View File
@@ -63,6 +63,7 @@ void dump(unsigned char *data, unsigned int size);
#define DUMP(data, size) dump(data, size)
void debugTask(void* pdata);
void debugTx(void);
#else
+5 -5
View File
@@ -37,17 +37,17 @@
#ifndef fifo_h
#define fifo_h
class Fifo32
class Fifo512
{
public:
Fifo32():
Fifo512():
widx(0),
ridx(0)
{
}
void push(uint8_t byte) {
uint32_t next = (widx+1) & 0x1f;
uint32_t next = (widx+1) & 0x1ff;
if (next != ridx) {
fifo[widx] = byte;
widx = next;
@@ -60,13 +60,13 @@ class Fifo32
}
else {
byte = fifo[ridx];
ridx = (ridx+1) & 0x1f;
ridx = (ridx+1) & 0x1ff;
return true;
}
}
protected:
uint8_t fifo[32];
uint8_t fifo[512];
volatile uint32_t widx;
volatile uint32_t ridx;
};
+2 -2
View File
@@ -39,7 +39,7 @@
#if !defined(SIMU)
extern Fifo32 debugFifo;
extern Fifo512 debugRxFifo;
/*
* Outputs a character on the UART line.
@@ -103,7 +103,7 @@ void DEBUG_UART_Stop()
extern "C" void UART0_IRQHandler()
{
debugFifo.push(CONSOLE_USART->UART_RHR);
debugRxFifo.push(CONSOLE_USART->UART_RHR);
}
#endif
+3
View File
@@ -171,6 +171,9 @@ void interrupt5ms()
pre_scale = 0 ;
per10ms();
}
#if defined(DEBUG)
debugTx();
#endif
}
extern "C" void TIM8_TRG_COM_TIM14_IRQHandler()
+10 -10
View File
@@ -105,16 +105,16 @@
// Heart Beat
#define PIN_HEART_BEAT GPIO_Pin_7 //PC.07
// Debug UART
#define RCC_AHB1Periph_GPIO_UART RCC_AHB1Periph_GPIOB
#define RCC_APB1Periph_UART_DEBUG RCC_APB1Periph_USART3
#define GPIO_UART GPIOB
#define GPIO_PIN_UART_TX GPIO_Pin_10 //PB.10
#define GPIO_PIN_UART_RX GPIO_Pin_11 //PB.11
#define GPIO_PinSource_UART_TX GPIO_PinSource10
#define GPIO_PinSource_UART_RX GPIO_PinSource11
#define GPIO_AF_UART GPIO_AF_USART3
#define UART_DEBUG USART3
// UART3
#define RCC_AHB1Periph_GPIO_UART3 RCC_AHB1Periph_GPIOB
#define RCC_APB1Periph_UART3 RCC_APB1Periph_USART3
#define GPIO_UART3 GPIOB
#define GPIO_PIN_UART3_TX GPIO_Pin_10 //PB.10
#define GPIO_PIN_UART3_RX GPIO_Pin_11 //PB.11
#define GPIO_PinSource_UART3_TX GPIO_PinSource10
#define GPIO_PinSource_UART3_RX GPIO_PinSource11
#define GPIO_AF_UART3 GPIO_AF_USART3
#define UART3 USART3
// USB_OTG
#define PIN_FS_VBUS GPIO_Pin_9 //PA.09
+11 -8
View File
@@ -41,15 +41,18 @@ void rtcSetTime(struct gtm * t)
RTC_TimeTypeDef RTC_TimeStruct;
RTC_DateTypeDef RTC_DateStruct;
RTC_TimeStructInit(&RTC_TimeStruct);
RTC_DateStructInit(&RTC_DateStruct);
RTC_TimeStruct.RTC_Hours = t->tm_hour;
RTC_TimeStruct.RTC_Minutes = t->tm_min;
RTC_TimeStruct.RTC_Seconds = t->tm_sec;
RTC_DateStruct.RTC_Year = t->tm_year - 100;
RTC_DateStruct.RTC_Month = t->tm_mon;
RTC_DateStruct.RTC_Month = t->tm_mon + 1;
RTC_DateStruct.RTC_Date = t->tm_mday;
RTC_SetTime(RTC_Format_BCD, &RTC_TimeStruct);
RTC_SetDate(RTC_Format_BCD, &RTC_DateStruct);
RTC_SetTime(RTC_Format_BIN, &RTC_TimeStruct);
RTC_SetDate(RTC_Format_BIN, &RTC_DateStruct);
}
void rtc_gettime(struct gtm * t)
@@ -57,14 +60,14 @@ void rtc_gettime(struct gtm * t)
RTC_TimeTypeDef RTC_TimeStruct;
RTC_DateTypeDef RTC_DateStruct;
RTC_GetTime(RTC_Format_BCD, &RTC_TimeStruct);
RTC_GetDate(RTC_Format_BCD, &RTC_DateStruct);
RTC_GetTime(RTC_Format_BIN, &RTC_TimeStruct);
RTC_GetDate(RTC_Format_BIN, &RTC_DateStruct);
t->tm_hour = RTC_TimeStruct.RTC_Hours;
t->tm_min = RTC_TimeStruct.RTC_Minutes;
t->tm_sec = RTC_TimeStruct.RTC_Seconds;
t->tm_year = RTC_DateStruct.RTC_Year + 100;
t->tm_mon = RTC_DateStruct.RTC_Month;
t->tm_mon = RTC_DateStruct.RTC_Month - 1;
t->tm_mday = RTC_DateStruct.RTC_Date;
}
+11 -13
View File
@@ -41,34 +41,32 @@ void uartInit(uint32_t baudrate)
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIO_UART, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART_DEBUG, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIO_UART3, ENABLE);
GPIO_PinAFConfig(GPIO_UART, GPIO_PinSource_UART_RX, GPIO_AF_UART);
GPIO_PinAFConfig(GPIO_UART, GPIO_PinSource_UART_TX, GPIO_AF_UART);
GPIO_PinAFConfig(GPIO_UART3, GPIO_PinSource_UART3_RX, GPIO_AF_UART3);
GPIO_PinAFConfig(GPIO_UART3, GPIO_PinSource_UART3_TX, GPIO_AF_UART3);
GPIO_InitStructure.GPIO_Pin = GPIO_PIN_UART_TX | GPIO_PIN_UART_RX;
GPIO_InitStructure.GPIO_Pin = GPIO_PIN_UART3_TX | GPIO_PIN_UART3_RX;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIO_UART, &GPIO_InitStructure);
GPIO_Init(GPIO_UART3, &GPIO_InitStructure);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART3, ENABLE);
USART_InitStructure.USART_BaudRate = baudrate;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_Mode = USART_Mode_Tx;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Tx;
USART_Init(UART_DEBUG, &USART_InitStructure);
USART_Cmd(UART_DEBUG, ENABLE);
USART_Init(UART3, &USART_InitStructure);
USART_Cmd(UART3, ENABLE);
}
void uartPutc(const char c)
{
USART_SendData(UART_DEBUG, c);
/* Wait for end of previous transfer */
while (USART_GetFlagStatus(UART_DEBUG, USART_FLAG_TC) == RESET);
USART_SendData(UART3, c);
}