📄 sampletask.c
字号:
/*
* description: Sample Task
* Maker : Shuichi Yanagihara
* Copyright : (C)2005,SEIKO EPSON Corp. All Rights Reserved.
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <SPRDEF.h>
#include <SPRSTS.h>
#ifdef TOYA2_C
#include <reg_mx21.h> /* Please change according to environment which you are using */
#else
#include <ap7tdmi.h> /* Please change according to environment which you are using */
#endif
#include <OSCall.h>
#include <SampleTask.h>
#include <usbh_SampleTaskAPI.h>
#include <usbd_SampleTaskAPI.h>
#include <DebugTask.h>
#include <Reg72V05.h>
#include <DebugTask.h>
#include <led_if.h>
#include <UART_FUNC.h>
#include <UART_IF.h>
/*****************************************
* Define definition
*****************************************/
#define DEVICE_MODE '1' /* Select USB Device Mode */
#define HOST_MODE '2' /* Select USB Host Mode */
#define NOTSEL_MODE '0' /* Not Select USB Mode */
/*****************************************
* Structure definition
*****************************************/
typedef struct _TASK_INFO {
unsigned char mode; // Action mode
} TASK_INFO, *PTASK_INFO;
/*****************************************
* Function prototype declaration
*****************************************/
static void SampleTaskInit( void );
static void USBH_SampleCallbackProc ( ULONG message, ULONG param0, void* vpParam );
static void USBD_SampleCallbackProc ( ULONG message, ULONG param0, void* vpParam );
static short RcvdDataCallback( unsigned short wMsg, unsigned short wStatus, void *pParam1 );
/*****************************************
* Macro definition
*****************************************/
/*****************************************
* Variable definition
*****************************************/
TASK_INFO TskInfo; // Information of task
/*=============================================================================================
// Function_Name: SampleTask
// description : Task for sample use
// Carry out switch over between host and device mode.
// argument : void
// return : void
===============================================================================================*/
#define UART_BUF_SIZE 80
#define IP 7
#define INT_UART 20 /* <TOYA2> Interrupt number of UART1 = 20 */
static unsigned char UartRcvBuf[UART_BUF_SIZE];
static unsigned char UartSndBuf[UART_BUF_SIZE];
void SampleTask( void )
{
unsigned char creClkSelect;
unsigned char creChipConfig;
volatile unsigned char temp;
CHAR inputData[80];
USHORT inputDataSize;
OS_FLGPTN flgPtn;
UART_FUNC_CONFIG sUartConfig;
/* Turn off all LED */
LED_Off(1);
LED_Off(2);
LED_Off(3);
LED_Off(4);
LED_Off(5);
LED_Off(6);
LED_Off(7);
LED_Off(8);
/* Task initialization */
SampleTaskInit();
// UART initialization
sUartConfig.wSndBufSize = UART_BUF_SIZE;
sUartConfig.pSndBufAddr = UartSndBuf;
sUartConfig.wRcvBufSize = UART_BUF_SIZE;
sUartConfig.pRcvBufAddr = UartRcvBuf;
sUartConfig.pfnRcvdEvent = RcvdDataCallback;
sUartConfig.sParam.bChannel = 1;
sUartConfig.sParam.bBaudRate = UART_FUNC_BRATE_38400;
sUartConfig.sParam.bDataBit = UART_FUNC_DATABIT_8;
sUartConfig.sParam.bParity = UART_FUNC_PRITY_NONE;
sUartConfig.sParam.bStopBit = UART_FUNC_STOPBIT_1;
sUartConfig.sParam.bFlowControl = UART_FUNC_FLOW_NONE;
UART_FuncStart( &sUartConfig );
ena_int( INT_UART );
/* 72V05 initialization */
#ifdef LITTLE_ENDIAN_C
creChipConfig = 0x06; // BusMode = 2
#else /* #ifdef LITTLE_ENDIAN_C */
creChipConfig = 0x02; // BusMode = 2
#endif /* #ifdef LITTLE_ENDIAN_C */
#ifdef TOYA2_C
creChipConfig |= 0x08; // CS Mode = 1
#endif //TOYA2_C
creClkSelect = 0x01; // ClkSelect = 1
#ifdef TOYA2_C
*(volatile unsigned char *)0xCC0000B6 = creChipConfig; // Chip config set
temp = *(volatile unsigned char *)0xCC0000B9; // Dummy reading
#else
*(volatile unsigned char *)0x010000B6 = creChipConfig; // Chip config set
temp = *(volatile unsigned char *)0x010000B9; // Dummy reading
#endif //TOYA2_C
#ifdef HOST_1PORT
creClkSelect = 0x02; // PORT1x2 = 1
#endif
RegSet(REG08_ClkSelect, creClkSelect);
RegWrite(REG08_ModeProtect, 0x00);
RegWrite(REG16_WakeupTim, 0xBBCC);
while(1)
{
/* Turn off all LED */
LED_Off(1);
LED_Off(2);
LED_Off(3);
LED_Off(4);
LED_Off(5);
LED_Off(6);
LED_Off(7);
LED_Off(8);
// Wait for selection input of host/device.
while(1) {
// Display host/device selection message
DBG_FlowStrPrint("[USB Mode Select Menu]\r\n", 3);
DBG_FlowStrPrint("[1 :USB Device Select]\r\n", 3);
DBG_FlowStrPrint("[2 :USB Host Select]\r\n", 3);
memset( inputData, 0x00, sizeof(inputData) );
DBG_FlowGetStr( inputData, &inputDataSize, 0 );
if( (inputDataSize == 1) && ((inputData[0] == DEVICE_MODE) || (inputData[0] == HOST_MODE)) ) {
break;
} else {
DBG_FlowStrPrint("\r\n[It is an input value error. Try to input it.]\r\n", 3);
}
}
if(inputData[0] == HOST_MODE) {
/* USB Host Mode Select */
DBG_FlowStrPrint("[USB Host Mode Select]\r\n", 3);
TskInfo.mode = HOST_MODE;
USBH_Sample_Create();
USBH_Sample_Active( USBH_SampleCallbackProc );
}
else {
/* USB Device Mode Select */
DBG_FlowStrPrint("[USB Device Mode Select]\r\n", 3);
TskInfo.mode = DEVICE_MODE;
USBD_Sample_Create();
USBD_Sample_Active( USBD_SampleCallbackProc );
}
if( TskInfo.mode == HOST_MODE || TskInfo.mode == DEVICE_MODE ){
/* Waiting for Host/Device selection flag set */
OS_WaiFlg( FLGID_SAMPLE, FLG_EVENT_HOSDEVSEL_SAMPLE, TWF_ORW, &flgPtn );
OS_ClrFlg( FLGID_SAMPLE, ~(FLG_EVENT_HOSDEVSEL_SAMPLE) ); /* Flag clearence */
if(TskInfo.mode == HOST_MODE) {
/* Stop HostSample task and delete it */
TskInfo.mode = NOTSEL_MODE;
USBH_Sample_Inactive();
USBH_Sample_Delete();
}
else {
/* Stop DeviceSample task and delete it */
OS_DisInt( INT_UART );
// Restrt UART controller
UART_FuncStop( sUartConfig.sParam.bChannel );
UART_FuncStart( &sUartConfig );
OS_EnaInt( INT_UART );
TskInfo.mode = NOTSEL_MODE;
USBD_Sample_Inactive();
USBD_Sample_Delete();
}
}
}
}
/*=============================================================================================
// Function_Name: SampleTaskInit
// description : Initialization process of sample task
// Carry out initialization process of sample task.
// argument : void
// return : void
===============================================================================================*/
void SampleTaskInit( void )
{
//------------------------------------------------
// Internal variable initalization
//------------------------------------------------
memset( &TskInfo, 0, sizeof( TASK_INFO ));
}
/*=============================================================================
// Function_Name: USBH_SampleCallbackProc
// description : Call back function
// argument :
// return :
// flag :
// global :
//=============================================================================
*/
void USBH_SampleCallbackProc ( ULONG message, ULONG param0, void* vpParam )
{
}
/*=============================================================================
// Function_Name: USBD_SampleCallbackProc
// description : Call back function
// argument :
// return :
// flag :
// global :
//=============================================================================
*/
void USBD_SampleCallbackProc ( ULONG message, ULONG param0, void* vpParam )
{
}
/*=============================================================================
// Function_Name: USBD_SampleCallbackProc
// description : Call back function
// argument :
// return :
// flag :
// global :
//=============================================================================
*/
short RcvdDataCallback( unsigned short wMsg, unsigned short wStatus, void *pParam1 )
{
// Receive data
return STATUS_SUCCESS;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -