主要是利用xprintf函式做出一個命令式的I/O讀取及觸發程式。
方便電子設計初期的訊號及功能檢查。
xprintf的設計不錯用。只使用二個I/O函式,所以很容易移植。
利用callback方式,除了連接方便外,也可以中途移轉到另一組通道去。
只要使用xdev_in()及xdev_out()就可以掛載I/O函式了。
程式如下:
#include "xprintf.h"
unsigned short usart6_buf;
unsigned int usart6_rx_cnt =0;
void USART6_IRQHandler(void)
{
if (USART_GetITStatus(USART6, USART_IT_RXNE) != RESET)
{
usart6_buf = USART_ReceiveData(USART6);
usart6_rx_cnt++;
}
}
unsigned char usart6_getc(void)
{
static unsigned int usart6_rx_out = 0;
/* Wait for Rx FIFO ready */
while (usart6_rx_out == usart6_rx_cnt) vTaskDelay(1);
usart6_rx_out++;
return (usart6_buf & 0xFF);
}
void usart6_putc(unsigned char c)
{
// while (USART_GetFlagStatus(USART6,USART_FLAG_TXE) == RESET) vTaskDelay(1);
USART_SendData(USART6, c);
vTaskDelayMs(1);
}
GPIO_TypeDef * const port[7] =
{
GPIOA,
GPIOB,
GPIOC,
GPIOD,
GPIOE,
GPIOF,
GPIOG
};
unsigned short const pin[16] =
{
GPIO_Pin_0,
GPIO_Pin_1,
GPIO_Pin_2,
GPIO_Pin_3,
GPIO_Pin_4,
GPIO_Pin_5,
GPIO_Pin_6,
GPIO_Pin_7,
GPIO_Pin_8,
GPIO_Pin_9,
GPIO_Pin_10,
GPIO_Pin_11,
GPIO_Pin_12,
GPIO_Pin_13,
GPIO_Pin_14,
GPIO_Pin_15
};
char Line[256]; /* Console input buffer */
static void vParser_Task( void *pvParameters )
{
char *ptr;
long p1;
long p2;
GPIO_TypeDef* GPIOx;
unsigned short GPIO_Pin_y;
(void) pvParameters;
// set device
USART6_Config();
xdev_in(usart6_getc);
xdev_out(usart6_putc);
xputs("\nI/O test monitor for STM32F205 evaluation board.\n");
// xprintf("LFN=%s, CP=%u\n", _USE_LFN ? "Enabled" : "Disabled", _CODE_PAGE);
for ( ;; )
{
xputc('>');
xgets(Line, sizeof Line);
ptr = Line;
switch (*ptr++)
{
case '?' : /* Show Command List */
xputs(HelpMsg);
break;
case 'r' : // Read Input
switch (*ptr++)
{
case 'a' : // ra port
GPIOx = port[0];
break;
case 'b' : // rb port
GPIOx = port[1];
break;
case 'c' : // rc port
GPIOx = port[2];
break;
case 'd' : // rd port
GPIOx = port[3];
break;
case 'e' : // re port
GPIOx = port[4];
break;
case 'f' : // rf port
GPIOx = port[5];
break;
case 'g' : // rg port
GPIOx = port[6];
break;
}
if (!xatoi(&ptr, &p1)) break;
GPIO_Pin_y = pin[p1];
GPIO_ReadInputDataBit(GPIOx, GPIO_Pin_y);
break;
case 'w' : // Write Output
switch (*ptr++)
{
case 'a' : // wa port data
GPIOx = port[0];
break;
case 'b' : // wb port data
GPIOx = port[1];
break;
case 'c' : // wc port data
GPIOx = port[2];
break;
case 'd' : // wd port data
GPIOx = port[3];
break;
case 'e' : // we port data
GPIOx = port[4];
break;
case 'f' : // wf port data
GPIOx = port[5];
break;
case 'g' : // wg port data
GPIOx = port[6];
break;
}
if (!xatoi(&ptr, &p1)) break;
if (!xatoi(&ptr, &p2)) break;
GPIO_Pin_y = pin[p1];
if ( !p2 )
{
GPIO_ResetBits(GPIOx, GPIO_Pin_y);
}
else
{
GPIO_SetBits(GPIOx, GPIO_Pin_y);
}
break;
}
vTaskDelayMs(1);
}
}
void main(void)
{
void vUSART1_Task( void *pvParameters );
GPIO_Config();
xTaskCreate( vParser_Task, ( signed char * ) "Parser", 512, NULL, tskIDLE_PRIORITY + 1, NULL );
vTaskStartScheduler();
}
沒有留言:
張貼留言