From 3209b7751a054359897f0e8c0b6373f8a38eddb9 Mon Sep 17 00:00:00 2001 From: machunyu <931663271@qq.com> Date: Mon, 21 Apr 2014 10:04:14 +0800 Subject: [PATCH 01/13] Update xgpio.c --- .../CoX_Peripheral_STM32F1xx/libcox/xgpio.c | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_STM32F1xx/libcox/xgpio.c b/CoX/CoX_Peripheral/CoX_Peripheral_STM32F1xx/libcox/xgpio.c index 3a7a57b5..57af8aa8 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_STM32F1xx/libcox/xgpio.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_STM32F1xx/libcox/xgpio.c @@ -1116,3 +1116,47 @@ GPIOPinToPeripheralId(unsigned long ulPort, unsigned long ulPin) } return 0; } + +//***************************************************************************** +// +//! \brief Get the GPIO port from a short Pin. +//! +//! \param eShortPin is the base address of the GPIO port +//! +//! \note None. +//! +//! \return GPIO port address which is used by GPIO API. +// +//***************************************************************************** +unsigned long GPIOPinToPort(unsigned long ulPort, unsigned long ulPin){ + (void)ulPin; + // + // Check the arguments. + // + xASSERT(GPIOBaseValid(ulPort)); + + return ulPort; +} + +//***************************************************************************** +// +//! \brief Get the GPIO pin number from a short Pin. +//! +//! \param eShortPin is the base address of the GPIO port +//! +//! \note None. +//! +//! \return GPIO pin number which is used by GPIO API. +// +//***************************************************************************** +unsigned long +GPIOPinToPin(unsigned long ulPort, unsigned long ulPin) +{ + (void)ulPort; + // + // Check the arguments. + // + xASSERT(GPIOBaseValid(ulPort)); + + return ulPin; +} From 8af51767843a3a4bce71c8662a71bce461f381dd Mon Sep 17 00:00:00 2001 From: machunyu <931663271@qq.com> Date: Mon, 21 Apr 2014 10:05:19 +0800 Subject: [PATCH 02/13] Update xuart.h --- CoX/CoX_Peripheral/CoX_Peripheral_STM32F1xx/libcox/xuart.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_STM32F1xx/libcox/xuart.h b/CoX/CoX_Peripheral/CoX_Peripheral_STM32F1xx/libcox/xuart.h index fdfc9a0f..b86ddf24 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_STM32F1xx/libcox/xuart.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_STM32F1xx/libcox/xuart.h @@ -1914,6 +1914,8 @@ extern void UARTIntCallbackInit(unsigned long ulBase, xtEventCallback xtUARTCallback); extern unsigned long UARTIntStatus(unsigned long ulBase); extern void UARTIntClear(unsigned long ulBase, unsigned long ulIntFlags); +extern void UARTIntClear(unsigned long ulBase, unsigned long ulIntFlags); +extern unsigned long UARTRxErrorGet(unsigned long ulBase); extern void UARTDMAEnable(unsigned long ulBase, unsigned long ulDMAFlags); extern void UARTDMADisable(unsigned long ulBase, unsigned long ulDMAFlags); extern void UARTAddressSet(unsigned long ulBase, unsigned long ulAddress); From 3411dd1991aac01db287192660889de527dafe0c Mon Sep 17 00:00:00 2001 From: machunyu <931663271@qq.com> Date: Mon, 21 Apr 2014 10:05:58 +0800 Subject: [PATCH 03/13] Update xuart.c --- .../CoX_Peripheral_STM32F1xx/libcox/xuart.c | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_STM32F1xx/libcox/xuart.c b/CoX/CoX_Peripheral/CoX_Peripheral_STM32F1xx/libcox/xuart.c index 148b8937..9e4f38e9 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_STM32F1xx/libcox/xuart.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_STM32F1xx/libcox/xuart.c @@ -1691,3 +1691,61 @@ UARTModemControlClear(unsigned long ulBase, unsigned long ulControl) // xHWREG(ulBase + USART_CR3) &= ~ulControl; } + +//***************************************************************************** +// +//! \brief Gets current receiver errors. +//! +//! \param ulBase is the base address of the UART port. +//! +//! This function returns the current state of each of the 3 receiver error +//! sources. +//! +//! \return Returns a logical OR combination of the receiver error flags, +//! \b UART_RXERROR_FRAMING, \b UART_RXERROR_PARITY, \b UART_RXERROR_BREAK +//! and \b UART_RXERROR_OVERRUN. +// +//***************************************************************************** +unsigned long +UARTRxErrorGet(unsigned long ulBase) +{ + // + // Check the arguments. + // + xASSERT(UARTBaseValid(ulBase)); + + // + // Return the current value of the receive status register. + // + return(xHWREG(ulBase + USART_SR) & 0x0000000F); +} + +//***************************************************************************** +// +//! \brief Clears all reported receiver errors. +//! +//! \param ulBase is the base address of the UART port. +//! +//! This function is used to clear all receiver error conditions reported via +//! UARTRxErrorGet(). If using the overrun, framing error, parity error or +//! break interrupts, this function must be called after clearing the interrupt +//! to ensure that later errors of the same type trigger another interrupt. +//! +//! \return None. +// +//***************************************************************************** +void +UARTRxErrorClear(unsigned long ulBase) +{ + // + // Check the arguments. + // + xASSERT(UARTBaseValid(ulBase)); + + // + // Any write to the Error Clear Register will clear all bits which are + // currently set. + // + xHWREG(ulBase + USART_SR); + xHWREG(ulBase + USART_DR); +} From f79a799f751fdefff915d92e96f87e754e993223 Mon Sep 17 00:00:00 2001 From: machunyu <931663271@qq.com> Date: Mon, 21 Apr 2014 10:06:49 +0800 Subject: [PATCH 04/13] Update xsysctl.h --- CoX/CoX_Peripheral/CoX_Peripheral_STM32F1xx/libcox/xsysctl.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_STM32F1xx/libcox/xsysctl.h b/CoX/CoX_Peripheral/CoX_Peripheral_STM32F1xx/libcox/xsysctl.h index 030c58af..3729751a 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_STM32F1xx/libcox/xsysctl.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_STM32F1xx/libcox/xsysctl.h @@ -616,7 +616,7 @@ extern "C" //! |--------------------------------|----------------|-----------| //! |xSysCtlPeripheralDisable2 | Mandatory | Y | //! |--------------------------------|----------------|-----------| -//! |xSysCtlPeripheraIntNumGet | Mandatory | Y | +//! |xSysCtlPeripheralIntNumGet | Mandatory | Y | //! |--------------------------------|----------------|-----------| //! |xSysCtlClockSet | Mandatory | Y | //! |--------------------------------|----------------|-----------| @@ -781,7 +781,7 @@ extern void xSysCtlPeripheralReset2(unsigned long ulPeripheralBase); //! \return None. // //***************************************************************************** -extern unsigned long xSysCtlPeripheraIntNumGet(unsigned long ulPeripheralBase); +extern unsigned long xSysCtlPeripheralIntNumGet(unsigned long ulPeripheralBase); //***************************************************************************** // From 155e4b7604743f3cd44fb23da94084f98bd4fa27 Mon Sep 17 00:00:00 2001 From: machunyu <931663271@qq.com> Date: Mon, 21 Apr 2014 10:07:26 +0800 Subject: [PATCH 05/13] Update xsysctl.c --- CoX/CoX_Peripheral/CoX_Peripheral_STM32F1xx/libcox/xsysctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_STM32F1xx/libcox/xsysctl.c b/CoX/CoX_Peripheral/CoX_Peripheral_STM32F1xx/libcox/xsysctl.c index c8d9849a..b6ddec60 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_STM32F1xx/libcox/xsysctl.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_STM32F1xx/libcox/xsysctl.c @@ -590,7 +590,7 @@ xSysCtlPeripheralReset2(unsigned long ulPeripheralBase) // //***************************************************************************** unsigned long -xSysCtlPeripheraIntNumGet(unsigned long ulPeripheralBase) +xSysCtlPeripheralIntNumGet(unsigned long ulPeripheralBase) { unsigned long i; From cc9d3b40de9bd45d98ff7d8f128521b80485881f Mon Sep 17 00:00:00 2001 From: xinyun Date: Fri, 11 Jul 2014 17:23:13 +0800 Subject: [PATCH 06/13] NUC4xx --- .../CoX_Peripheral_NUC4xx/libcox/acmp.h | 10 +-- .../CoX_Peripheral_NUC4xx/libcox/adc.h | 26 +++++++ .../CoX_Peripheral_NUC4xx/libcox/dma.h | 26 +++++++ .../CoX_Peripheral_NUC4xx/libcox/i2c.h | 26 +++++++ .../CoX_Peripheral_NUC4xx/libcox/lowlayer.h | 4 +- .../CoX_Peripheral_NUC4xx/libcox/spi.h | 26 +++++++ .../CoX_Peripheral_NUC4xx/libcox/sysctl.h | 26 +++++++ .../CoX_Peripheral_NUC4xx/libcox/uart.h | 25 +++++++ .../CoX_Peripheral_Template/doc/mainpage.md | 3 + .../doc/xGPIO_General_Pin_IDs.md | 4 +- .../CoX_Peripheral_Template/doc/xrtc.md | 74 +++++++++---------- 11 files changed, 205 insertions(+), 45 deletions(-) diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/acmp.h b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/acmp.h index a63afc76..091b27a1 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/acmp.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/acmp.h @@ -67,14 +67,14 @@ extern "C" //***************************************************************************** // -//! \addtogroup M051_ACMP +//! \addtogroup NUC4xx_ACMP //! @{ // //***************************************************************************** //***************************************************************************** // -//! \addtogroup M051_ACMP_Analog_Src_negative M051 negative(ACMP-) Input Source +//! \addtogroup NUC4xx_ACMP_Analog_Src_negative NUC4xx negative(ACMP-) Input Source //! \brief Analog comparator negative input select. //! @{ // @@ -98,7 +98,7 @@ extern "C" //***************************************************************************** // -//! \addtogroup M051_ACMP_Comparator_IDs M051_ACMP Analog Comparator ID +//! \addtogroup NUC4xx_ACMP_Comparator_IDs NUC4xx_ACMP Analog Comparator ID //! \brief Analog Comparator ID (index). //! //! The ID index is always like 0-1, and so on. @@ -119,8 +119,8 @@ extern "C" //***************************************************************************** // -//! \addtogroup M051_ACMP_Exported_APIs M051 ACMP API -//! \brief M051 ACMP API Reference. +//! \addtogroup NUC4xx_ACMP_Exported_APIs NUC4xx ACMP API +//! \brief NUC4xx ACMP API Reference. //! @{ // //***************************************************************************** diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/adc.h b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/adc.h index 2679cf7c..e8f7ae7c 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/adc.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/adc.h @@ -1,6 +1,21 @@ #ifndef _NUC4XX_ADC_H_ #define _NUC4XX_ADC_H_ + +//***************************************************************************** +// +//! \addtogroup CoX_Peripheral_Lib +//! @{ +// +//***************************************************************************** + +//***************************************************************************** +// +//! \addtogroup ADC +//! @{ +// +//***************************************************************************** + //***************************************************************************** // //! \addtogroup NUC4xx_ADC @@ -408,6 +423,17 @@ extern void ADCCompConfigure(unsigned long ulBase, unsigned long ulComp, // //***************************************************************************** +//***************************************************************************** +// +//! @} +// +//***************************************************************************** +//***************************************************************************** +// +//! @} +// +//***************************************************************************** + //***************************************************************************** // //! @} diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/dma.h b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/dma.h index e9a91be8..74f2375b 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/dma.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/dma.h @@ -1,6 +1,21 @@ #ifndef _NUC4XX_DMA_H_ #define _NUC4XX_DMA_H_ + +//***************************************************************************** +// +//! \addtogroup CoX_Peripheral_Lib +//! @{ +// +//***************************************************************************** + +//***************************************************************************** +// +//! \addtogroup DMA +//! @{ +// +//***************************************************************************** + //***************************************************************************** // //! \addtogroup NUC4xx_DMA @@ -196,6 +211,17 @@ extern unsigned long PDMAInternalBufPointerGet(unsigned long ulChannelID); // //***************************************************************************** +//***************************************************************************** +// +//! @} +// +//***************************************************************************** +//***************************************************************************** +// +//! @} +// +//***************************************************************************** + //***************************************************************************** // //! @} diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/i2c.h b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/i2c.h index 8ead9723..62951daf 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/i2c.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/i2c.h @@ -1,6 +1,20 @@ #ifndef _NUC4XX_I2C_H_ #define _NUC4XX_I2C_H_ +//***************************************************************************** +// +//! \addtogroup CoX_Peripheral_Lib +//! @{ +// +//***************************************************************************** + +//***************************************************************************** +// +//! \addtogroup I2C +//! @{ +// +//***************************************************************************** + //***************************************************************************** // //! \addtogroup NUC4xx_I2C @@ -417,4 +431,16 @@ extern xtBoolean I2CWakeupStatusGet(unsigned long ulBase); // //***************************************************************************** +//***************************************************************************** +// +//! @} +// +//***************************************************************************** + +//***************************************************************************** +// +//! @} +// +//***************************************************************************** + #endif diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/lowlayer.h b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/lowlayer.h index 8ee1616c..28e7c506 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/lowlayer.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/lowlayer.h @@ -49,7 +49,7 @@ //***************************************************************************** // -//! \addtogroup NUC4xx_LowLayer +//! \addtogroup LowLayer //! @{ // //***************************************************************************** @@ -150,7 +150,7 @@ //***************************************************************************** // -//! \addtogroup STM32F1xx_Interrupt_Assignments STM32F1xx Interrupt Assignments +//! \addtogroup NUC4xx_Interrupt_Assignments NUC4xx Interrupt Assignments //! \brief Macro definitions for the fault/interrupt assignments. //! //! They can be used as ulInterrupt parameters with xIntEnable(), xIntDisable() diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/spi.h b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/spi.h index f2953b54..40b70c8f 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/spi.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/spi.h @@ -1,6 +1,20 @@ #ifndef _NUC4XX_SPI_H_ #define _NUC4XX_SPI_H_ +//***************************************************************************** +// +//! \addtogroup CoX_Peripheral_Lib +//! @{ +// +//***************************************************************************** + +//***************************************************************************** +// +//! \addtogroup SPI +//! @{ +// +//***************************************************************************** + //***************************************************************************** // //! \addtogroup NUC4xx_SPI @@ -487,4 +501,16 @@ extern void SPIPDuadIODisable(unsigned long ulBase); // //***************************************************************************** +//***************************************************************************** +// +//! @} +// +//***************************************************************************** + +//***************************************************************************** +// +//! @} +// +//***************************************************************************** + #endif diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/sysctl.h b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/sysctl.h index 640363f9..55d1b45a 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/sysctl.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/sysctl.h @@ -1,6 +1,20 @@ #ifndef _NUC4XX_SYSCTL_H_ #define _NUC4XX_SYSCTL_H_ +//***************************************************************************** +// +//! \addtogroup CoX_Peripheral_Lib +//! @{ +// +//***************************************************************************** + +//***************************************************************************** +// +//! \addtogroup SysCtl +//! @{ +// +//***************************************************************************** + //***************************************************************************** // //! \addtogroup NUC4xx_SysCtl @@ -857,4 +871,16 @@ extern void SysCtlHClockSet(unsigned long ulConfig); // //***************************************************************************** +//***************************************************************************** +// +//! @} +// +//***************************************************************************** + +//***************************************************************************** +// +//! @} +// +//***************************************************************************** + #endif diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/uart.h b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/uart.h index 6baa211c..ca7827ed 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/uart.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/uart.h @@ -1,6 +1,20 @@ #ifndef _NUC4XX_UART_H_ #define _NUC4XX_UART_H_ +//***************************************************************************** +// +//! \addtogroup CoX_Peripheral_Lib +//! @{ +// +//***************************************************************************** + +//***************************************************************************** +// +//! \addtogroup UART +//! @{ +// +//***************************************************************************** + //***************************************************************************** // //! \addtogroup NUC4xx_UART @@ -328,4 +342,15 @@ extern void UART485Config(unsigned long ulBase, unsigned long ulBaud, // //***************************************************************************** +//***************************************************************************** +// +//! @} +// +//***************************************************************************** + +//***************************************************************************** +// +//! @} +// +//***************************************************************************** #endif diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_Template/doc/mainpage.md b/CoX/CoX_Peripheral/CoX_Peripheral_Template/doc/mainpage.md index a84d0cfd..185b8570 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_Template/doc/mainpage.md +++ b/CoX/CoX_Peripheral/CoX_Peripheral_Template/doc/mainpage.md @@ -26,7 +26,10 @@ CoX develop manual - \ref xSPI_page - \ref xPWM_page - \ref xADC_page + - [xRTC](@ref xRTC_document_md) . + +more please refer to [xGPIO interrupt number config ID in MD file](@ref xRTC_document_md). Features ---------- diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_Template/doc/xGPIO_General_Pin_IDs.md b/CoX/CoX_Peripheral/CoX_Peripheral_Template/doc/xGPIO_General_Pin_IDs.md index 1f687151..bf1507ac 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_Template/doc/xGPIO_General_Pin_IDs.md +++ b/CoX/CoX_Peripheral/CoX_Peripheral_Template/doc/xGPIO_General_Pin_IDs.md @@ -5,7 +5,7 @@ -xGPIO document +xGPIO document {#xGPIO_document_md} ====== 本篇文章主要讲解,CoX.GPIO的规范,包括: - 宏参数 @@ -558,6 +558,8 @@ NUC4xx GPIO UART MAP | | UART5RX | PB10 PD15 | + + xGPIO DAC MAP {#CoX_DAC_MAP} ========= diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_Template/doc/xrtc.md b/CoX/CoX_Peripheral/CoX_Peripheral_Template/doc/xrtc.md index 435e6056..d1a6cf8e 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_Template/doc/xrtc.md +++ b/CoX/CoX_Peripheral/CoX_Peripheral_Template/doc/xrtc.md @@ -1,33 +1,33 @@ -\page xRTC_page xRTC page + [TOC] -xRTC document +xRTC document {#xRTC_document_md} ====== -ƪҪ⣬CoX.RTCĹ淶 -- - - 壿 - - ĸAPI - - ʽ - - ϵеʵ -- API - - ԭ - - ҪʵֵĹܺÿ - - ֮Ӧãܣ +本篇文章主要讲解,CoX.RTC的规范,包括: +- 宏参数 + - 参数的意义? + - 传给哪个API? + - 参数的形式 + - 各个厂商系列的实现情况 +- API函数 + - 函数原型 + - 需要实现的功能和每个参数的意义 + - 函数之间的组合应用(功能) xRTC Interrupt Type {#xRTC_INT_Type_md} ================ -жϵͣRTC˵жͣʱжϣCoXж϶Ϊһ룩жϺжϡ -ʽΪ̶ĺƣ +这个参数定义中断的类型:对于RTC来说,中断有三种类型,时间中断(CoX将这个中断定义为一秒)、闹钟中断和溢出中断。 +参数的形式为固定的宏名称: - \ref xRTC_INT_SECOND - \ref xRTC_INT_ALARM - \ref xRTC_INT_OVERFLOW - API \ref xRTCIntEnable() API \ref xRTCIntDisable() ulIntType -ЩϵʵܣȻЩϵֻǰܣǸϵеʵֵ +这个参数是 API \ref xRTCIntEnable() 和 API \ref xRTCIntDisable() 的 ulIntType参数。 +有些系列实现了这三个功能,然后有些系列只有前两个功能,下面是各个系列的实现的情况。 | xRTC Interrupts |LPC17xx|STM32F1xx|NUC1xx/NUC2xx/M051/Mini51|KLx |HT32F125x|HT32F175x| |:----------------:|:-----:|:-------:|:-----------------------:|:-------:|:-------:|:-------:| @@ -38,16 +38,16 @@ xRTC Interrupt Type {#xRTC_INT_Type_md} xRTC Interrupt Event {#xRTC_INT_Event_md} ======== -жϵ¼RTCʱ ж ǰ жԴ ʲô -ж¼ͣһ¡ -ʽΪ̶ĺƣ +这个参数是中断的事件,当RTC发生时 用这个参数来判断 当前的 中断源 是什么。 +中断事件和类型,基本保持一致。 +参数的形式为固定的宏名称: - \ref xRTC_EVENT_SECOND - \ref xRTC_EVENT_ALARM - \ref xRTC_EVENT_OVERFLOW -ڻصʹãжѾжԴ +这个将在回调函数中使用,以判断已经发生的中断源。 -ЩϵʵܣȻЩϵֻǰܣǸϵеʵֵ +有些系列实现了这三个功能,然后有些系列只有前两个功能,下面是各个系列的实现的情况。 | xRTC Event |LPC17xx|STM32F1xx|NUC1xx/NUC2xx/M051/Mini51|KLx |HT32F125x|HT32F175x| |:------------------:|:-----:|:-------:|:-----------------------:|:-------:|:-------:|:-------:| @@ -58,9 +58,9 @@ xRTC Interrupt Event {#xRTC_INT_Event_md} xRTC Day Week {#xRTC_Day_Week_md} ======== -ڶڣö +这组宏用于定义星期,枚举 星期日 到 星期六 -ʽΪ̶ĺƣ +参数的形式为固定的宏名称: - \ref xRTC_WEEK_SUNDAY - \ref xRTC_WEEK_MONDAY - \ref xRTC_WEEK_TUESDAY @@ -69,7 +69,7 @@ xRTC Day Week {#xRTC_Day_Week_md} - \ref xRTC_WEEK_FRIDAY - \ref xRTC_WEEK_SATURDAY -콫Ϊ xtTime.ulWDay \ref xRTCTimeRead(), \ref xRTCTimeWrite() +这组红将作为 xtTime.ulWDay 参数传入 函数 \ref xRTCTimeRead(), \ref xRTCTimeWrite() | tTime.ulWDay | All Series | |--------------------------|------------------------| @@ -85,19 +85,19 @@ xRTC Day Week {#xRTC_Day_Week_md} xRTC Year Offset {#xRTC_Year_Offset_md} ======= -Щ RTC ʵϾһ 32 λļΪ˽תΪʱ䣬Ҫ -һת̣ 32 λܱʾޣܱʾ136ࣩΪܱʾǰ2014 -Ҫһ ̶ƫ磬ƫΪ2000򵱼ֵΪ14ʱʾ2014110ʱ00롣 -ƫƽӰ 32 λļ RTCʱڷΧ +由于有些 RTC 实际上就是一个 32 位的计数器,所以为了将这个鬼计数器转化为具体的时间,需要 +一个转换过程,而 32 位数据能表示的年份有限(最多能表示136年多),所以为了能表示当前公历(比如2014) +需要定义一个 固定偏移量。比如,偏移量为2000,则当计数值为14年时,表示2014年1月1日0时0分0秒。 +这个偏移将影响 32 位的计数器 类型RTC的时间调节范围。 -ʽΪ̶ĺƣ +参数的形式为固定的宏名称: - \ref xRTC_YEAR_OFFSET -ʱĵڷΪ xRTC_YEAR_OFFSET <= time <= xRTC_YEAR_OFFSET+136 +时间的调节分为 xRTC_YEAR_OFFSET <= time <= xRTC_YEAR_OFFSET+136 -CoX һĬֵΪ2000 +CoX 定义了一个默认值为2000 -Ǹϵеʵ +下面是各个系列的实现情况 | xRTC_Year_Offset | LPC17xx |STM32F1xx|NUC1xx/NUC2xx/M051/Mini51|KLx |HT32F125x|HT32F175x| |--------------------------|---------|:-------:|:-----------------------:|:-------:|:-------:|:-------:| | xRTC_YEAR_OFFSET | N | **Y** | **Y** | **Y** | **Y** | **Y** | @@ -105,9 +105,9 @@ CoX xRTC Time Type {#xRTC_Time_Type_md} ====== - ǰʱ ӵʱ÷ʽһ һʾǰʲô ʱ ӣ +在设置 当前时间 和 设置 闹钟的时候,由于设置方式一样,所以 用了一个参数表示,当前究竟是什么操作(是在设置 时间 还是闹钟)? -ʽΪ̶ĺƣ +参数的形式为固定的宏名称: - \ref xRTC_TIME_CURRENT - \ref xRTC_TIME_ALARM @@ -119,7 +119,7 @@ xRTC Time Type {#xRTC_Time_Type_md} xRTC Exported Types {#xRTC_Exported_Types_md} ========== -CoX ΪRTCһ xtime Ľṹ壬ýṹ ʱ ʱ ڡ +CoX 为RTC定义了一个 xtime 的结构体,该结构体包含了组成 时间的 年月日 时分秒 和星期。 xRTC API {#xRTC_Exported_APIs_md} @@ -136,9 +136,9 @@ xRTC API {#xRTC_Exported_APIs_md} | \ref xRTCStart | Y | | \ref xRTCStop | Y | -\note xRTCTimeInit ʵֵʱҪRTC ʱ жϼΪһ롣 +\note xRTCTimeInit 在实现的时候要将RTC 的时间 中断间隔设置为一秒。 -\note Щϵ Ҫ xRTCStart xRTCStopô ʵּɡ +\note 有些系列 不需要 xRTCStart 和 xRTCStop,那么 这两个函数空实现即可。 From 1998d541ef69bb0b355049606fd89b38457c8e1e Mon Sep 17 00:00:00 2001 From: xinyun Date: Thu, 24 Jul 2014 09:18:58 +0800 Subject: [PATCH 07/13] change file name --- .../all/project/template/coide/main.c | 3 +- .../project/template/coide/template.coproj | 61 ++++---- .../libcox/{xacmp.c => acmp.c} | 4 +- .../libcox/{xadc.c => adc.c} | 4 +- .../libcox/{xcore.c => core.c} | 2 +- .../libcox/{xdebug.c => debug.c} | 2 +- .../libcox/{xgpio.c => gpio.c} | 6 +- .../CoX_Peripheral_M051DN/libcox/gpio.h | 57 ++++++++ .../libcox/{xhw_acmp.h => hw_acmp.h} | 2 +- .../libcox/{xhw_adc.h => hw_adc.h} | 2 +- .../libcox/{xhw_gpio.h => hw_gpio.h} | 2 +- .../libcox/{xhw_i2c.h => hw_i2c.h} | 2 +- .../libcox/{xhw_pwm.h => hw_pwm.h} | 2 +- .../libcox/{xhw_spi.h => hw_spi.h} | 2 +- .../libcox/{xhw_sysctl.h => hw_sysctl.h} | 2 +- .../libcox/{xhw_timer.h => hw_timer.h} | 2 +- .../libcox/{xhw_uart.h => hw_uart.h} | 2 +- .../libcox/{xhw_wdt.h => hw_wdt.h} | 2 +- .../libcox/{xi2c.c => i2c.c} | 6 +- .../libcox/{xpwm.c => pwm.c} | 6 +- .../libcox/{xspi.c => spi.c} | 6 +- .../libcox/{xsysctl.c => sysctl.c} | 4 +- .../libcox/{xtimer.c => timer.c} | 6 +- .../libcox/{xuart.c => uart.c} | 6 +- .../libcox/{xwdt.c => wdt.c} | 6 +- .../libcox/{CoX_base.h => xPort.h} | 4 +- .../libcox/{xacmp.c => acmp.c} | 4 +- .../libcox/{xadc.c => adc.c} | 4 +- .../libcox/{xcore.c => core.c} | 0 .../libcox/{xdma.c => dma.c} | 0 .../libcox/{xgpio.c => gpio.c} | 6 +- .../CoX_Peripheral_NUC1xxDN/libcox/gpio.h | 97 +++++++++++++ .../libcox/{xhw_acmp.h => hw_acmp.h} | 2 +- .../libcox/{xhw_adc.h => hw_adc.h} | 2 +- .../libcox/{xhw_dma.h => hw_dma.h} | 0 .../libcox/{xhw_gpio.h => hw_gpio.h} | 2 +- .../libcox/{xhw_i2c.h => hw_i2c.h} | 2 +- .../libcox/{xhw_pwm.h => hw_pwm.h} | 2 +- .../libcox/{xhw_rtc.h => hw_rtc.h} | 0 .../libcox/{xhw_spi.h => hw_spi.h} | 2 +- .../libcox/{xhw_sysctl.h => hw_sysctl.h} | 2 +- .../libcox/{xhw_timer.h => hw_timer.h} | 2 +- .../libcox/{xhw_uart.h => hw_uart.h} | 2 +- .../libcox/{xhw_wdt.h => hw_wdt.h} | 2 +- .../libcox/{xi2c.c => i2c.c} | 6 +- .../libcox/{xpwm.c => pwm.c} | 6 +- .../libcox/{xrtc.c => rtc.c} | 0 .../libcox/{xspi.c => spi.c} | 6 +- .../libcox/{xsysctl.c => sysctl.c} | 4 +- .../libcox/{xtimer.c => timer.c} | 6 +- .../libcox/{xuart.c => uart.c} | 6 +- .../libcox/{xwdt.c => wdt.c} | 6 +- .../CoX_Peripheral_NUC1xxDN/libcox/xdebug.c | 66 --------- .../CoX_Peripheral_NUC1xxDN/libcox/xdebug.h | 134 ------------------ .../CoX_Peripheral_NUC4xx/libcox/xPort.h | 2 +- .../CoX_Peripheral_NUC4xx/libcox/xdma.c | 54 +++---- .../CoX_Peripheral_Template/inc/CoX.h | 4 +- .../CoX_Peripheral_Template/inc/xacmp.h | 4 +- .../CoX_Peripheral_Template/inc/xadc.h | 4 +- .../CoX_Peripheral_Template/inc/xcore.h | 4 +- .../CoX_Peripheral_Template/inc/xdebug.c | 5 +- .../CoX_Peripheral_Template/inc/xdebug.h | 4 +- .../CoX_Peripheral_Template/inc/xdma.h | 4 +- .../CoX_Peripheral_Template/inc/xgpio.h | 4 +- .../CoX_Peripheral_Template/inc/xhw_nvic.h | 4 +- .../CoX_Peripheral_Template/inc/xhw_types.h | 4 +- .../CoX_Peripheral_Template/inc/xi2c.h | 4 +- .../CoX_Peripheral_Template/inc/xlowlayer.h | 4 +- .../CoX_Peripheral_Template/inc/xpwm.h | 4 +- .../CoX_Peripheral_Template/inc/xrtc.h | 4 +- .../CoX_Peripheral_Template/inc/xspi.h | 4 +- .../CoX_Peripheral_Template/inc/xsysctl.h | 4 +- .../CoX_Peripheral_Template/inc/xtimer.h | 4 +- .../CoX_Peripheral_Template/inc/xuart.h | 4 +- .../CoX_Peripheral_Template/inc/xwdt.h | 4 +- 75 files changed, 333 insertions(+), 374 deletions(-) rename CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/{xacmp.c => acmp.c} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/{xadc.c => adc.c} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/{xcore.c => core.c} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/{xdebug.c => debug.c} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/{xgpio.c => gpio.c} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/{xhw_acmp.h => hw_acmp.h} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/{xhw_adc.h => hw_adc.h} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/{xhw_gpio.h => hw_gpio.h} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/{xhw_i2c.h => hw_i2c.h} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/{xhw_pwm.h => hw_pwm.h} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/{xhw_spi.h => hw_spi.h} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/{xhw_sysctl.h => hw_sysctl.h} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/{xhw_timer.h => hw_timer.h} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/{xhw_uart.h => hw_uart.h} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/{xhw_wdt.h => hw_wdt.h} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/{xi2c.c => i2c.c} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/{xpwm.c => pwm.c} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/{xspi.c => spi.c} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/{xsysctl.c => sysctl.c} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/{xtimer.c => timer.c} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/{xuart.c => uart.c} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/{xwdt.c => wdt.c} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/{CoX_base.h => xPort.h} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/{xacmp.c => acmp.c} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/{xadc.c => adc.c} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/{xcore.c => core.c} (100%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/{xdma.c => dma.c} (100%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/{xgpio.c => gpio.c} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/{xhw_acmp.h => hw_acmp.h} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/{xhw_adc.h => hw_adc.h} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/{xhw_dma.h => hw_dma.h} (100%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/{xhw_gpio.h => hw_gpio.h} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/{xhw_i2c.h => hw_i2c.h} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/{xhw_pwm.h => hw_pwm.h} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/{xhw_rtc.h => hw_rtc.h} (100%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/{xhw_spi.h => hw_spi.h} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/{xhw_sysctl.h => hw_sysctl.h} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/{xhw_timer.h => hw_timer.h} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/{xhw_uart.h => hw_uart.h} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/{xhw_wdt.h => hw_wdt.h} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/{xi2c.c => i2c.c} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/{xpwm.c => pwm.c} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/{xrtc.c => rtc.c} (100%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/{xspi.c => spi.c} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/{xsysctl.c => sysctl.c} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/{xtimer.c => timer.c} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/{xuart.c => uart.c} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/{xwdt.c => wdt.c} (99%) delete mode 100644 CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xdebug.c delete mode 100644 CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xdebug.h diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/all/project/template/coide/main.c b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/all/project/template/coide/main.c index bf6465a0..991ebc69 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/all/project/template/coide/main.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/all/project/template/coide/main.c @@ -1,5 +1,6 @@ - +#include "CoX.h" int main() { + xSysCtlDelay(1000); while(1); } diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/all/project/template/coide/template.coproj b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/all/project/template/coide/template.coproj index 1149b443..ea0df44f 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/all/project/template/coide/template.coproj +++ b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/all/project/template/coide/template.coproj @@ -1,7 +1,7 @@ - + @@ -22,10 +22,11 @@ - + - - - - - - - + + + - + + + + - - - + + + + - + + + - + + + - - + + - + + - - + - + - - + + + - \ No newline at end of file diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xacmp.c b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/acmp.c similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xacmp.c rename to CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/acmp.c index 78b7f308..0e3b7962 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xacmp.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/acmp.c @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xacmp.c +//! \file acmp.c //! \brief Driver for the analog comparator. //! \version V2.1.1.0 //! \date 1/3/2012 @@ -11,7 +11,7 @@ // //***************************************************************************** -#include "xhw_acmp.h" +#include "hw_acmp.h" #include "CoX.h" diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xadc.c b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/adc.c similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xadc.c rename to CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/adc.c index 49bb17a1..af7b7418 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xadc.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/adc.c @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xadc.c +//! \file adc.c //! \brief Driver for the ADC Controller. //! \version V2.1.1.0 //! \date 12/29/2011 @@ -37,7 +37,7 @@ // //***************************************************************************** -#include "xhw_adc.h" +#include "hw_adc.h" #include "CoX.h" static xtEventCallback g_pfnADCHandlerCallbacks[1] = {0}; diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xcore.c b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/core.c similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xcore.c rename to CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/core.c index 2d3f92c8..ff7604e5 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xcore.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/core.c @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xcore.c +//! \file core.c //! \brief Instruction wrappers for special CPU instructions. //! Driver for the NVIC Interrupt Controller. //! Driver for the SysTick driver. diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xdebug.c b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/debug.c similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xdebug.c rename to CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/debug.c index 96d15b10..4de3236d 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xdebug.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/debug.c @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xdebug.h +//! \file debug.h //! \brief Drivers for assisting debug of the peripheral library. //! \version V2.1.1.0 //! \date 12/20/2011 diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xgpio.c b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/gpio.c similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xgpio.c rename to CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/gpio.c index dab80b37..ea8e558f 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xgpio.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/gpio.c @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xgpio.c +//! \file gpio.c //! \brief Driver for the GPIO controller //! \version V2.1.1.0 //! \date 12/27/2011 @@ -38,8 +38,8 @@ //***************************************************************************** #include "CoX.h" -#include "xhw_sysctl.h" -#include "xhw_gpio.h" +#include "hw_sysctl.h" +#include "hw_gpio.h" typedef struct diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/gpio.h b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/gpio.h index 49fd6dfd..16fb4c8f 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/gpio.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/gpio.h @@ -315,6 +315,63 @@ extern "C" // //***************************************************************************** +//***************************************************************************** +// +//! \addtogroup M051_GP_Short_Pin M051 General Purpose Short Pin +//! @{ +// +//***************************************************************************** +#define GPA0 GPIO_PORTA_BASE, GPIO_PIN_0 +#define GPA1 GPIO_PORTA_BASE, GPIO_PIN_1 +#define GPA2 GPIO_PORTA_BASE, GPIO_PIN_2 +#define GPA3 GPIO_PORTA_BASE, GPIO_PIN_3 +#define GPA4 GPIO_PORTA_BASE, GPIO_PIN_4 +#define GPA5 GPIO_PORTA_BASE, GPIO_PIN_5 +#define GPA6 GPIO_PORTA_BASE, GPIO_PIN_6 +#define GPA7 GPIO_PORTA_BASE, GPIO_PIN_7 + +#define GPB0 GPIO_PORTB_BASE, GPIO_PIN_0 +#define GPB1 GPIO_PORTB_BASE, GPIO_PIN_1 +#define GPB2 GPIO_PORTB_BASE, GPIO_PIN_2 +#define GPB3 GPIO_PORTB_BASE, GPIO_PIN_3 +#define GPB4 GPIO_PORTB_BASE, GPIO_PIN_4 +#define GPB5 GPIO_PORTB_BASE, GPIO_PIN_5 +#define GPB6 GPIO_PORTB_BASE, GPIO_PIN_6 +#define GPB7 GPIO_PORTB_BASE, GPIO_PIN_7 + +#define GPC0 GPIO_PORTC_BASE, GPIO_PIN_0 +#define GPC1 GPIO_PORTC_BASE, GPIO_PIN_1 +#define GPC2 GPIO_PORTC_BASE, GPIO_PIN_2 +#define GPC3 GPIO_PORTC_BASE, GPIO_PIN_3 +#define GPC4 GPIO_PORTC_BASE, GPIO_PIN_4 +#define GPC5 GPIO_PORTC_BASE, GPIO_PIN_5 +#define GPC6 GPIO_PORTC_BASE, GPIO_PIN_6 +#define GPC7 GPIO_PORTC_BASE, GPIO_PIN_7 + +#define GPD0 GPIO_PORTD_BASE, GPIO_PIN_0 +#define GPD1 GPIO_PORTD_BASE, GPIO_PIN_1 +#define GPD2 GPIO_PORTD_BASE, GPIO_PIN_2 +#define GPD3 GPIO_PORTD_BASE, GPIO_PIN_3 +#define GPD4 GPIO_PORTD_BASE, GPIO_PIN_4 +#define GPD5 GPIO_PORTD_BASE, GPIO_PIN_5 +#define GPD6 GPIO_PORTD_BASE, GPIO_PIN_6 +#define GPD7 GPIO_PORTD_BASE, GPIO_PIN_7 + +#define GPE0 GPIO_PORTE_BASE, GPIO_PIN_0 +#define GPE1 GPIO_PORTE_BASE, GPIO_PIN_1 +#define GPE2 GPIO_PORTE_BASE, GPIO_PIN_2 +#define GPE3 GPIO_PORTE_BASE, GPIO_PIN_3 +#define GPE4 GPIO_PORTE_BASE, GPIO_PIN_4 +#define GPE5 GPIO_PORTE_BASE, GPIO_PIN_5 +#define GPE6 GPIO_PORTE_BASE, GPIO_PIN_6 +#define GPE7 GPIO_PORTE_BASE, GPIO_PIN_7 + +//***************************************************************************** +// +//! @} +// +//***************************************************************************** + //***************************************************************************** // //! \addtogroup M051_GPIO_Pin_Config M051 GPIO Pin Config diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xhw_acmp.h b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/hw_acmp.h similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xhw_acmp.h rename to CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/hw_acmp.h index ccdb889c..c79bd0be 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xhw_acmp.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/hw_acmp.h @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xhw_acmp.h +//! \file hw_acmp.h //! \brief Macros used when accessing the comparator hardware. //! \version V2.1.1.0 //! \date 1/3/2012 diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xhw_adc.h b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/hw_adc.h similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xhw_adc.h rename to CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/hw_adc.h index 43880eda..bda15ba4 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xhw_adc.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/hw_adc.h @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xhw_adc.h +//! \file hw_adc.h //! \brief Macros used when accessing the ADC hardware. //! \version V2.1.1.0 //! \date 12/29/2011 diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xhw_gpio.h b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/hw_gpio.h similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xhw_gpio.h rename to CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/hw_gpio.h index bfa16ca9..be8cf99d 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xhw_gpio.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/hw_gpio.h @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xhw_gpio.h +//! \file hw_gpio.h //! \brief Macros used when accessing the GPIO control hardware. //! \version V2.1.1.0 //! \date 12/23/2011 diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xhw_i2c.h b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/hw_i2c.h similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xhw_i2c.h rename to CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/hw_i2c.h index dc05e3fe..d42877bf 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xhw_i2c.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/hw_i2c.h @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xhw_i2c.h +//! \file hw_i2c.h //! \brief Macros and defines used when accessing the I2C hardware. //! \version V2.1.1.0 //! \date 12/30/2011 diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xhw_pwm.h b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/hw_pwm.h similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xhw_pwm.h rename to CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/hw_pwm.h index 2eb4b24a..36e1a986 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xhw_pwm.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/hw_pwm.h @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xhw_pwm.h +//! \file hw_pwm.h //! \brief Macros and defines used when accessing the PWM hardware. //! \version V2.1.1.0 //! \date 12/27/2011 diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xhw_spi.h b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/hw_spi.h similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xhw_spi.h rename to CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/hw_spi.h index 1f5cb117..39fc7f34 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xhw_spi.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/hw_spi.h @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xhw_spi.h +//! \file hw_spi.h //! \brief Macros used when accessing the SPI hardware. //! \version V2.1.1.0 //! \date 12/27/2011 diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xhw_sysctl.h b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/hw_sysctl.h similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xhw_sysctl.h rename to CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/hw_sysctl.h index 147ed93f..a9babb00 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xhw_sysctl.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/hw_sysctl.h @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xhw_sysctl.h +//! \file hw_sysctl.h //! \brief Macros used when accessing the system control hardware. //! \version V2.1.1.0 //! \date 12/26/2011 diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xhw_timer.h b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/hw_timer.h similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xhw_timer.h rename to CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/hw_timer.h index b6c50b0f..7a05528b 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xhw_timer.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/hw_timer.h @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xhw_timer.h +//! \file hw_timer.h //! \brief Macros and defines used when accessing the TIMER hardware. //! \version V2.1.1.0 //! \date 12/31/2011 diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xhw_uart.h b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/hw_uart.h similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xhw_uart.h rename to CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/hw_uart.h index f69177ac..15bd5803 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xhw_uart.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/hw_uart.h @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xhw_uart.h +//! \file hw_uart.h //! \brief Macros used when accessing the UART hardware. //! \version V2.1.1.0 //! \date 12/28/2011 diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xhw_wdt.h b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/hw_wdt.h similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xhw_wdt.h rename to CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/hw_wdt.h index f94fd110..9bb19e9e 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xhw_wdt.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/hw_wdt.h @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xhw_wdt.h +//! \file hw_wdt.h //! \brief Macros and defines used when accessing the WATCHDOG hardware. //! \version V2.1.1.0 //! \date 1/3/2012 diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xi2c.c b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/i2c.c similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xi2c.c rename to CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/i2c.c index 7c8beefc..95e142bc 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xi2c.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/i2c.c @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xi2c.c +//! \file i2c.c //! \brief Driver for the I2C //! \version V2.2.1.0 //! \date 11/15/2013 @@ -37,8 +37,8 @@ // //***************************************************************************** #include "CoX.h" -#include "xhw_sysctl.h" -#include "xhw_i2c.h" +#include "hw_sysctl.h" +#include "hw_i2c.h" //***************************************************************************** diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xpwm.c b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/pwm.c similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xpwm.c rename to CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/pwm.c index d554d7e5..d116ac75 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xpwm.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/pwm.c @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xpwm.c +//! \file pwm.c //! \brief Driver for the PWM //! \version V2.2.1.0 //! \date 11/15/2013 @@ -38,8 +38,8 @@ //***************************************************************************** #include "CoX.h" -#include "xhw_sysctl.h" -#include "xhw_pwm.h" +#include "hw_sysctl.h" +#include "hw_pwm.h" diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xspi.c b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/spi.c similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xspi.c rename to CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/spi.c index c3e6077d..b4b42a4d 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xspi.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/spi.c @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xspi.c +//! \file spi.c //! \brief Driver for the SPI //! \version V2.2.1.0 //! \date 11/15/2013 @@ -38,8 +38,8 @@ //***************************************************************************** #include "CoX.h" -#include "xhw_sysctl.h" -#include "xhw_spi.h" +#include "hw_sysctl.h" +#include "hw_spi.h" //***************************************************************************** // diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xsysctl.c b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/sysctl.c similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xsysctl.c rename to CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/sysctl.c index cf32e0b3..30ba6230 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xsysctl.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/sysctl.c @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xsysctl.c +//! \file sysctl.c //! \brief Driver for the system controller //! \version V2.1.1.0 //! \date 12/26/2011 @@ -37,7 +37,7 @@ // //***************************************************************************** #include "CoX.h" -#include "xhw_sysctl.h" +#include "hw_sysctl.h" static unsigned long s_ulExtClockMHz = 12; diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xtimer.c b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/timer.c similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xtimer.c rename to CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/timer.c index 19c7c5c2..4ec18153 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xtimer.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/timer.c @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xtimer.c +//! \file timer.c //! \brief Driver for the Timer //! \version V2.1.1.0 //! \date 12/31/2011 @@ -37,8 +37,8 @@ // //***************************************************************************** #include "CoX.h" -#include "xhw_sysctl.h" -#include "xhw_timer.h" +#include "hw_sysctl.h" +#include "hw_timer.h" //***************************************************************************** // diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xuart.c b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/uart.c similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xuart.c rename to CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/uart.c index 707072ae..622658d4 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xuart.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/uart.c @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xuart.c +//! \file uart.c //! \brief Driver for the UART //! \version V2.1.1.0 //! \date 12/28/2011 @@ -37,8 +37,8 @@ // //***************************************************************************** #include "CoX.h" -#include "xhw_sysctl.h" -#include "xhw_uart.h" +#include "hw_sysctl.h" +#include "hw_uart.h" //***************************************************************************** diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xwdt.c b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/wdt.c similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xwdt.c rename to CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/wdt.c index 21bc3027..c23ad18c 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xwdt.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/wdt.c @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xwdt.c +//! \file wdt.c //! \brief Driver for the WDT //! \version V2.1.1.0 //! \date 1/3/2012 @@ -37,8 +37,8 @@ // //***************************************************************************** #include "CoX.h" -#include "xhw_sysctl.h" -#include "xhw_wdt.h" +#include "hw_sysctl.h" +#include "hw_wdt.h" //***************************************************************************** diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/CoX_base.h b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xPort.h similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/CoX_base.h rename to CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xPort.h index 7c7a5a53..ce91ed26 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/CoX_base.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_M051DN/libcox/xPort.h @@ -1,5 +1,5 @@ -#ifndef _M051DNDE_COX_BASE_H_ -#define _M051DNDE_COX_BASE_H_ +#ifndef _M051DNDE_X_PORT_H_ +#define _M051DNDE_X_PORT_H_ #include "lowlayer.h" #include "acmp.h" diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xacmp.c b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/acmp.c similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xacmp.c rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/acmp.c index a9a0b449..4ba8e0a4 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xacmp.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/acmp.c @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xacmp.c +//! \file acmp.c //! \brief Driver for the analog comparator. //! \version V2.1.1.1 //! \date 11/14/2011 @@ -12,7 +12,7 @@ //***************************************************************************** #include "CoX.h" -#include "xhw_acmp.h" +#include "hw_acmp.h" //***************************************************************************** // diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xadc.c b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/adc.c similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xadc.c rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/adc.c index 98578c14..4cf54feb 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xadc.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/adc.c @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xadc.c +//! \file adc.c //! \brief Driver for the ADC Controller. //! \version V2.1.1.1 //! \date 11/14/2011 @@ -38,7 +38,7 @@ //***************************************************************************** #include "CoX.h" -#include "xhw_adc.h" +#include "hw_adc.h" static xtEventCallback g_pfnADCHandlerCallbacks[1] = {0}; diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xcore.c b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/core.c similarity index 100% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xcore.c rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/core.c diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xdma.c b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/dma.c similarity index 100% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xdma.c rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/dma.c diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xgpio.c b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/gpio.c similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xgpio.c rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/gpio.c index 52015a62..baff2f6e 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xgpio.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/gpio.c @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xgpio.c +//! \file gpio.c //! \brief Driver for the GPIO controller //! \version V2.1.1.1 //! \date 11/14/2011 @@ -38,8 +38,8 @@ //***************************************************************************** #include "CoX.h" -#include "xhw_sysctl.h" -#include "xhw_gpio.h" +#include "hw_sysctl.h" +#include "hw_gpio.h" typedef struct { diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/gpio.h b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/gpio.h index ee160f33..539cd439 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/gpio.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/gpio.h @@ -337,6 +337,103 @@ // //***************************************************************************** +//***************************************************************************** +// +//! \addtogroup NUC1xx_GPIO_GP_Short_Pin NUC1xx General Purpose Short Pin +//! @{ +// +//***************************************************************************** +#define GPA0 GPIO_PORTA_BASE, GPIO_PIN_0 +#define GPA1 GPIO_PORTA_BASE, GPIO_PIN_1 +#define GPA2 GPIO_PORTA_BASE, GPIO_PIN_2 +#define GPA3 GPIO_PORTA_BASE, GPIO_PIN_3 +#define GPA4 GPIO_PORTA_BASE, GPIO_PIN_4 +#define GPA5 GPIO_PORTA_BASE, GPIO_PIN_5 +#define GPA6 GPIO_PORTA_BASE, GPIO_PIN_6 +#define GPA7 GPIO_PORTA_BASE, GPIO_PIN_7 +#define GPA8 GPIO_PORTA_BASE, GPIO_PIN_8 +#define GPA9 GPIO_PORTA_BASE, GPIO_PIN_9 +#define GPA10 GPIO_PORTA_BASE, GPIO_PIN_10 +#define GPA11 GPIO_PORTA_BASE, GPIO_PIN_11 +#define GPA12 GPIO_PORTA_BASE, GPIO_PIN_12 +#define GPA13 GPIO_PORTA_BASE, GPIO_PIN_13 +#define GPA14 GPIO_PORTA_BASE, GPIO_PIN_14 +#define GPA15 GPIO_PORTA_BASE, GPIO_PIN_15 + +#define GPB0 GPIO_PORTB_BASE, GPIO_PIN_0 +#define GPB1 GPIO_PORTB_BASE, GPIO_PIN_1 +#define GPB2 GPIO_PORTB_BASE, GPIO_PIN_2 +#define GPB3 GPIO_PORTB_BASE, GPIO_PIN_3 +#define GPB4 GPIO_PORTB_BASE, GPIO_PIN_4 +#define GPB5 GPIO_PORTB_BASE, GPIO_PIN_5 +#define GPB6 GPIO_PORTB_BASE, GPIO_PIN_6 +#define GPB7 GPIO_PORTB_BASE, GPIO_PIN_7 +#define GPB8 GPIO_PORTB_BASE, GPIO_PIN_8 +#define GPB9 GPIO_PORTB_BASE, GPIO_PIN_9 +#define GPB10 GPIO_PORTB_BASE, GPIO_PIN_10 +#define GPB11 GPIO_PORTB_BASE, GPIO_PIN_11 +#define GPB12 GPIO_PORTB_BASE, GPIO_PIN_12 +#define GPB13 GPIO_PORTB_BASE, GPIO_PIN_13 +#define GPB14 GPIO_PORTB_BASE, GPIO_PIN_14 +#define GPB15 GPIO_PORTB_BASE, GPIO_PIN_15 + +#define GPC0 GPIO_PORTC_BASE, GPIO_PIN_0 +#define GPC1 GPIO_PORTC_BASE, GPIO_PIN_1 +#define GPC2 GPIO_PORTC_BASE, GPIO_PIN_2 +#define GPC3 GPIO_PORTC_BASE, GPIO_PIN_3 +#define GPC4 GPIO_PORTC_BASE, GPIO_PIN_4 +#define GPC5 GPIO_PORTC_BASE, GPIO_PIN_5 +#define GPC6 GPIO_PORTC_BASE, GPIO_PIN_6 +#define GPC7 GPIO_PORTC_BASE, GPIO_PIN_7 +#define GPC8 GPIO_PORTC_BASE, GPIO_PIN_8 +#define GPC9 GPIO_PORTC_BASE, GPIO_PIN_9 +#define GPC10 GPIO_PORTC_BASE, GPIO_PIN_10 +#define GPC11 GPIO_PORTC_BASE, GPIO_PIN_11 +#define GPC12 GPIO_PORTC_BASE, GPIO_PIN_12 +#define GPC13 GPIO_PORTC_BASE, GPIO_PIN_13 +#define GPC14 GPIO_PORTC_BASE, GPIO_PIN_14 +#define GPC15 GPIO_PORTC_BASE, GPIO_PIN_15 + +#define GPD0 GPIO_PORTD_BASE, GPIO_PIN_0 +#define GPD1 GPIO_PORTD_BASE, GPIO_PIN_1 +#define GPD2 GPIO_PORTD_BASE, GPIO_PIN_2 +#define GPD3 GPIO_PORTD_BASE, GPIO_PIN_3 +#define GPD4 GPIO_PORTD_BASE, GPIO_PIN_4 +#define GPD5 GPIO_PORTD_BASE, GPIO_PIN_5 +#define GPD6 GPIO_PORTD_BASE, GPIO_PIN_6 +#define GPD7 GPIO_PORTD_BASE, GPIO_PIN_7 +#define GPD8 GPIO_PORTD_BASE, GPIO_PIN_8 +#define GPD9 GPIO_PORTD_BASE, GPIO_PIN_9 +#define GPD10 GPIO_PORTD_BASE, GPIO_PIN_10 +#define GPD11 GPIO_PORTD_BASE, GPIO_PIN_11 +#define GPD12 GPIO_PORTD_BASE, GPIO_PIN_12 +#define GPD13 GPIO_PORTD_BASE, GPIO_PIN_13 +#define GPD14 GPIO_PORTD_BASE, GPIO_PIN_14 +#define GPD15 GPIO_PORTD_BASE, GPIO_PIN_15 + +#define GPE0 GPIO_PORTE_BASE, GPIO_PIN_0 +#define GPE1 GPIO_PORTE_BASE, GPIO_PIN_1 +#define GPE2 GPIO_PORTE_BASE, GPIO_PIN_2 +#define GPE3 GPIO_PORTE_BASE, GPIO_PIN_3 +#define GPE4 GPIO_PORTE_BASE, GPIO_PIN_4 +#define GPE5 GPIO_PORTE_BASE, GPIO_PIN_5 +#define GPE6 GPIO_PORTE_BASE, GPIO_PIN_6 +#define GPE7 GPIO_PORTE_BASE, GPIO_PIN_7 +#define GPE8 GPIO_PORTE_BASE, GPIO_PIN_8 +#define GPE9 GPIO_PORTE_BASE, GPIO_PIN_9 +#define GPE10 GPIO_PORTE_BASE, GPIO_PIN_10 +#define GPE11 GPIO_PORTE_BASE, GPIO_PIN_11 +#define GPE12 GPIO_PORTE_BASE, GPIO_PIN_12 +#define GPE13 GPIO_PORTE_BASE, GPIO_PIN_13 +#define GPE14 GPIO_PORTE_BASE, GPIO_PIN_14 +#define GPE15 GPIO_PORTE_BASE, GPIO_PIN_15 + +//***************************************************************************** +// +//! @} +// +//***************************************************************************** + //***************************************************************************** // //! \addtogroup NUC1xx_GPIO_Pin_Config NUC1xx GPIO Pin Config diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xhw_acmp.h b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/hw_acmp.h similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xhw_acmp.h rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/hw_acmp.h index 3cf4f39d..97a083b4 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xhw_acmp.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/hw_acmp.h @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xhw_acmp.h +//! \file hw_acmp.h //! \brief Macros used when accessing the comparator hardware. //! \version V2.1.1.1 //! \date 11/14/2011 diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xhw_adc.h b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/hw_adc.h similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xhw_adc.h rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/hw_adc.h index d4278d72..fd9ab243 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xhw_adc.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/hw_adc.h @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xhw_adc.h +//! \file hw_adc.h //! \brief Macros used when accessing the ADC hardware. //! \version V2.1.1.1 //! \date 11/14/2011 diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xhw_dma.h b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/hw_dma.h similarity index 100% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xhw_dma.h rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/hw_dma.h diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xhw_gpio.h b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/hw_gpio.h similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xhw_gpio.h rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/hw_gpio.h index af0c1848..bacefbf6 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xhw_gpio.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/hw_gpio.h @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xhw_gpio.h +//! \file hw_gpio.h //! \brief Macros used when accessing the GPIO control hardware. //! \version V2.1.1.1 //! \date 11/14/2011 diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xhw_i2c.h b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/hw_i2c.h similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xhw_i2c.h rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/hw_i2c.h index 69fe82bc..22542902 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xhw_i2c.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/hw_i2c.h @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xhw_i2c.h +//! \file hw_i2c.h //! \brief Macros and defines used when accessing the I2C hardware. //! \version V2.1.1.1 //! \date 11/14/2011 diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xhw_pwm.h b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/hw_pwm.h similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xhw_pwm.h rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/hw_pwm.h index 713a7f4d..10155e5a 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xhw_pwm.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/hw_pwm.h @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xhw_pwm.h +//! \file hw_pwm.h //! \brief Macros and defines used when accessing the PWM hardware. //! \version V2.1.1.1 //! \date 11/14/2011 diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xhw_rtc.h b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/hw_rtc.h similarity index 100% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xhw_rtc.h rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/hw_rtc.h diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xhw_spi.h b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/hw_spi.h similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xhw_spi.h rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/hw_spi.h index 79d6c4fc..fd2cf232 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xhw_spi.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/hw_spi.h @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xhw_spi.h +//! \file hw_spi.h //! \brief Macros used when accessing the SPI hardware. //! \version V2.1.1.1 //! \date 11/14/2011 diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xhw_sysctl.h b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/hw_sysctl.h similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xhw_sysctl.h rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/hw_sysctl.h index 610d4f7e..5d18b6ff 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xhw_sysctl.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/hw_sysctl.h @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xhw_sysctl.h +//! \file hw_sysctl.h //! \brief Macros used when accessing the system control hardware. //! \version V2.1.1.1 //! \date 11/14/2011 diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xhw_timer.h b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/hw_timer.h similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xhw_timer.h rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/hw_timer.h index fcc4282b..5cebb575 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xhw_timer.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/hw_timer.h @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xhw_timer.h +//! \file hw_timer.h //! \brief Macros and defines used when accessing the TIMER hardware. //! \version V2.1.1.1 //! \date 11/14/2011 diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xhw_uart.h b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/hw_uart.h similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xhw_uart.h rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/hw_uart.h index 7ea50e13..a62a4e5d 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xhw_uart.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/hw_uart.h @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xhw_uart.h +//! \file hw_uart.h //! \brief Macros used when accessing the UART hardware. //! \version V2.1.1.1 //! \date 11/14/2011 diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xhw_wdt.h b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/hw_wdt.h similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xhw_wdt.h rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/hw_wdt.h index 86619c4b..67ca9e39 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xhw_wdt.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/hw_wdt.h @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xhw_wdt.h +//! \file hw_wdt.h //! \brief Macros and defines used when accessing the WATCHDOG hardware. //! \version V2.1.1.1 //! \date 11/14/2011 diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xi2c.c b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/i2c.c similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xi2c.c rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/i2c.c index c74459a7..56e742b0 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xi2c.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/i2c.c @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xi2c.c +//! \file i2c.c //! \brief Driver for the I2C //! \version V2.1.1.1 //! \date 6/14/2014 @@ -37,8 +37,8 @@ // //***************************************************************************** #include "CoX.h" -#include "xhw_sysctl.h" -#include "xhw_i2c.h" +#include "hw_sysctl.h" +#include "hw_i2c.h" //***************************************************************************** // diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xpwm.c b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/pwm.c similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xpwm.c rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/pwm.c index ea5762f9..750c77e3 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xpwm.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/pwm.c @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xpwm.c +//! \file pwm.c //! \brief Driver for the PWM //! \version V2.1.1.1 //! \date 11/14/2011 @@ -37,8 +37,8 @@ // //***************************************************************************** #include "CoX.h" -#include "xhw_sysctl.h" -#include "xhw_pwm.h" +#include "hw_sysctl.h" +#include "hw_pwm.h" //***************************************************************************** diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xrtc.c b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/rtc.c similarity index 100% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xrtc.c rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/rtc.c diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xspi.c b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/spi.c similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xspi.c rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/spi.c index 25335cbf..1e95350a 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xspi.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/spi.c @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xspi.c +//! \file spi.c //! \brief Driver for the SPI //! \version V2.1.1.1 //! \date 11/14/2011 @@ -37,8 +37,8 @@ // //***************************************************************************** #include "CoX.h" -#include "xhw_sysctl.h" -#include "xhw_spi.h" +#include "hw_sysctl.h" +#include "hw_spi.h" //***************************************************************************** // diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xsysctl.c b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/sysctl.c similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xsysctl.c rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/sysctl.c index c293d259..5110da92 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xsysctl.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/sysctl.c @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xsysctl.c +//! \file sysctl.c //! \brief Driver for the system controller //! \version V2.1.1.1 //! \date 11/14/2011 @@ -37,7 +37,7 @@ // //***************************************************************************** #include "CoX.h" -#include "xhw_sysctl.h" +#include "hw_sysctl.h" static unsigned long s_ulExtClockMHz = 12; diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xtimer.c b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/timer.c similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xtimer.c rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/timer.c index 8dece6ed..1375e0f7 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xtimer.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/timer.c @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xtimer.c +//! \file timer.c //! \brief Driver for the Timer //! \version V2.1.1.1 //! \date 11/14/2011 @@ -37,8 +37,8 @@ // //***************************************************************************** #include "CoX.h" -#include "xhw_sysctl.h" -#include "xhw_timer.h" +#include "hw_sysctl.h" +#include "hw_timer.h" //***************************************************************************** // diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xuart.c b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/uart.c similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xuart.c rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/uart.c index e6021ec6..f9b79a68 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xuart.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/uart.c @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xuart.c +//! \file uart.c //! \brief Driver for the UART //! \version V2.1.1.1 //! \date 11/14/2011 @@ -37,8 +37,8 @@ // //***************************************************************************** #include "CoX.h" -#include "xhw_sysctl.h" -#include "xhw_uart.h" +#include "hw_sysctl.h" +#include "hw_uart.h" //***************************************************************************** // diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xwdt.c b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/wdt.c similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xwdt.c rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/wdt.c index e68d41a8..5e632c9e 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xwdt.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/wdt.c @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xwdt.c +//! \file wdt.c //! \brief Driver for the WDT //! \version V2.1.1.1 //! \date 11/14/2011 @@ -37,8 +37,8 @@ // //***************************************************************************** #include "CoX.h" -#include "xhw_sysctl.h" -#include "xhw_wdt.h" +#include "hw_sysctl.h" +#include "hw_wdt.h" //***************************************************************************** diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xdebug.c b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xdebug.c deleted file mode 100644 index 6f0e6d74..00000000 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xdebug.c +++ /dev/null @@ -1,66 +0,0 @@ -//***************************************************************************** -// -//! \file xdebug.h -//! \brief Drivers for assisting debug of the peripheral library. -//! \version V2.1.1.1 -//! \date 11/14/2011 -//! \author CooCox -//! \copy -//! -//! Copyright (c) 2011, CooCox -//! All rights reserved. -//! -//! Redistribution and use in source and binary forms, with or without -//! modification, are permitted provided that the following conditions -//! are met: -//! -//! * Redistributions of source code must retain the above copyright -//! notice, this list of conditions and the following disclaimer. -//! * Redistributions in binary form must reproduce the above copyright -//! notice, this list of conditions and the following disclaimer in the -//! documentation and/or other materials provided with the distribution. -//! * Neither the name of the nor the names of its -//! contributors may be used to endorse or promote products derived -//! from this software without specific prior written permission. -//! -//! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -//! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -//! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -//! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -//! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -//! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -//! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -//! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -//! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -//! THE POSSIBILITY OF SUCH DAMAGE. -// -//***************************************************************************** - -//***************************************************************************** -// -//! \brief Error Function to be called when assert runs false. -//! -//! \param pcFilename is the current file name. -//! \param ulLine is the current line number. -//! -//! This is just an default error handler function, Users should implement -//! this function with your own way when debug. -//! -//! \note This is only used when doing a \b xDEBUG build. -//! -//! \return None. -// -//***************************************************************************** -#ifdef xDEBUG -void __xerror__(char *pcFilename, unsigned long ulLine) -{ - // - // Add your own error handling - // - while(1) - { - - } -} -#endif diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xdebug.h b/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xdebug.h deleted file mode 100644 index 96e09a3a..00000000 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC1xxDN/libcox/xdebug.h +++ /dev/null @@ -1,134 +0,0 @@ -//***************************************************************************** -// -//! \file xdebug.h -//! \brief Macros for assisting debug of the peripheral library. -//! \version V2.1.1.1 -//! \date 11/14/2011 -//! \author CooCox -//! \copy -//! -//! Copyright (c) 2011, CooCox -//! All rights reserved. -//! -//! Redistribution and use in source and binary forms, with or without -//! modification, are permitted provided that the following conditions -//! are met: -//! -//! * Redistributions of source code must retain the above copyright -//! notice, this list of conditions and the following disclaimer. -//! * Redistributions in binary form must reproduce the above copyright -//! notice, this list of conditions and the following disclaimer in the -//! documentation and/or other materials provided with the distribution. -//! * Neither the name of the nor the names of its -//! contributors may be used to endorse or promote products derived -//! from this software without specific prior written permission. -//! -//! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -//! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -//! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -//! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -//! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -//! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -//! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -//! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -//! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -//! THE POSSIBILITY OF SUCH DAMAGE. -// -//***************************************************************************** - -#ifndef __xDEBUG_H__ -#define __xDEBUG_H__ - -//***************************************************************************** -// -//! \addtogroup CoX_Peripheral_Lib -//! @{ -// -//***************************************************************************** - -//***************************************************************************** -// -//! \addtogroup xDebug xDebug -//! \brief Provided some assert macros to help debug. -//! -//! This module provides a macro called \ref xASSERT, Used to assert -//! some conditions if is correct. -//! -//! \section xDebug_When When User the Debug feature? -//! - Verify the legitimacy of the parameters -//! - Judge execution of the accuracy of the results -//! - where you want to determine if actual == expected ? -//! . -//! -//! \section xDebug_How How to use the Debug Feature? -//! -# Enable the debug feature by doing a \b xDEBUG build. -//! -# add the \ref xASSERT where you want. -//! . -//! -//! We strongly recommend you to open the debug characteristics in your -//! development process. This way can find out the questions as soon -//! as possible. -//! -//! When release the code, you should shut down the debug characteristics, -//! because they also take up CPU time, and you have ensured the condition -//! is ok in the debug process. -//! -//! @{ -// -//***************************************************************************** - -//***************************************************************************** -// -//! \addtogroup xDebug_Exported_APIs xDebug API -//! \brief xDebug API Reference. -//! @{ -// -//***************************************************************************** - -extern void __xerror__(char *pcFilename, unsigned long ulLine); - -//***************************************************************************** -// -//! \brief The ASSERT macro. -//! -//! \param expr is the expression to be check. -//! -//! It does the actual assertion checking. Typically, this will be for -//! procedure arguments. -//! -//! \return None. -// -//***************************************************************************** -#ifdef xDEBUG -#define xASSERT(expr) { \ - if(!(expr)) \ - { \ - __xerror__(__FILE__, __LINE__); \ - } \ - } -#else -#define xASSERT(expr) -#endif - -//***************************************************************************** -// -//! @} -// -//***************************************************************************** - -//***************************************************************************** -// -//! @} -// -//***************************************************************************** - -//***************************************************************************** -// -//! @} -// -//***************************************************************************** - -#endif // __xDEBUG_H__ - - diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xPort.h b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xPort.h index b6de11de..6e1c83d8 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xPort.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xPort.h @@ -11,7 +11,7 @@ #include "wdt.h" #include "rtc.h" -#define WDT_BASE WWDT_BASE +//#define WDT_BASE WWDT_BASE #define SYSCTL_PERIPH_IOPA SYSCTL_PERIPH_GPIO #define SYSCTL_PERIPH_IOPB SYSCTL_PERIPH_GPIO diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xdma.c b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xdma.c index 152cec84..fb1ea0fa 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xdma.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xdma.c @@ -314,21 +314,21 @@ xDMAChannelIntEnable(unsigned long ulChannelID, unsigned long ulIntFlags) //! \return None. // //***************************************************************************** -void -xDMAChannelIntEnable(unsigned long ulChannelID, unsigned long ulIntFlags) -{ - // - // Check the arguments. - // - xASSERT(xDMAChannelIDValid(ulChannelID)); - xASSERT(((ulIntFlags & DMA_EVENT_TC) == PDMA_EVENT_TC) || - ((ulIntFlags & DMA_EVENT_ERROR) == PDMA_EVENT_ERROR)); - - // - // Disable DMA channel interrupt. - // - xHWREG(DMA0_BASE + DMA_IER) &= ~(1 << ulChannelID); -} +//void +//xDMAChannelIntEnable(unsigned long ulChannelID, unsigned long ulIntFlags) +//{ +// // +// // Check the arguments. +// // +// xASSERT(xDMAChannelIDValid(ulChannelID)); +// xASSERT(((ulIntFlags & DMA_EVENT_TC) == PDMA_EVENT_TC) || +// ((ulIntFlags & DMA_EVENT_ERROR) == PDMA_EVENT_ERROR)); +// +// // +// // Disable DMA channel interrupt. +// // +// xHWREG(DMA0_BASE + DMA_IER) &= ~(1 << ulChannelID); +//} //***************************************************************************** // @@ -446,9 +446,9 @@ PDMAChannelDynamicAssign(unsigned long ulDMASrcRequest, xHWREG(g_psDMAIPSelectReg[PDMA_PDSRx(ulDMASrcRequest)]) |= (PDMA_PDSR_M((ulDMASrcRequest & 0xFFFFFF0) | ulChannelID)); - xHWREG(g_psDMAChannelAddress[ulChannelID] + PDMA_CSR) &= + xHWREG(g_psDMAChannelAddress[ulChannelID] + DMA_CTRL) &= ~PDMA_CSR_MODE_M; - xHWREG(g_psDMAChannelAddress[ulChannelID] + PDMA_CSR) |= + xHWREG(g_psDMAChannelAddress[ulChannelID] + DMA_CTRL) |= PDMA_CSR_MODE_MTOP; return ulChannelID; } @@ -469,9 +469,9 @@ PDMAChannelDynamicAssign(unsigned long ulDMASrcRequest, xHWREG(g_psDMAIPSelectReg[PDMA_PDSRx(ulDMADestRequest)]) |= (PDMA_PDSR_M((ulDMADestRequest & 0xFFFFFF0) | ulChannelID)); - xHWREG(g_psDMAChannelAddress[ulChannelID] + PDMA_CSR) &= + xHWREG(g_psDMAChannelAddress[ulChannelID] + DMA_CTRL) &= ~PDMA_CSR_MODE_M; - xHWREG(g_psDMAChannelAddress[ulChannelID] + PDMA_CSR) |= + xHWREG(g_psDMAChannelAddress[ulChannelID] + DMA_CTRL) |= PDMA_CSR_MODE_PTOM; return ulChannelID; } @@ -490,9 +490,9 @@ PDMAChannelDynamicAssign(unsigned long ulDMASrcRequest, if(g_psDMAChannelAssignTable[ulChannelID].ulChannelID != xDMA_CHANNEL_NOT_EXIST) { - xHWREG(g_psDMAChannelAddress[ulChannelID] + PDMA_CSR) &= + xHWREG(g_psDMAChannelAddress[ulChannelID] + DMA_CTRL) &= ~PDMA_CSR_MODE_M; - xHWREG(g_psDMAChannelAddress[ulChannelID] + PDMA_CSR) |= + xHWREG(g_psDMAChannelAddress[ulChannelID] + DMA_CTRL) |= PDMA_CSR_MODE_MTOM; return ulChannelID; } @@ -585,10 +585,10 @@ PDMAChannelControlSet(unsigned long ulChannelID, xASSERT(xDMAChannelIDValid(ulChannelID)); - xHWREG(g_psDMAChannelAddress[ulChannelID] + PDMA_CSR) &= + xHWREG(g_psDMAChannelAddress[ulChannelID] + DMA_CTRL) &= ~(PDMA_CSR_SDA_M | PDMA_CSR_DAD_M | PDMA_CSR_TWS_M); - xHWREG(g_psDMAChannelAddress[ulChannelID] + PDMA_CSR) |= ulControl; + xHWREG(g_psDMAChannelAddress[ulChannelID] + DMA_CTRL) |= ulControl; } @@ -647,17 +647,17 @@ PDMAChannelTransferSet(unsigned long ulChannelID, void *pvSrcAddr, { xASSERT(xDMAChannelIDValid(ulChannelID)); - xHWREG(g_psDMAChannelAddress[ulChannelID] + PDMA_CSR) |= PDMA_CSR_CEN; + xHWREG(g_psDMAChannelAddress[ulChannelID] + DMA_CTRL) |= PDMA_CSR_CEN; - xHWREG(g_psDMAChannelAddress[ulChannelID] + PDMA_SAR) = + xHWREG(g_psDMAChannelAddress[ulChannelID] + DMA_SAR) = (unsigned long)pvSrcAddr; - xHWREG(g_psDMAChannelAddress[ulChannelID] + PDMA_DAR) = + xHWREG(g_psDMAChannelAddress[ulChannelID] + DMA_DAR) = (unsigned long)pvDstAddr; xHWREG(g_psDMAChannelAddress[ulChannelID] + PDMA_BCR) = ulTransferSize; - xHWREG(g_psDMAChannelAddress[ulChannelID] + PDMA_CSR) |= PDMA_CSR_TEN; + xHWREG(g_psDMAChannelAddress[ulChannelID] + DMA_CTRL) |= PDMA_CSR_TEN; } diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/CoX.h b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/CoX.h index 1c59e700..b46e37db 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/CoX.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/CoX.h @@ -2,8 +2,8 @@ // //! \file CoX.h //! \brief Include all the h files in this file. -//! \version V2.1.1.1 -//! \date 11/14/2011 +//! \version V2.3 +//! \date 07/01/2014 //! \author CooCox //! \copy //! diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xacmp.h b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xacmp.h index c3fd6ba7..40d4a149 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xacmp.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xacmp.h @@ -2,8 +2,8 @@ // //! \file xacmp.h //! \brief Defines and Macros for the analog comparator API. -//! \version V2.2.1.0 -//! \date 11/20/2011 +//! \version V2.3 +//! \date 07/01/2014 //! \author CooCox //! \copy //! diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xadc.h b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xadc.h index cc3a5ffb..faea5738 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xadc.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xadc.h @@ -2,8 +2,8 @@ // //! \file xadc.h //! \brief Defines and Macros for ADC API. -//! \version V3.0 -//! \date 14/4/2014 +//! \version V2.3 +//! \date 07/01/2014 //! \author CooCox //! \copy //! diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xcore.h b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xcore.h index 6f99851e..a1c7b129 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xcore.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xcore.h @@ -4,8 +4,8 @@ //! \brief Prototypes for the CPU instruction wrapper functions. //! \brief Prototypes for the NVIC Interrupt Controller Driver. //! \brief Prototypes for the SysTick driver. -//! \version V2.2 -//! \date 5/17/2012 +//! \version V2.3 +//! \date 07/01/2014 //! \author CooCox //! \copy //! diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xdebug.c b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xdebug.c index cb21e8d7..d1b8ccf2 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xdebug.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xdebug.c @@ -2,9 +2,8 @@ // //! \file xdebug.h //! \brief Drivers for assisting debug of the peripheral library. -//! \version V2.1.1.0 -//! \date 11/14/2011 -//! \todo Update this time information. +//! \version V2.3 +//! \date 07/01/2014 //! \author CooCox //! \copy //! diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xdebug.h b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xdebug.h index 764ecd63..af28edd0 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xdebug.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xdebug.h @@ -2,8 +2,8 @@ // //! \file xdebug.h //! \brief Macros for assisting debug of the peripheral library. -//! \version V2.1.1.0 -//! \date $CURRENTTIME$ +//! \version V2.3 +//! \date 07/01/2014 //! \author CooCox //! \copyright //! diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xdma.h b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xdma.h index 17314283..aa1c2a20 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xdma.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xdma.h @@ -2,8 +2,8 @@ // //! \file xdma.h //! \brief Defines and Macros for DMA API. -//! \version V2.2.1.0 -//! \date 11/14/2011 +//! \version V2.3 +//! \date 07/01/2014 //! \author CooCox //! \copy //! diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xgpio.h b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xgpio.h index fb4e1ab2..ba85083f 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xgpio.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xgpio.h @@ -3,8 +3,8 @@ //! \file xgpio.h //! \brief Prototypes for the GPIO Driver. //! \brief Prototypes for the AFIO Driver. -//! \version V2.1.1.1 -//! \date 11/14/2011 +//! \version V2.3 +//! \date 07/01/2014 //! \author CooCox //! \copy //! diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xhw_nvic.h b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xhw_nvic.h index fb3652ca..9600baf6 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xhw_nvic.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xhw_nvic.h @@ -2,8 +2,8 @@ // //! \file xhw_nvic.h //! \brief Macros used when accessing the NVIC hardware.For M4 -//! \version V2.2.1.0 -//! \date 5/28/2014 +//! \version V2.3 +//! \date 07/01/2014 //! \author CooCox //! \copy //! diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xhw_types.h b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xhw_types.h index 6607850d..b566c960 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xhw_types.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xhw_types.h @@ -2,8 +2,8 @@ // //! \file xhw_types.h //! \brief Common types and macros. -//! \version V2.1.1.0 -//! \date $CURRENTTIME$ +//! \version V2.3 +//! \date 07/01/2014 //! \author CooCox //! \copyright //! diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xi2c.h b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xi2c.h index 0ef031c8..946ff66d 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xi2c.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xi2c.h @@ -2,8 +2,8 @@ // //! \file xi2c.h //! \brief Prototypes for the I2C Driver. -//! \version V2.2.1.0 -//! \date $CURRENTTIME$ +//! \version V2.3 +//! \date 07/01/2014 //! \author CooCox //! \copyright //! diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xlowlayer.h b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xlowlayer.h index c26f58d1..7d0287b5 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xlowlayer.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xlowlayer.h @@ -2,8 +2,8 @@ // //! \file xlowlayer.h //! \brief Macros defining of Peripehral Base and interrupt assignments. -//! \version V2.1.1.0 -//! \date $CURRENTTIME$ +//! \version V2.3 +//! \date 07/01/2014 //! \author CooCox //! \copyright //! diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xpwm.h b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xpwm.h index c3752d7b..f0c6d9a0 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xpwm.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xpwm.h @@ -2,8 +2,8 @@ // //! \file xpwm.h //! \brief Prototypes for the PWM Driver. -//! \version V2.2.1.0 -//! \date 5/2/2012 +//! \version V2.3 +//! \date 07/01/2014 //! \author CooCox //! \copy //! diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xrtc.h b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xrtc.h index 267854f1..26963a25 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xrtc.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xrtc.h @@ -2,8 +2,8 @@ // //! \file xrtc.h //! \brief Prototypes for the RTC Driver. -//! \version V2.2.1.0 -//! \date $CURRENTTIME$ +//! \version V2.3 +//! \date 07/01/2014 //! \author CooCox //! \copyright //! diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xspi.h b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xspi.h index 1c6b2d3f..a121232f 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xspi.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xspi.h @@ -2,8 +2,8 @@ // //! \file xspi.h //! \brief Prototypes for the SPI Driver. -//! \version V2.1.1.0 -//! \date 3/6/2012 +//! \version V2.3 +//! \date 07/01/2014 //! \author CooCox //! \copy //! diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xsysctl.h b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xsysctl.h index 20d025e3..ae075a98 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xsysctl.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xsysctl.h @@ -2,8 +2,8 @@ // //! \file xsysctl.h //! \brief Prototypes for the System Control Driver. -//! \version V2.2.1.0 -//! \date $CURRENTTIME$ +//! \version V2.3 +//! \date 07/01/2014 //! \author CooCox //! \copyright //! diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xtimer.h b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xtimer.h index e419b6ef..cabb6502 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xtimer.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xtimer.h @@ -2,8 +2,8 @@ // //! \file xtimer.h //! \brief Prototypes for the TIMER Driver. -//! \version V2.2.1.0 -//! \date 6/12/2012 +//! \version V2.3 +//! \date 07/01/2014 //! \author CooCox //! \copy //! diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xuart.h b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xuart.h index 39710d8d..b2374e06 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xuart.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xuart.h @@ -2,8 +2,8 @@ // //! \file xuart.h //! \brief Prototypes for the UART Driver. -//! \version V2.2 -//! \date 5/17/2012 +//! \version V2.3 +//! \date 07/01/2014 //! \author CooCox //! \copy //! diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xwdt.h b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xwdt.h index 090d3ce9..7544d0a8 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xwdt.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xwdt.h @@ -2,8 +2,8 @@ // //! \file xwdt.h //! \brief Prototypes for the WDT Driver. -//! \version V2.2.1.0 -//! \date $CURRENTTIME$ +//! \version V2.3 +//! \date 07/01/2014 //! \author CooCox //! \copyright //! From 85491db7ae6551ffa636396be785f2d5b660d1d9 Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 24 Jul 2014 09:50:08 +0800 Subject: [PATCH 08/13] add pwm i2c spi uart dma --- .../CoX_Peripehral_AU9110/libcox/dma.c | 962 ++++++++ .../CoX_Peripehral_AU9110/libcox/i2c.c | 2172 +++++++++++++++++ .../CoX_Peripehral_AU9110/libcox/pwm.c | 1049 ++++++++ .../startup/src/startup_coide.c | 719 ++---- 4 files changed, 4453 insertions(+), 449 deletions(-) create mode 100644 CoX/CoX_Peripheral/CoX_Peripehral_AU9110/libcox/dma.c create mode 100644 CoX/CoX_Peripheral/CoX_Peripehral_AU9110/libcox/i2c.c create mode 100644 CoX/CoX_Peripheral/CoX_Peripehral_AU9110/libcox/pwm.c diff --git a/CoX/CoX_Peripheral/CoX_Peripehral_AU9110/libcox/dma.c b/CoX/CoX_Peripheral/CoX_Peripehral_AU9110/libcox/dma.c new file mode 100644 index 00000000..d8196480 --- /dev/null +++ b/CoX/CoX_Peripheral/CoX_Peripehral_AU9110/libcox/dma.c @@ -0,0 +1,962 @@ +//***************************************************************************** +// +//! \file xdma.c +//! \brief Driver for the DMA Controller. +//! \version V2.1.1.1 +//! \date 11/14/2011 +//! \author CooCox +//! \copy +//! +//! Copyright (c) 2011, CooCox +//! All rights reserved. +//! +//! Redistribution and use in source and binary forms, with or without +//! modification, are permitted provided that the following conditions +//! are met: +//! +//! * Redistributions of source code must retain the above copyright +//! notice, this list of conditions and the following disclaimer. +//! * Redistributions in binary form must reproduce the above copyright +//! notice, this list of conditions and the following disclaimer in the +//! documentation and/or other materials provided with the distribution. +//! * Neither the name of the nor the names of its +//! contributors may be used to endorse or promote products derived +//! from this software without specific prior written permission. +//! +//! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +//! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +//! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +//! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +//! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +//! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +//! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +//! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +//! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +//! THE POSSIBILITY OF SUCH DAMAGE. +// +//***************************************************************************** + +#include "xhw_types.h" +#include "xhw_ints.h" +#include "xhw_memmap.h" +#include "xhw_nvic.h" +#include "xhw_sysctl.h" +#include "xhw_dma.h" +#include "xdebug.h" +#include "xcore.h" +#include "xsysctl.h" +#include "xdma.h" + +typedef struct +{ + // + // Channel ID. + // + unsigned long ulChannelID; + + // + // + // + xtEventCallback pfnDMAChannelHandlerCallback; + + // + // Channel Assignment status + // + xtBoolean bChannelAssigned; + +} +tDMAChannelAsssign; + +// +// DMA Channels Address. +// +static unsigned long g_psDMAChannelAddress[] = +{ + PDMA0_BASE, + PDMA1_BASE, + PDMA2_BASE, + PDMA3_BASE, + PDMA4_BASE, + PDMA5_BASE, + PDMA6_BASE, + PDMA7_BASE, + PDMA8_BASE +}; + +// +// PDMA Service Selection Control Register. +// +static unsigned long g_psDMAIPSelectReg[] = +{ + PDMA_PDSSR0, + PDMA_PDSSR1, + PDMA_PDSSR2 +}; + +#define PDMA_PDSRx(a) (((a) >> 28) & 0x3) +#define PDMA_PDSR_M(a) ((((a) & 0xF) << ((a) & 0x1f0000 >> 16))) + +//***************************************************************************** +// +// An array is DMA Callback function point +// +//***************************************************************************** +// static xtEventCallback g_pfnDMAGHandlerCallbacks[9]={0}; + +// +// DMA Channels Assignment table. +// +static tDMAChannelAsssign g_psDMAChannelAssignTable[] = +{ + { xDMA_CHANNEL_0, 0, xfalse }, + { xDMA_CHANNEL_1, 0, xfalse }, + { xDMA_CHANNEL_2, 0, xfalse }, + { xDMA_CHANNEL_3, 0, xfalse }, + { xDMA_CHANNEL_4, 0, xfalse }, + { xDMA_CHANNEL_5, 0, xfalse }, + { xDMA_CHANNEL_6, 0, xfalse }, + { xDMA_CHANNEL_7, 0, xfalse }, + { xDMA_CHANNEL_8, 0, xfalse }, + + // + // End. + // + { xDMA_CHANNEL_NOT_EXIST, xfalse }, + +}; + +//***************************************************************************** +// +//! \internal +//! Checks a DMA channel ID. +//! +//! \param ulChannelID is the DMA channel ID. +//! +//! This function determines if a DMA channel ID is valid. +//! +//! \return Returns \b xtrue if the ID is valid and \b xfalse +//! otherwise. +// +//***************************************************************************** +#ifdef xDEBUG +static xtBoolean +xDMAChannelIDValid(unsigned long ulChannelID) +{ + return( (ulChannelID >= 0) && (ulChannelID < 9)); +} +#endif + + +//***************************************************************************** +// +//! DMA Interrupt Handler. +//! +//! The interrupt handler for uDMA interrupts from the memory channel. +//! +//! \return None. +// +//***************************************************************************** +void +PDMAIntHandler(void) +{ + unsigned long ulChannelID; + unsigned long ulStatus; + ulStatus = xHWREG(PDMA_GCRISR); + for(ulChannelID = 0; + g_psDMAChannelAssignTable[ulChannelID].ulChannelID != + xDMA_CHANNEL_NOT_EXIST; + ulChannelID++) + { + if(g_psDMAChannelAssignTable[ulChannelID].bChannelAssigned == xtrue) + { + if (ulStatus & (1< nor the names of its +//! contributors may be used to endorse or promote products derived +//! from this software without specific prior written permission. +//! +//! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +//! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +//! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +//! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +//! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +//! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +//! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +//! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +//! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +//! THE POSSIBILITY OF SUCH DAMAGE. +// +//***************************************************************************** +#include "CoX.h" +#include "xhw_sysctl.h" +#include "xhw_i2c.h" + +//***************************************************************************** +// +// An array is I2C callback function point +// +//***************************************************************************** +static xtEventCallback g_pfnI2CHandlerCallbacks[1]={0}; + +//***************************************************************************** +// +//! \brief I2C0 interrupt handler. Clear the I2C0 interrupt flag and execute the +//! callback function. +//! +//! \param none. +//! +//! This function is the I2C0 interrupt handler,it will Clear the I2C0 +//! interrupt flag and execute the callback function if there be one. +//! +//! \note There are two source of this interrupt.One is I2C0 function +//! and one is I2C0 time out. +//! +//! \return None. +// +//***************************************************************************** +void +I2C0_IRQHandler(void) +{ + unsigned long ulBase = I2C0_BASE; + unsigned long ulStatus = xHWREG(ulBase + I2C_STATUS); + unsigned long ulTimeout; + // + // 0 + // + //I2CFlagStatusClear(ulBase, I2C_EVENT_BUSERR | I2C_EVENT_RXNACK | + // I2C_EVENT_ARBLOS); + + if((ulStatus == I2C_I2STAT_S_RX_SLAW_ACK) || + (ulStatus == I2C_I2STAT_S_RX_GENCALL_ACK) || + (ulStatus == I2C_I2STAT_S_RX_PRE_GENCALL_DAT_NACK) || + (ulStatus == I2C_I2STAT_S_TX_DAT_NACK) || + (ulStatus == I2C_I2STAT_S_TX_SLAR_ACK)) + { + xHWREG(ulBase + I2C_CON) |= I2C_CON_SI; + } + + if((ulStatus == I2C_I2STAT_S_RX_PRE_SLA_DAT_ACK) || + (ulStatus == I2C_I2STAT_S_RX_PRE_GENCALL_DAT_ACK)) + { + g_pfnI2CHandlerCallbacks[0](0, 0, xI2C_SLAVE_EVENT_RREQ, 0); + } + if((ulStatus == I2C_I2STAT_S_TX_SLAR_ACK) || + (ulStatus == I2C_I2STAT_S_TX_DAT_ACK)) + { + g_pfnI2CHandlerCallbacks[0](0, 0, xI2C_SLAVE_EVENT_TREQ, 0); + } + if((ulStatus == I2C_I2STAT_M_TX_SLAW_ACK) || + (ulStatus == I2C_I2STAT_M_TX_DAT_ACK)) + { + g_pfnI2CHandlerCallbacks[0](0, 0, xI2C_MASTER_EVENT_TX, 0); + } + if((ulStatus == I2C_I2STAT_M_RX_SLAR_ACK) || + (ulStatus == I2C_I2STAT_M_RX_DAT_ACK)) + { + g_pfnI2CHandlerCallbacks[0](0, 0, xI2C_MASTER_EVENT_RX, 0); + } + if((ulStatus == I2C_I2STAT_S_RX_STA_STO_SLVREC_SLVTRX)) + { + // + //Temporally lock the interrupt for timeout condition + // + xI2CSlaveIntDisable(ulBase, 0); + xHWREG(ulBase + I2C_CON) |= I2C_CON_SI; + // + // enable time out + // + ulTimeout = 0x10000; + while(1) + { + if (xHWREG(ulBase + I2C_CON) & I2C_CON_SI) + { + // + // re-Enable interrupt + // + xI2CSlaveIntEnable(ulBase, 0); + break; + } + else + { + ulTimeout--; + if (ulTimeout == 0) + { + // + //timeout occur, it's really a stop condition + // + g_pfnI2CHandlerCallbacks[0](0, 0, xI2C_SLAVE_EVENT_STOP, 0); + break; + } + } + } + } +} + +//***************************************************************************** +// +//! \internal +//! \brief Get the I2C number. +//! +//! \param ulBase specifies the I2C module base address. +//! +//! This function is to get the I2C number . +//! +//! The \e ulBase can be one of the following values: +//! \b I2C0_BASE. +//! +//! \note None +//! +//! \return value of I2C number,it can only be 0. +// +//***************************************************************************** +static unsigned long I2CNumGet(unsigned long ulBase) +{ + unsigned char num = 0; + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + + return 0; +} + +//***************************************************************************** +// +//! \internal +//! \brief Generate a start condition on I2C bus. +//! +//! \param ulBase specifies the I2C module base address. +//! +//! This function is to generate a start condition on +//! specified I2C BUS. +//! +//! The \e ulBase can be one of the following values: +//! \b I2C0_BASE. +//! +//! \note This is only for master +//! +//! \return value of I2C status register after generate a start condition. +// +//***************************************************************************** +static unsigned long I2CStartSend (unsigned long ulBase) +{ + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + + xHWREG(ulBase + I2C_CON) |= I2C_CON_SI; + xHWREG(ulBase + I2C_CON) |= I2C_CON_STA; + + // + // Wait for complete + // + while (!(xHWREG(ulBase + I2C_CON) & I2C_CON_SI)); + + return (xHWREG(ulBase + I2C_STATUS) & I2C_STATUS_M); +} + +//***************************************************************************** +// +//! \internal +//! \brief Generate a stop condition on I2C bus. +//! +//! \param ulBase specifies the I2C module base address. +//! +//! This function is to generate a stop condition on +//! specified I2C BUS. +//! +//! The \e ulBase can be one of the following values: +//! \b I2C0_BASE. +//! +//! \note This is only for master +//! +//! \return None. +// +//***************************************************************************** +static void I2CStopSend (unsigned long ulBase) +{ + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + + if (xHWREG(ulBase + I2C_CON) & I2C_CON_STA) + { + xHWREG(ulBase + I2C_CON) &= ~I2C_CON_STA; + } + xHWREG(ulBase + I2C_CON) |= I2C_CON_STO; + xHWREG(ulBase + I2C_CON) |= I2C_CON_SI; + + xHWREG(ulBase + I2C_CON) &= ~I2C_CON_AA; +} + +//***************************************************************************** +// +//! \internal +//! \brief Send a byte to I2C bus. +//! +//! \param ulBase specifies the I2C module base address. +//! \param ucData specifies the data which will send to I2C BUS. +//! +//! This function is to send a byte on specified I2C BUS. +//! +//! The \e ulBase can be one of the following values: +//! \b I2C0_BASE. +//! +//! \note This is only for master +//! +//! \return value of I2C status register after send a byte. +// +//***************************************************************************** +static unsigned long I2CByteSend (unsigned long ulBase, unsigned char ucData) +{ + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + + // + // Make sure start bit is not active,but do not clear SI + // + if (xHWREG(ulBase + I2C_CON) & I2C_CON_STA) + { + xHWREG(ulBase + I2C_CON) &= ~(I2C_CON_STA | I2C_CON_SI); + } + + // + // Send i2c address and RW bit + // + xHWREG(ulBase + I2C_DAT) = ucData; + + // + // Make sure AA and EI bit is not active,and clear SI + // + xHWREG(ulBase + I2C_CON) &= ~(I2C_CON_AA | I2C_CON_EI); + + // + // Wait the SI be set again by hardware + // + while (!(xHWREG(ulBase + I2C_CON) & I2C_CON_SI)); + + // + // Return the i2c status + // + return (xHWREG(ulBase + I2C_STATUS) & I2C_STATUS_M); +} + +//***************************************************************************** +// +//! \internal +//! \brief Get a byte to I2C bus. +//! +//! \param ulBase specifies the I2C module base address. +//! \param ucpData specifies the data point which will save the data get from +//! I2C BUS. +//! +//! This function is to get a byte on specified I2C BUS. +//! +//! The \e ulBase can be one of the following values: +//! \b I2C0_BASE. +//! +//! \note This is only for master +//! +//! \return value of I2C status register after send a byte. +// +//***************************************************************************** +static unsigned long I2CByteGet (unsigned long ulBase, unsigned char *ucpData, + unsigned char ucAck) +{ + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + + // + // Make sure start bit is not active + // + if (ucAck == 1) + { + xHWREG(ulBase + I2C_CON) |= I2C_CON_AA; + } + else + { + xHWREG(ulBase + I2C_CON) &= ~I2C_CON_AA; + } + xHWREG(ulBase + I2C_CON) |= I2C_CON_SI; + + while (!(xHWREG(ulBase + I2C_CON) & I2C_CON_SI)); + *ucpData = (unsigned char)xHWREG(ulBase + I2C_DAT); + return (xHWREG(ulBase + I2C_STATUS) & I2C_STATUS_M); +} + +//***************************************************************************** +// +//! \brief Set the clock rate of the specified I2C port. +//! +//! \param ulBase specifies the I2C module base address. +//! \param ulI2CClk specifies the I2C clock rate. +//! +//! This function is to init and set the clock rate +//! specified SPI port. +//! +//! The \e ulBase can be one of the following values: +//! \b I2C0_BASE. +//! +//! The \e ulI2CClk is the I2C clock rate: +//! +//! \note This is only for master +//! +//! \return None. +// +//***************************************************************************** +void +xI2CMasterInit(unsigned long ulBase, unsigned long ulI2CClk) +{ + unsigned long ulHclk; + unsigned long ulDiv; + + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + + xSysCtlPeripheralReset(xSYSCTL_PERIPH_I2C0); + + ulHclk = xSysCtlClockGet(); + + ulDiv = (unsigned long) (((ulHclk * 10)/(ulI2CClk * 4) + 5) / 10 - 1); + xHWREG(ulBase + I2C_CLKDIV) = ulDiv; + + xHWREG(ulBase + I2C_CON) = 0; + xHWREG(ulBase + I2C_CON) = I2C_CON_ENS1; +} + +//***************************************************************************** +// +//! \brief Indicates whether or not the I2C bus is busy. +//! This function returns an indication of whether or not the I2C bus +//! is busy. This function can be used in a multi-master environment to +//! determine if another master is currently using the bus. +//! +//! \param [in] ulBase is the I2C module base address. +//! +//! The \e ulBase can be one of the following values: +//! \b I2C0_BASE. +//! +//! \return The I2C bus status: +//! - xtrue if I2C bus is busy. +//! - xfalse if I2C bus is free. +// +//***************************************************************************** +xtBoolean xI2CMasterBusBusy(unsigned long ulBase) +{ + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + + return ((xHWREG(ulBase + I2C_STATUS)&0xF8) == 0xF8)? xfalse : xtrue; +} + +//***************************************************************************** +// +//! \brief Indicates whether or not the I2C Master is busy. +//! This function returns an indication of whether or not the I2C Master +//! is busy transmitting or receiving data. +//! +//! \param [in] ulBase is the I2C module base address. +//! +//! The \e ulBase can be one of the following values: +//! \b I2C0_BASE. +//! +//! \return The I2C bus status: +//! - xtrue if I2C bus is busy. +//! - xfalse if I2C bus is free. +// +//***************************************************************************** +xtBoolean xI2CMasterBusy(unsigned long ulBase) +{ + return xfalse; +} + +//***************************************************************************** +// +//! \brief Gets the error status of the I2C Master module. +//! This function is used to obtain the error status of the Master module +//! send and receive operations. +//! +//! \param [in] ulBase is the I2C module base address. +//! +//! The \e ulBase can be one of the following values: +//! \b I2C0_BASE. +//! +//! \return Returns the error status, can be one of the following value: +//! - \ref I2C_MASTER_ERR_NONE +//! - \ref I2C_MASTER_ERR_ADDR_ACK +//! - \ref I2C_MASTER_ERR_DATA_ACK +//! - \ref I2C_MASTER_ERR_ARB_LOST +// +//***************************************************************************** +unsigned long xI2CMasterError(unsigned long ulBase) +{ + unsigned long ulStatus; + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + + ulStatus = (xHWREG(ulBase + I2C_STATUS) & I2C_STATUS_M); + + if((ulStatus == I2C_I2STAT_M_TX_DAT_NACK) || + (ulStatus == I2C_I2STAT_M_RX_DAT_NACK)) + { + return xI2C_MASTER_ERR_ADDR_ACK; + } + if((ulStatus == I2C_I2STAT_M_TX_SLAW_NACK) || + (ulStatus == I2C_I2STAT_M_RX_SLAR_NACK)) + { + return xI2C_MASTER_ERR_DATA_ACK; + } + if((ulStatus == I2C_I2STAT_M_TX_ARB_LOST)) + { + return xI2C_MASTER_ERR_ARB_LOST; + } + return xI2C_MASTER_ERR_NONE; +} + +//***************************************************************************** +// +//! Transmits a byte from the I2C Master. +//! +//! \param ulBase is the base address of the I2C module. +//! \param ucData data to be transmitted from the I2C Master +//! +//! This function will place the supplied data into I2C Master Data Register. +//! +//! \return None. +// +//***************************************************************************** +void xI2CMasterDataPut(unsigned long ulBase, unsigned char ucData) +{ + // + // Send data to I2C BUS + // + xHWREG(ulBase + I2C_DAT) = ucData; + + // + // Make sure AA bit is active,and clear EI + // + xHWREG(ulBase + I2C_CON) |= I2C_CON_AA; + xHWREG(ulBase + I2C_CON) |= I2C_CON_SI; +} + +//***************************************************************************** +// +//! Receives a byte that has been sent to the I2C Master. +//! +//! \param ulBase is the base address of the I2C Master module. +//! +//! This function reads a byte of data from the I2C Master Data Register. +//! +//! \return Returns the byte received from by the I2C Master, cast as an +//! unsigned long. +// +//***************************************************************************** +unsigned long xI2CMasterDataGet(unsigned long ulBase) +{ + unsigned long ulData = xHWREG(ulBase + I2C_DAT); + xHWREG(ulBase + I2C_CON) |= I2C_CON_SI; + return ulData; +} + +//***************************************************************************** +// +//! \brief Transmite the STOP condition, master goes to idle state. +//! +//! \param ulBase is the base address of the I2C Master module. +//! +//! This function free the I2C bus. When the master no longer need send or +//! receive any more data, or need to terminate this transmition after getting +//! some errors, call this function. +//! +//! \return None. +// +//***************************************************************************** +void xI2CMasterStop(unsigned long ulBase) +{ + +} + +//***************************************************************************** +// +//! \brief Send a master transmit request when the bus is idle.(Write Step1) +//! +//! \param ulBase is the base address of the I2C Master module. +//! \param ucSlaveAddr is the 7-bit slave address. +//! \param ucData is the byte to transmit. +//! \param bEndTransmition is flag to control if transmit the STOP condition and +//! terminate this transmition. +//! +//! This function init a new write transmition. When the master have not obtained +//! control of the bus, This function send request to transmit the START +//! condition, the slave address and the data, Then it returns immediately, no +//! waiting any bus transmition to complete. +//! +//! Users can call I2CMasterBusy() to check if all the bus transmition +//! complete, the call I2CMasterErr() to check if any error occurs. +//! +//! After the master obtained control of the bus, and haven't release it, users +//! can call I2CMasterWriteRequestS2() to continue transmit data to slave. +//! Users can also call I2CMasterStop() to terminate this transmition and +//! release the I2C bus. +//! +//! For this function returns immediately, it is always using in the interrupt +//! hander. +//! +//! \return None. +// +//***************************************************************************** +void +xI2CMasterWriteRequestS1(unsigned long ulBase, unsigned char ucSlaveAddr, + unsigned char ucData, xtBoolean bEndTransmition) +{ + unsigned long ulStatus; + + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + xASSERT(!(ucSlaveAddr & 0x80)); + + // + // Send start + // + ulStatus = I2CStartSend(ulBase); + + if(!(ulStatus == I2C_I2STAT_M_TX_START)) + { + I2CStopSend(ulBase); + return; + } + + // + // Send address + // + ulStatus = I2CByteSend(ulBase, (ucSlaveAddr << 1)); + if(!(ulStatus == I2C_I2STAT_M_TX_SLAW_ACK)) + { + I2CStopSend(ulBase); + return; + } + + // + // Send data to I2C BUS + // + xHWREG(ulBase + I2C_DAT) = ucData; + + // + // Make sure AA and EI bit is not active,and clear EI + // + //xHWREG(ulBase + I2C_CON) &= ~(I2C_CON_AA | I2C_CON_EI); + xHWREG(ulBase + I2C_CON) |= I2C_CON_SI; + + if(bEndTransmition) + { + I2CStopSend(ulBase); + } +} + +//***************************************************************************** +// +//! \brief Send a master data transmit request when the master have obtained +//! control of the bus.(Write Step2) +//! +//! \param ulBase is the base address of the I2C Master module. +//! \param ucData is the byte to transmit. +//! \param bEndTransmition is flag to control if transmit the STOP condition and +//! terminate this transmition. +//! +//! After the master obtained control of the bus(have called +//! I2CMasterWriteRequestS1() without any error), and haven't release it, users +//! can call this function to continue transmit data to slave. +//! +//! This function just send request to transmit the data, and it returns +//! immediately, no waiting any bus transmition to complete. +//! +//! Users can call I2CMasterBusy() to check if all the bus transmition +//! complete, the call I2CMasterErr() to check if any error occurs. Users call +//! also can I2CMasterStop() to terminate this transmition and release the +//! I2C bus. +//! +//! For this function returns immediately, it is always using in the interrupt +//! hander. +//! +//! \return None. +// +//***************************************************************************** +void +xI2CMasterWriteRequestS2(unsigned long ulBase, unsigned char ucData, + xtBoolean bEndTransmition) +{ + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + + // + // Send data to I2C BUS + // + xHWREG(ulBase + I2C_DAT) = ucData; + + // + // Make sure AA and EI bit is not active,and clear EI + // + xHWREG(ulBase + I2C_CON) &= ~(I2C_CON_AA | I2C_CON_EI); + + // + // Send the stop if End Transmition. + // + if(bEndTransmition) + { + I2CStopSend(ulBase); + } +} + +//***************************************************************************** +// +//! \brief Write a data to the slave when the bus is idle, and waiting for all +//! bus transmiton complete.(Write Step1) +//! +//! \param ulBase is the base address of the I2C Master module. +//! \param ucSlaveAddr is the 7-bit slave address. +//! \param ucData is the byte to transmit. +//! \param bEndTransmition is flag to control if transmit the STOP condition and +//! terminate this transmition. +//! +//! This function init a new write transmition. When the master have not obtained +//! control of the bus, This function transmit the START condition, the slave +//! address and the data, then waiting for all bus transmition complete. +//! +//! Users can then check the return value to see if any error occurs: +//! - \ref I2C_MASTER_ERR_NONE - \b 0, no error +//! - \ref I2C_MASTER_ERR_ADDR_ACK - The transmitted address was not acknowledged +//! - \ref I2C_MASTER_ERR_DATA_ACK - The transmitted data was not acknowledged +//! - \ref I2C_MASTER_ERR_ARB_LOST - The I2C controller lost arbitration. +//! +//! After the master obtained control of the bus, and haven't release it, users +//! can call I2CMasterWriteS2() to continue transmit data to slave. +//! Users call also can I2CMasterStop() to terminate this transmition and +//! release the I2C bus. +//! +//! This function is always used in thread mode. +//! +//! \return Returns the master error status. +// +//***************************************************************************** +unsigned long +xI2CMasterWriteS1(unsigned long ulBase, unsigned char ucSlaveAddr, + unsigned char ucData, xtBoolean bEndTransmition) +{ + unsigned long ulStatus; + + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + xASSERT(!(ucSlaveAddr & 0x80)); + + // + // Send write request + // + xI2CMasterWriteRequestS1(ulBase, ucSlaveAddr, ucData, xfalse); + + // + // Wait the SI be set again by hardware + // + while (!(xHWREG(ulBase + I2C_CON) & I2C_CON_SI)); + ulStatus = xHWREG(ulBase + I2C_STATUS) & I2C_STATUS_M; + if(!(ulStatus == I2C_I2STAT_M_TX_DAT_ACK)) + { + ulStatus = xI2CMasterError(ulBase); + I2CStopSend(ulBase); + return ulStatus; + } + + if(bEndTransmition) + { + I2CStopSend(ulBase); + } + + // + // return the error status + // + return xI2C_MASTER_ERR_NONE; +} + +//***************************************************************************** +// +//! \brief Write a data to the slave, when the master have obtained control of +//! the bus, and waiting for all bus transmiton complete.(Write Step2) +//! +//! \param ulBase is the base address of the I2C Master module. +//! \param ucData is the byte to transmit. +//! \param bEndTransmition is flag to control if transmit the STOP condition and +//! terminate this transmition. +//! +//! After the master obtained control of the bus(have called +//! I2CMasterWriteS1() without any error), and haven't release it, users +//! can call this function to continue transmit data to slave. +//! +//! This function transmit the data to the slave, and waiting for all bus +//! transmition complete. +//! +//! Users can then check the return value to see if any error occurs: +//! - \ref I2C_MASTER_ERR_NONE - \b 0, no error +//! - \ref I2C_MASTER_ERR_ADDR_ACK - The transmitted address was not acknowledged +//! - \ref I2C_MASTER_ERR_DATA_ACK - The transmitted data was not acknowledged +//! - \ref I2C_MASTER_ERR_ARB_LOST - The I2C controller lost arbitration. +//! +//! Then users can call this function to continue transmit data to slave. +//! Users call also call I2CMasterStop() to terminate this transmition and +//! release the I2C bus. +//! +//! This function is always used in thread mode. +//! +//! \return Returns the master error status. +// +//***************************************************************************** +unsigned long +xI2CMasterWriteS2(unsigned long ulBase, unsigned char ucData, + xtBoolean bEndTransmition) +{ + unsigned long ulStatus; + + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + + // + // Send write request + // + xI2CMasterWriteRequestS2(ulBase, ucData, xfalse); + + // + // Wait the SI be set again by hardware + // + while (!(xHWREG(ulBase + I2C_CON) & I2C_CON_SI)); + ulStatus = xHWREG(ulBase + I2C_STATUS) & I2C_STATUS_M; + if(!(ulStatus == I2C_I2STAT_M_TX_DAT_ACK)) + { + ulStatus = xI2CMasterError(ulBase); + I2CStopSend(ulBase); + return ulStatus; + } + + if(bEndTransmition) + { + I2CStopSend(ulBase); + } + + // + // return the error status + // + return xI2C_MASTER_ERR_NONE; +} + +//***************************************************************************** +// +//! \brief Write a data buffer to the slave when the bus is idle, and waiting +//! for all bus transmiton complete.(Write Buffer Step1) +//! +//! \param ulBase is the base address of the I2C Master module. +//! \param ucSlaveAddr is the 7-bit slave address. +//! \param pucDataBuf is the data buffer to transmit. +//! \param ulLen is the data buffer byte size. +//! \param bEndTransmition is flag to control if transmit the STOP condition and +//! terminate this transmition. +//! +//! This function init a new data buffer write transmition. When the master have +//! not obtained control of the bus, This function transmit the START condition, +//! the slave address and the data, then waiting for the data transmition +//! complete, and continue next data transmition, until all complete. If there +//! is any error occurs, the remain data will be canceled. +//! +//! Users can then check the return value to see how many datas have been +//! successfully transmited. if the number != ulLen, user can call +//! I2CMasterErr() to see what error occurs. +//! +//! After the master obtained control of the bus, and haven't release it, users +//! can call I2CMasterWriteS2() / I2CMasterWriteBufS2() to continue transmit data +//! to slave. Users call also call I2CMasterStop() to terminate this transmition +//! and release the I2C bus. +//! +//! This function is always used in thread mode. +//! +//! \return Returns the data number that have been successully tranmited. +// +//***************************************************************************** +unsigned long +xI2CMasterWriteBufS1(unsigned long ulBase, unsigned char ucSlaveAddr, + unsigned char *pucDataBuf, unsigned long ulLen, + xtBoolean bEndTransmition) +{ + + unsigned long ulStatus; + unsigned long ulWritten; + + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + xASSERT(pucDataBuf); + + if(ulLen == 1) + { + ulStatus = xI2CMasterWriteS1(ulBase, ucSlaveAddr, + pucDataBuf[0], bEndTransmition); + + return (ulStatus == xI2C_MASTER_ERR_NONE) ? 1 : 0; + } + + // + // Send start + // + ulStatus = I2CStartSend(ulBase); + if(!(ulStatus == I2C_I2STAT_M_TX_START)) + { + I2CStopSend(ulBase); + return 0; + } + // + // Send address + // + ulStatus = I2CByteSend(ulBase, (ucSlaveAddr << 1)); + if(!(ulStatus == I2C_I2STAT_M_TX_SLAW_ACK)) + { + I2CStopSend(ulBase); + return 0; + } + + // + // Send data + // + ulStatus = I2CByteSend(ulBase, *pucDataBuf); + + // + // Check if any error occurs + // + if(!(ulStatus == I2C_I2STAT_M_TX_DAT_ACK)) + { + I2CStopSend(ulBase); + return 0; + } + else + { + ulWritten = 1; + } + + ulWritten += xI2CMasterWriteBufS2(ulBase, + &pucDataBuf[1], + ulLen - 1, + bEndTransmition); + + return ulWritten; +} + +//***************************************************************************** +// +//! \brief Write a data buffer to the slave, when the master have obtained +//! control of the bus, and waiting for all bus transmiton complete.(Write +//! Buffer Step2) +//! +//! \param ulBase is the base address of the I2C Master module. +//! \param pucDataBuf is the data buffer to transmit. +//! \param ulLen is the data buffer byte size. +//! \param bEndTransmition is flag to control if transmit the STOP condition and +//! terminate this transmition. +//! +//! After the master obtained control of the bus(have called +//! I2CMasterWriteS1() or I2CMasterWriteBufS1() without any error), and haven't +//! release it, users can call this function to continue transmit data to slave. +//! +//! This function transmit the data one by one to the slave, waiting for every +//! data transmition complete, and continue next data transmition, until all +//! complete. If there is any error occurs, the remain data will be canceled. +//! +//! Users can then check the return value to see how many datas have been +//! successfully transmited. if the number != ulLen, user can call +//! I2CMasterErr() to see what error occurs. +//! +//! Then users can call I2CMasterWriteS2() or this function to continue +//! transmit data to slave. Users call also call I2CMasterStop() to terminate +//! this transmition and release the I2C bus. +//! +//! This function is always used in thread mode. +//! +//! \return Returns the data number that have been successully tranmited. +// +//***************************************************************************** +unsigned long +xI2CMasterWriteBufS2(unsigned long ulBase, unsigned char *pucDataBuf, + unsigned long ulLen, xtBoolean bEndTransmition) +{ + unsigned long i; + unsigned long ulStatus; + + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + xASSERT(pucDataBuf); + + for(i = 0; i < ulLen - 1; i++) + { + // + // Send data + // + ulStatus = I2CByteSend(ulBase, *pucDataBuf++); + + // + // Check if any error occurs + // + if(!(ulStatus == I2C_I2STAT_M_TX_DAT_ACK)) + { + I2CStopSend(ulBase); + return i; + + } + } + // + // Waiting the I2C controller to idle + // + ulStatus = I2CByteSend(ulBase, *pucDataBuf); + if(!(ulStatus == I2C_I2STAT_M_TX_DAT_ACK)) + { + I2CStopSend(ulBase); + return i; + } + + if(bEndTransmition) + { + I2CStopSend(ulBase); + } + + return ulLen; +} + +//***************************************************************************** +// +//! \brief Send a master receive request when the bus is idle.(Read Step1) +//! +//! \param ulBase is the base address of the I2C Master module. +//! \param ucSlaveAddr is the 7-bit slave address. +//! \param bEndTransmition is flag to control if transmit the STOP condition and +//! terminate this transmition. +//! +//! This function init a new receive transmition. When the master have not obtained +//! control of the bus, This function send request to transmit the START +//! condition, the slave address and the data request, Then it returns +//! immediately, no waiting any bus transmition to complete. +//! +//! If bEndTransmition is xtrue, the receive operation will followed by an +//! negative ACK and STOP condition. +//! +//! Users can call I2CMasterBusy() to check if all the bus transmition +//! complete, then call I2CMasterErr() to check if any error occurs. Then user +//! can get the data by calling I2CMasterDataGet() if there is no error occurs. +//! +//! After the master obtained control of the bus, and haven't release it, users +//! can call I2CMasterReadRequestS2() to continue receive data from slave. +//! Users call also can I2CMasterStop() to terminate this transmition and +//! release the I2C bus. +//! +//! For this function returns immediately, it is always using in the interrupt +//! hander. +//! +//! \return None. +// +//***************************************************************************** +void +xI2CMasterReadRequestS1(unsigned long ulBase, unsigned char ucSlaveAddr, + xtBoolean bEndTransmition) +{ + unsigned long ulStatus; + + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + xHWREG(ulBase + I2C_CON) |= I2C_CON_AA; + // + // Send start and address + // + ulStatus = I2CStartSend(ulBase); + if(!((ulStatus == I2C_I2STAT_M_TX_START) || + (ulStatus == I2C_I2STAT_M_TX_RESTART))) + { + I2CStopSend(ulBase); + return ; + } + // + // Send address + // + ulStatus = I2CByteSend(ulBase, (ucSlaveAddr << 1) | 1) ; + if(!(ulStatus == I2C_I2STAT_M_RX_SLAR_ACK)) + { + I2CStopSend(ulBase); + return ; + } + if(bEndTransmition) + { + xHWREG(ulBase + I2C_CON) &= ~I2C_CON_AA; + I2CStopSend(ulBase); + } +} + +//***************************************************************************** +// +//! \brief Send a master data receive request when the master have obtained +//! control of the bus.(Write Step2) +//! +//! \param ulBase is the base address of the I2C Master module. +//! \param bEndTransmition is flag to control if transmit the STOP condition and +//! terminate this transmition. +//! +//! After the master obtained control of the bus(have called +//! I2CMasterReadRequestS1() without any error), and haven't release it, users +//! can call this function to continue receive data from slave. +//! +//! If bEndTransmition is xtrue, the receive operation will followed by an +//! negative ACK and STOP condition. +//! +//! Users can call I2CMasterBusy() to check if all the bus transmition +//! complete, then call I2CMasterErr() to check if any error occurs. Then user +//! can get the data by calling I2CMasterDataGet() if there is no error occurs. +//! +//! Then users can call this function to continue receive data from slave. +//! Users call also can I2CMasterStop() to terminate this transmition and +//! release the I2C bus. +//! +//! For this function returns immediately, it is always using in the interrupt +//! hander. +//! +//! \return None. +// +//***************************************************************************** +void +xI2CMasterReadRequestS2(unsigned long ulBase, xtBoolean bEndTransmition) +{ + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + + // + // Send the stop if End Transmition. + // + if(bEndTransmition) + { + xHWREG(ulBase + I2C_CON) &= ~I2C_CON_AA; + I2CStopSend(ulBase); + } +} + +//***************************************************************************** +// +//! \brief Send a master data receive request with an NACK when the master have +//! obtained control of the bus(Write Step2). +//! +//! \param ulBase is the base address of the I2C Master module. +//! +//! This function is used to request the last data to receive, and signal the +//! end of the transfer to the slave transmitter. Then the master can repeat +//! START condition, switch to transmit or other slaves without lost control +//! of the bus. +//! +//! Users can call I2CMasterBusy() to check if all the bus transmition +//! complete, then call I2CMasterErr() to check if any error occurs. Then user +//! can get the data by calling I2CMasterDataGet() if there is no error occurs. +//! +//! Users call also can I2CMasterStop() to terminate this transmition and +//! release the I2C bus. +//! +//! For this function returns immediately, it is always using in the interrupt +//! hander. +//! +//! \return None. +// +//***************************************************************************** +void +xI2CMasterReadLastRequestS2(unsigned long ulBase) +{ + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + + // + // RECEIVE operation with negative ACK(no stop) + // + xHWREG(ulBase + I2C_CON) &= ~I2C_CON_AA; +} + +//***************************************************************************** +// +//! \brief Read a data from a slave when the bus is idle, and waiting for all +//! bus transmiton complete.(Read Step1) +//! +//! \param ulBase is the base address of the I2C Master module. +//! \param ucSlaveAddr is the 7-bit slave address. +//! \param pucData is the buffer where to save the data. +//! \param bEndTransmition is flag to control if transmit the STOP condition and +//! terminate this transmition. +//! +//! This function init a new receive transmition. When the master have not obtained +//! control of the bus, This function send request to transmit the START +//! condition, the slave address and the data request, then waiting for all bus +//! transmition complete. +//! +//! If bEndTransmition is xtrue, the receive operation will followed by an +//! negative ACK and STOP condition. +//! +//! Users can then check the return value to see if any error occurs: +//! - \ref I2C_MASTER_ERR_NONE - \b 0, no error +//! - \ref I2C_MASTER_ERR_ADDR_ACK - The transmitted address was not acknowledged +//! - \ref I2C_MASTER_ERR_DATA_ACK - The transmitted data was not acknowledged +//! - \ref I2C_MASTER_ERR_ARB_LOST - The I2C controller lost arbitration. +//! +//! After the master obtained control of the bus, and haven't release it, users +//! can call I2CMasterReadS2() to continue receive data from slave. +//! Users call also can I2CMasterStop() to terminate this transmition and +//! release the I2C bus. +//! +//! This function is usually used in thread mode. +//! +//! \return Returns the master error status. +// +//***************************************************************************** +unsigned long +xI2CMasterReadS1(unsigned long ulBase, + unsigned char ucSlaveAddr, + unsigned char *pucData, + xtBoolean bEndTransmition) +{ + unsigned long ulStatus; + + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + xASSERT(pucData); + + xI2CMasterReadRequestS1(ulBase, ucSlaveAddr, xfalse); + + xHWREG(ulBase + I2C_CON) |= I2C_CON_AA; + xSysCtlDelay(100); + xHWREG(ulBase + I2C_CON) |= I2C_CON_SI; + + while (!(xHWREG(ulBase + I2C_CON) & I2C_CON_SI)); + + *pucData = xHWREG(ulBase + I2C_DAT); + + ulStatus = (xHWREG(ulBase + I2C_STATUS) & I2C_STATUS_M); + + if (ulStatus != I2C_I2STAT_M_RX_DAT_ACK) + { + ulStatus = xI2CMasterError(ulBase); + I2CStopSend(ulBase); + return ulStatus; + } + if(bEndTransmition) + { + I2CStopSend(ulBase); + } + + // + // return the error status + // + return xI2C_MASTER_ERR_NONE; +} + +//***************************************************************************** +// +//! \brief Read a data from a slave when the master have obtained control of +//! the bus, and waiting for all bus transmiton complete.(Read Step2) +//! +//! \param ulBase is the base address of the I2C Master module. +//! \param pucData is the buffer where to save the data. +//! \param bEndTransmition is flag to control if transmit the STOP condition and +//! terminate this transmition. +//! +//! After the master obtained control of the bus(have called +//! I2CMasterReadS1() without any error), and haven't release it, users can +//! call this function to continue receive data from the slave. +//! +//! If bEndTransmition is xtrue, the receive operation will followed by an +//! negative ACK and STOP condition. +//! +//! It will be waiting for all bus transmition complete before return. +//! Users can then check the return value to see if any error occurs: +//! - \ref I2C_MASTER_ERR_NONE - \b 0, no error +//! - \ref I2C_MASTER_ERR_ADDR_ACK - The transmitted address was not acknowledged +//! - \ref I2C_MASTER_ERR_DATA_ACK - The transmitted data was not acknowledged +//! - \ref I2C_MASTER_ERR_ARB_LOST - The I2C controller lost arbitration. +//! +//! Then useres can call this function to continue receive data from slave. +//! Users call also can I2CMasterStop() to terminate this transmition and +//! release the I2C bus. +//! +//! This function is usually used in thread mode. +//! +//! \return Returns the master error status. +// +//***************************************************************************** +unsigned long +xI2CMasterReadS2(unsigned long ulBase, + unsigned char *pucData, + xtBoolean bEndTransmition) +{ + unsigned long ulStatus; + + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + + xI2CMasterReadRequestS2(ulBase, xfalse); + + if(bEndTransmition) + { + xHWREG(ulBase + I2C_CON) &= ~I2C_CON_AA; + } + + xHWREG(ulBase + I2C_CON) |= I2C_CON_SI; + + // + // Waiting the I2C controller to be transmited + // + while (!(xHWREG(ulBase + I2C_CON) & I2C_CON_SI)); + *pucData = (unsigned char)xHWREG(ulBase + I2C_DAT); + + // + // Get the Status code + // + ulStatus = (xHWREG(ulBase + I2C_STATUS) & I2C_STATUS_M); + + // + // Waiting the I2C controller to be transmited + // + if (ulStatus != I2C_I2STAT_M_RX_DAT_ACK) + { + ulStatus = xI2CMasterError(ulBase); + I2CStopSend(ulBase); + return ulStatus; + } + + if(bEndTransmition) + { + I2CStopSend(ulBase); + } + + // + // return the error status + // + return xI2C_MASTER_ERR_NONE; +} + +//***************************************************************************** +// +//! \brief Read some data from a slave when the bus is idle, and waiting for all +//! bus transmiton complete.(Read Buffer Step1) +//! +//! \param ulBase is the base address of the I2C Master module. +//! \param ucSlaveAddr is the 7-bit slave address. +//! \param pucDataBuf is the buffer where to save the data. +//! \param ulLen is the data number to receive. +//! \param bEndTransmition is flag to control if transmit the STOP condition and +//! terminate this transmition. +//! +//! This function init a new data buffer receive transmition. When the master +//! have not obtained control of the bus, This function send request to transmit +//! the START condition, the slave address and the data request, then waiting for +//! the data transmition complete, and continue next data transmition, until all +//! complete. If there is any error occurs, the remain data will be canceled. +//! +//! If bEndTransmition is xtrue, the receive operation will followed by an +//! negative ACK and STOP condition. +//! +//! Users can then check the return value to see how many datas have been +//! successfully received. if the number != ulLen, user can call +//! I2CMasterErr() to see what error occurs. +//! +//! After the master obtained control of the bus, and haven't release it, users +//! can call I2CMasterReadS2() or I2CMasterReadBufS2() to continue receive data . +//! from slave .Users call also can I2CMasterStop() to terminate this transmition +//! and release the I2C bus. +//! +//! This function is usually used in thread mode. +//! +//! \return Returns the data number that have been successully received. +// +//***************************************************************************** +unsigned long +xI2CMasterReadBufS1(unsigned long ulBase, unsigned char ucSlaveAddr, + unsigned char* pucDataBuf, unsigned long ulLen, + xtBoolean bEndTransmition) +{ + unsigned long ulStatus,ulStatusStart; + unsigned long ulRead; + + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + xASSERT(pucDataBuf); + + if(ulLen == 0) + return 0; + + else if(ulLen == 1) + { + ulStatus = xI2CMasterReadS1(ulBase, ucSlaveAddr, + pucDataBuf, bEndTransmition); + + if (ulStatus == xI2C_MASTER_ERR_NONE) + { + pucDataBuf[0] = xHWREG(ulBase + I2C_DAT); + + return 1; + } + else + { + return 0; + } + } + + xHWREG(ulBase + I2C_CON) |= I2C_CON_AA; + + // + // Send start and address + // + ulStatusStart = I2CStartSend(ulBase); + if(!((ulStatusStart == I2C_I2STAT_M_TX_START) || + (ulStatusStart == I2C_I2STAT_M_TX_RESTART))) + { + I2CStopSend(ulBase); + return 0; + } + // + // Send address + // + //ulStatus = I2CByteSend(ulBase, (ucSlaveAddr << 1) | 1) ; + // + // Make sure start bit is not active,but do not clear SI + // + if (xHWREG(ulBase + I2C_CON) & I2C_CON_STA) + { + xHWREG(ulBase + I2C_CON) &= ~(I2C_CON_STA | I2C_CON_SI); + } + + // + // Send data to I2C BUS + // + xHWREG(ulBase + I2C_DAT) = (ucSlaveAddr << 1) | 1; + + // + // Make sure AA and EI bit is not active,and clear SI + // + xHWREG(ulBase + I2C_CON) &= ~(I2C_CON_EI); + + // + // Wait the SI be set again by hardware + // + while (!(xHWREG(ulBase + I2C_CON) & I2C_CON_SI)); + + // + // Return the i2c status + // + ulStatus = (xHWREG(ulBase + I2C_STATUS) & I2C_STATUS_M); + if(!(ulStatus == I2C_I2STAT_M_RX_SLAR_ACK)) + { + I2CStopSend(ulBase); + return 0; + } + + // + // Waiting the I2C controller to be transmited + // + //xI2CMasterReadRequestS1(ulBase, ucSlaveAddr, xfalse); + if(ulStatusStart == I2C_I2STAT_M_TX_RESTART) + { + xHWREG(ulBase + I2C_CON) |= I2C_CON_AA; + } + xSysCtlDelay(100); + xHWREG(ulBase + I2C_CON) |= I2C_CON_SI; + + while (!(xHWREG(ulBase + I2C_CON) & I2C_CON_SI)); + + pucDataBuf[0] = xHWREG(ulBase + I2C_DAT); + + //ulStatus = I2CByteGet(ulBase, &pucDataBuf[0], 1); + + ulRead = 1; + ulRead += xI2CMasterReadBufS2(ulBase, + &pucDataBuf[1], + ulLen - 1, + bEndTransmition); + + return ulRead; +} + +//***************************************************************************** +// +//! \brief Read some data from a slave when the master have obtained control of +//! the bus, and waiting for all bus transmiton complete.(Write Buffer Step2) +//! +//! \param ulBase is the base address of the I2C Master module. +//! \param ucSlaveAddr is the 7-bit slave address. +//! \param pucDataBuf is the buffer where to save the data. +//! \param ulLen is the data number to receive. +//! \param bEndTransmition is flag to control if transmit the STOP condition and +//! terminate this transmition. +//! +//! After the master obtained control of the bus(have called +//! I2CMasterReadS1() or I2CMasterReadBufS1() without any error), and haven't +//! release it, users can call this function to continue receive data from slave. +//! +//! This function receive data one by one from the slave, waiting for every +//! data transmition complete, and continue next data transmition, until all +//! complete. If there is any error occurs, the remain data will be canceled. +//! +//! If bEndTransmition is xtrue, the receive operation will followed by an +//! negative ACK and STOP condition. +//! +//! Users can then check the return value to see how many datas have been +//! successfully received. if the number != ulLen, user can call +//! I2CMasterErr() to see what error occurs. +//! +//! After the master obtained control of the bus, and haven't release it, users +//! can call I2CMasterReadS2() or I2CMasterReadBufS2() to continue receive data +//! from slave. Users call also can I2CMasterStop() to terminate this transmition +//! and release the I2C bus. +//! +//! This function is usually used in thread mode. +//! +//! \return Returns the data number that have been successully received. +// +//***************************************************************************** +unsigned long +xI2CMasterReadBufS2(unsigned long ulBase, unsigned char *pucDataBuf, + unsigned long ulLen, xtBoolean bEndTransmition) +{ + unsigned long i; + unsigned long ulStatus; + + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + xASSERT(pucDataBuf); + + if(ulLen == 0) + return 0; + + for(i = 0; i < ulLen - 1; i++) + { + // + // Issue an ACK signal for next data frame + // + ulStatus = I2CByteGet(ulBase, pucDataBuf++, 1); + if (ulStatus != I2C_I2STAT_M_RX_DAT_ACK) + { + I2CStopSend(ulBase); + return i; + } + } + + if(bEndTransmition) + { + xHWREG(ulBase + I2C_CON) &= ~(I2C_CON_AA|I2C_CON_SI); + } + + xHWREG(ulBase + I2C_CON) |= I2C_CON_SI; + + while (!(xHWREG(ulBase + I2C_CON) & I2C_CON_SI)); + + *pucDataBuf = xHWREG(ulBase + I2C_DAT); + + if(bEndTransmition) + { + I2CStopSend(ulBase); + } + + return ulLen; +} + +//***************************************************************************** +// +//! \brief Set the clock rate of the specified I2C port. +//! +//! \param ulBase specifies the I2C module base address. +//! \param ucSlaveAddr specifies the slave address. +//! \param ulGeneralCall specifies enable General Call function or not. +//! +//! This function is to Set 4 7-bit slave addresses and enable General Call +//! function of specified I2C port. +//! +//! The \e ulBase can be one of the following values: +//! \b I2C0_BASE. +//! +//! The \e ucSlaveAddr is the I2C slave address,There are 4 slave addrss. +//! The ucSlaveAddr can be a 7-bit value. +//! +//! The \e ulGeneralCall is to enable the General Call function or not. +//! The ulGeneralCall can be one of the following values: +//! \b I2C_GENERAL_CALL_EN,\b I2C_GENERAL_CALL_DIS. +//! +//! \note this is only for slave +//! +//! \return None. +// +//***************************************************************************** +void +xI2CSlaveInit(unsigned long ulBase, unsigned char ucSlaveAddr, + unsigned long ulGeneralCall) +{ + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + + xSysCtlPeripheralReset(xSYSCTL_PERIPH_I2C0); + + xHWREG(ulBase + I2C_CON) = I2C_CON_ENS1; + + xHWREG(ulBase + I2C_CON) = 0; + + xHWREG(ulBase + I2C_ADDR0) = (ucSlaveAddr << 1) | ulGeneralCall; + + xHWREG(ulBase + I2C_CON) = I2C_CON_ENS1; + xHWREG(ulBase + I2C_CON) |= I2C_CON_AA; +} + +//***************************************************************************** +// +//! \brief Slave Send a byte to I2C bus. +//! This function is to send a byte on specified I2C BUS. +//! +//! \param [in] ulBase is the I2C module base address. +//! +//! The \e ulBase can be one of the following values: +//! \b I2C0_BASE. +//! +//! \param [in] ucData specifies the data which will send to I2C BUS. +//! +//! \return None. +//! +//! \note This is only for slave +// +//***************************************************************************** +void xI2CSlaveDataPut(unsigned long ulBase, unsigned char ucData) +{ + xI2CMasterDataPut(ulBase, ucData); +} + +//***************************************************************************** +//! \brief Slave receive a byte to I2C bus. +//! This function is to receive a byte on specified I2C BUS. +//! +//! \param [in] ulBase is the I2C module base address. +//! +//! The \e ulBase can be one of the following values: +//! \b I2C0_BASE. +//! +//! \return None. +//! +//! \note This is only for slave +// +//***************************************************************************** +unsigned long xI2CSlaveDataGet(unsigned long ulBase) +{ + return xI2CMasterDataGet(ulBase); +} + +//***************************************************************************** +// +//! \brief Set the slave address of the specified I2C port. +//! +//! \param ulBase specifies the I2C module base address. +//! \param ucSlaveNum specifies the salve address number. +//! \param ucSlaveAddr specifies the slave address. +//! \param ulGeneralCall specifies enable General Call function or not. +//! +//! This function is to Set 4 7-bit slave addresses and enable General Call +//! function of specified I2C port. +//! +//! The \e ulBase can be one of the following values: +//! \b I2C0_BASE. +//! +//! The \e ucSlaveNum is the I2C slave address number,There are 4 slave addrss,so +//! The ucSlaveNum can be: \b 0, \b 1, \b 2, \b 3. +//! +//! The \e ucSlaveAddr is the I2C slave address,There are 4 slave addrss. +//! The ucSlaveAddr can be a 7-bit value. +//! +//! The \e ulGeneralCall is to enable the General Call function or not. +//! The ulGeneralCall can be one of the following values: +//! \b I2C_GENERAL_CALL_EN,\b I2C_GENERAL_CALL_DIS. +//! +//! \note this is only for slave +//! +//! \return None. +// +//***************************************************************************** +void +I2CSlaveOwnAddressSet(unsigned long ulBase, unsigned char ucSlaveNum, + unsigned char ucSlaveAddr, unsigned long ulGeneralCall) +{ + unsigned long ulTemp[4] = {0x04, 0x18, 0x1C, 0x20}; + + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + + // + // Check the arguments. + // + xASSERT((ucSlaveNum == 0) || (ucSlaveNum == 1) || + (ucSlaveNum == 2) || (ucSlaveNum == 3)); + + // + // Check the arguments. + // + xASSERT((ulGeneralCall == I2C_GENERAL_CALL_EN) || + (ulGeneralCall == I2C_GENERAL_CALL_DIS)); + + + xHWREG(ulBase + ulTemp[ucSlaveNum]) |= ((ucSlaveAddr << 1) | + ulGeneralCall); +} + +//***************************************************************************** +// +//! \brief Set 4 7-bit slave address mask of the specified I2C port. +//! +//! \param ulBase specifies the I2C module base address. +//! \param ucSlaveNum specifies the salve address number. +//! \param ucSlaveAddrMask specifies the slave address mask. +//! +//! This function is to Set 4 7-bit slave address mask +//! of specified I2C port.The corresponding address bit is "Don't Care" +//! +//! The \e ulBase can be one of the following values: +//! \b I2C0_BASE. +//! +//! The \e ucSlaveNum is the I2C slave address number,There are 4 slave addrss,so +//! The ucSlaveNum can be: \b 0, \b 1, \b 2, \b 3. +//! +//! The \e ucSlaveAddrMask is the I2C slave address mask,There are 4 slave addrss. +//! The ucSlaveAddrMask can be a 7-bit value. +//! +//! \note this is only for slave +//! +//! \return None. +// +//***************************************************************************** +void +I2CSlaveOwnAddressMaskSet(unsigned long ulBase, + unsigned char ucSlaveNum, + unsigned char ucSlaveAddrMask) +{ + unsigned long ulTemp[4] = {0x24, 0x28, 0x2C, 0x30}; + + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + + // + // Check the arguments. + // + xASSERT((ucSlaveNum == 0) || (ucSlaveNum == 1) || + (ucSlaveNum == 2) || (ucSlaveNum == 3)); + + xHWREG(ulBase + ulTemp[ucSlaveNum]) |= (ucSlaveAddrMask << 1); +} + +//***************************************************************************** +// +//! \brief Get I2C status of the specified I2C port. +//! +//! \param ulBase specifies the I2C module base address. +//! +//! This function is to get I2C status of the specified I2C port. +//! There are 26 status codes. Please refer to Xi2c.h AU9110_I2C_STATUS_Type +//! in detail. +//! +//! The \e ulBase can be one of the following values: +//! \b I2C0_BASE. +//! +//! \note None +//! +//! \return I2C status. +// +//***************************************************************************** +unsigned long +I2CStatusGet(unsigned long ulBase) +{ + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + + return (xHWREG(ulBase + I2C_STATUS) & I2C_STATUS_M); +} + +//***************************************************************************** +// +//! \brief Enable I2C interrupt of the specified I2C port. +//! +//! \param ulBase specifies the I2C module base address. +//! +//! This function is to enable I2C interrupt of the specified I2C port. +//! +//! The \e ulBase can be one of the following values: +//! \b I2C0_BASE. +//! +//! \note None +//! +//! \return None. +// +//***************************************************************************** +void +xI2CMasterIntEnable(unsigned long ulBase, unsigned long ulIntType) +{ + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + + xHWREG(ulBase + I2C_CON) |= I2C_CON_EI; + xIntEnable(xINT_I2C0); +} + +//***************************************************************************** +// +//! \brief Enables the I2C Slave interrupt. +//! +//! \param [in] ulBase is the I2C module base address. +//! - \ref xI2C0_BASE +//! +//! \param [in] ulIntType is the interrupt type of the I2C module. +//! This value can be one of the following value: +//! - \ref xI2C_SLAVE_INT_STOP +//! - \ref xI2C_SLAVE_INT_DATA +//! +//! \return None. +// +//***************************************************************************** +void +xI2CSlaveIntEnable(unsigned long ulBase, unsigned long ulIntType) +{ + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + + xHWREG(ulBase + I2C_CON) |= I2C_CON_EI; +} + +//***************************************************************************** +// +//! \brief Init interrupts callback for the specified Port. +//! +//! \param ulPort is the base address of the I2C port. +//! \param xtI2CCallback is callback for the specified Port. +//! +//! Init interrupts callback for the specified Port. +//! +//! \return None. +// +//***************************************************************************** +void +xI2CIntCallbackInit(unsigned long ulBase, xtEventCallback xtI2CCallback) +{ + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + + g_pfnI2CHandlerCallbacks[I2CNumGet(ulBase)] = xtI2CCallback; +} + +//***************************************************************************** +// +//! \brief Disable I2C interrupt of the specified I2C port. +//! +//! \param ulBase specifies the I2C module base address. +//! +//! This function is to disable I2C interrupt of the specified I2C port. +//! +//! The \e ulBase can be one of the following values: +//! \b I2C0_BASE. +//! +//! \note None +//! +//! \return None. +// +//***************************************************************************** +void +xI2CMasterIntDisable(unsigned long ulBase, unsigned long ulIntType) +{ + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + + xHWREG(ulBase + I2C_CON) &= ~I2C_CON_EI; +} + +//***************************************************************************** +// +//! \brief Disables the I2C Slave interrupt. +//! +//! \param [in] ulBase is the I2C module base address. +//! - \ref xI2C0_BASE +//! +//! \param [in] ulIntType is the interrupt type of the I2C module. +//! This value can be one of the following value: +//! - \ref xI2C_SLAVE_INT_STOP +//! - \ref xI2C_SLAVE_INT_DATA +//! +//! \return None. +// +//***************************************************************************** +void +xI2CSlaveIntDisable(unsigned long ulBase, unsigned long ulIntType) +{ + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + + xHWREG(ulBase + I2C_CON) &= ~I2C_CON_EI; +} + +//***************************************************************************** +// +//! \brief Get the I2C interrupt flag of the specified I2C port. +//! +//! \param ulBase specifies the I2C module base address. +//! +//! This function is to get the I2C interrupt flag of the specified I2C port. +//! +//! The \e ulBase can be one of the following values: +//! \b I2C0_BASE. +//! +//! \note None +//! +//! \return a xtBoolean value xtrue or xfalse. +// +//***************************************************************************** +unsigned long +xI2CMasterIntFlagGet(unsigned long ulBase) +{ + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + + return ((xHWREG(ulBase + I2C_CON) & I2C_CON_SI) ? xtrue : xfalse); +} + +//***************************************************************************** +// +//! Gets the current I2C Slave status. +//! +//! \param ulBase is the base address of the I2C module. +//! - \ref xI2C0_BASE +//! +//! This function reads the bytes of data from the I2C Slave status Register. +//! +//! \return Returns the bytes(unsigned long) of I2C Slave status Register. +// +//***************************************************************************** +unsigned char xI2CSlaveIntFlagGet(unsigned long ulBase) +{ + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + + return ((xHWREG(ulBase + I2C_CON) & I2C_CON_SI) ? xtrue : xfalse); +} +//***************************************************************************** +// +//! \brief Enable I2C master module of the specified I2C port. +//! +//! \param ulBase specifies the I2C module base address. +//! +//! This function is to enable I2C module of the specified I2C port. +//! +//! The \e ulBase can be one of the following values: +//! \b I2C0_BASE. +//! +//! \note None +//! +//! \return None. +// +//***************************************************************************** +void +xI2CMasterEnable(unsigned long ulBase) +{ + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + + xHWREG(ulBase + I2C_CON) |= I2C_CON_ENS1; +} + +//***************************************************************************** +// +//! \brief Enables the I2C Slave block. +//! This will enable operation of the I2C Slave block. +//! +//! \param [in] ulBase is the I2C module base address. +//! +//! The \e ulBase can be one of the following values: +//! \b I2C0_BASE. +//! +//! \return None. +// +//***************************************************************************** +void xI2CSlaveEnable(unsigned long ulBase) +{ + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + + xHWREG(ulBase + I2C_CON) |= I2C_CON_ENS1; +} + +//***************************************************************************** +// +//! \brief Disable I2C master module of the specified I2C port. +//! +//! \param ulBase specifies the I2C module base address. +//! +//! This function is to disable I2C module of the specified I2C port. +//! +//! The \e ulBase can be one of the following values: +//! \b I2C0_BASE. +//! +//! \note None +//! +//! \return None. +// +//***************************************************************************** +void +xI2CMasterDisable(unsigned long ulBase) +{ + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + + xHWREG(ulBase + I2C_CON) &= ~I2C_CON_ENS1; +} + +//***************************************************************************** +// +//! \brief Disables the I2C slave block. +//! This will disable operation of the I2C slave block. +//! +//! \param [in] ulBase is the I2C module base address. +//! +//! The \e ulBase can be one of the following values: +//! \b I2C0_BASE. +//! +//! \return None. +// +//***************************************************************************** +void xI2CSlaveDisable(unsigned long ulBase) +{ + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + + xHWREG(ulBase + I2C_CON) &= ~I2C_CON_ENS1; +} +//***************************************************************************** +// +//! \brief Get the I2C time out flag of the specified I2C port. +//! +//! \param ulBase specifies the I2C module base address. +//! +//! This function is to get the I2C time out flag of the specified I2C port. +//! +//! The \e ulBase can be one of the following values: +//! \b I2C0_BASE. +//! +//! \note None +//! +//! \return a xtBoolean value xtrue or xfalse. +// +//***************************************************************************** +xtBoolean +I2CTimeoutFlagGet(unsigned long ulBase) +{ + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + + return ((xHWREG(ulBase + I2C_TOC) & I2C_TOC_TIF) ? xtrue : xfalse); +} + +//***************************************************************************** +// +//! \brief Clear the I2C interrupt flag of the specified I2C port. +//! +//! \param ulBase specifies the I2C module base address. +//! +//! This function is to clear the I2C interrupt flag of the specified I2C port. +//! +//! The \e ulBase can be one of the following values: +//! \b I2C0_BASE. +//! +//! \note None +//! +//! \return None. +// +//***************************************************************************** +void +I2CIntFlagClear(unsigned long ulBase) +{ + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + + xHWREG(ulBase + I2C_CON) |= I2C_CON_SI; +} + +//***************************************************************************** +// +//! \brief Clear the I2C time out flag of the specified I2C port. +//! +//! \param ulBase specifies the I2C module base address. +//! +//! This function is to clear the I2C time out flag of the specified I2C port. +//! +//! The \e ulBase can be one of the following values: +//! \b I2C0_BASE. +//! +//! \note None +//! +//! \return None. +// +//***************************************************************************** +void +I2CTimeoutFlagClear(unsigned long ulBase) +{ + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + + xHWREG(ulBase + I2C_TOC) |= I2C_TOC_TIF; +} + +//***************************************************************************** +// +//! \brief Enable/Disable I2C 14-bit timeout counter of the specified I2C port. +//! +//! \param ulBase specifies the I2C module base address. +//! \param ulEnable specifies Enable/Disable 14-bit timeout counter. +//! \param ulDiv4 specifies 4 time the 14-bit timeout counter or not. +//! +//! This function is to Enable/Disable I2C 14-bit timeout counter and +//! set div4 bit of timeout counter of the specified I2C port. +//! +//! The \e ulBase can be one of the following values: +//! \b I2C0_BASE. +//! +//! The \e ulEnable can be one of the following values: +//! \b I2C_TIMEOUT_EN, \b I2C_TIMEOUT_DIS. +//! +//! The \e ulDiv4 can be one of the following values: +//! \b I2C_TIMEOUT_DIV4, \b I2C_TIMEOUT_DIV_NO. +//! +//! \note None +//! +//! \return None. +// +//***************************************************************************** +void +I2CTimeoutCounterSet(unsigned long ulBase, unsigned long ulEnable, + unsigned long ulDiv4) +{ + // + // Check the arguments. + // + xASSERT((ulBase == I2C0_BASE)); + + // + // Check the arguments. + // + xASSERT((ulEnable == I2C_TIMEOUT_EN) || (ulEnable == I2C_TIMEOUT_DIS)); + + // + // Check the arguments. + // + xASSERT((ulDiv4 == I2C_TIMEOUT_DIV4) || (ulDiv4 == I2C_TIMEOUT_DIV_NO)); + + xHWREG(ulBase + I2C_TOC) &= ~0x00000006; + xHWREG(ulBase + I2C_TOC) |= ulEnable | ulDiv4; +} diff --git a/CoX/CoX_Peripheral/CoX_Peripehral_AU9110/libcox/pwm.c b/CoX/CoX_Peripheral/CoX_Peripehral_AU9110/libcox/pwm.c new file mode 100644 index 00000000..886a957e --- /dev/null +++ b/CoX/CoX_Peripheral/CoX_Peripehral_AU9110/libcox/pwm.c @@ -0,0 +1,1049 @@ +//***************************************************************************** +// +//! \file xpwm.c +//! \brief Driver for the AU9110 PWM +//! \version V2.1.1.1 +//! \date 11/14/2011 +//! \author CooCox +//! \copy +//! +//! Copyright (c) 2011, CooCox +//! All rights reserved. +//! +//! Redistribution and use in source and binary forms, with or without +//! modification, are permitted provided that the following conditions +//! are met: +//! +//! * Redistributions of source code must retain the above copyright +//! notice, this list of conditions and the following disclaimer. +//! * Redistributions in binary form must reproduce the above copyright +//! notice, this list of conditions and the following disclaimer in the +//! documentation and/or other materials provided with the distribution. +//! * Neither the name of the nor the names of its +//! contributors may be used to endorse or promote products derived +//! from this software without specific prior written permission. +//! +//! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +//! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +//! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +//! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +//! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +//! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +//! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +//! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +//! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +//! THE POSSIBILITY OF SUCH DAMAGE. +// +//***************************************************************************** + +#include "CoX.h" +#include "pwm.h" + +//***************************************************************************** +// +// An array is PWM Callback function point +// +//***************************************************************************** +static xtEventCallback g_pfnPWMHandlerCallbacks[2]={0}; + + +//***************************************************************************** +// +//! \brief The PWMA default IRQ, declared in start up code. +//! +//! \param None. +//! +//! This function is to give a default PWMA IRQ service. +//! +//! \note The Callback function have two effective parameters,One is indicate +//! is a PWM or Capture interrupt.And the other one show which channel have a +//! interrupt,bit0 in ulPWMStastus shows PWM_CHANNEL0,bit1 in ulPWMStastus +//! shows PWM_CHANNEL1,bit2 in ulPWMStastus shows PWM_CHANNEL2 and bit3 in +//! ulPWMStastus shows PWM_CHANNEL3. +//! Only the last four bits(0~3 bits) is effective. +//! +//! \return None. +// +//***************************************************************************** +void +PWMAIntHandler(void) +{ + unsigned long ulPWMStastus; + unsigned long ulCAPStastus0; + unsigned long ulBase = PWMA_BASE; + + // + //! Clear the PWMA INT Flag + // + ulPWMStastus = xHWREG(ulBase + PWM_PIIR) & 0xF; + xHWREG(ulBase + PWM_PIIR) = ulPWMStastus; + + ulCAPStastus0 = xHWREG(ulBase + PWM_CCR0) & 0x100010; + + if (g_pfnPWMHandlerCallbacks[0] != 0) + { + if(ulPWMStastus != 0) + { + g_pfnPWMHandlerCallbacks[0](0, PWM_EVENT_PWM, ulPWMStastus, 0); + } + if(ulCAPStastus0 != 0) + { + ulPWMStastus = 0; + if (ulCAPStastus0 & 0x10) + { + ulPWMStastus |= (1 << PWM_CHANNEL0); + } + if (ulCAPStastus0 & 0x100000) + { + ulPWMStastus |= (1 << PWM_CHANNEL1); + } + g_pfnPWMHandlerCallbacks[0](0, PWM_EVENT_CAP, ulPWMStastus, 0); + } + } + xHWREG(ulBase + PWM_CCR0) |= ulCAPStastus0; +} + +//***************************************************************************** +// +//! \internal +//! \brief Get the PWM module's clock. +//! +//! \param ulBase is the base address of the PWM port. +//! +//! This function is to get the PWM module's clock. +//! +//! +//! \return the PWM module's input clock. +// +//***************************************************************************** +static unsigned long +PWMClockGet(unsigned long ulBase, unsigned long ulChannel) +{ + unsigned long ulTemp; + unsigned long ulPWMFreq; + + ulTemp = ulChannel; + + // + // Check the arguments. + // + xASSERT(ulBase == PWMA_BASE); + xASSERT(((ulTemp >= 0) || (ulTemp <= 1))); + switch(ulChannel) + { + case PWM_CHANNEL0: + case PWM_CHANNEL1: + ulTemp = ((xHWREG(SYSCLK_CLKSEL1) & SYSCLK_CLKSEL1_PWM01_M) >> + SYSCLK_CLKSEL1_PWM01_S); + break; + default: + break; + } + if (ulTemp == 0) + { + ulPWMFreq = 12000000; + } + else if (ulTemp == 1) + { + ulPWMFreq = 32768; + } + else if (ulTemp == 2) + { + ulPWMFreq = SysCtlHClockGet(); + } + else + { + ulPWMFreq = 22118400; + } + return ulPWMFreq; +} + +//***************************************************************************** +// +//! \brief Initialize and configure the PWM module. +//! +//! \param ulBase is the base address of the PWM port. +//! \param ulChannel is the PWM channel. +//! \param ulConfig is the configuration of PWM channel. +//! +//! This function is to initialize and configure channel of the PWM module. +//! +//! The \e ulChannel parameter can be values: xPWM_CHANNEL0 or xPWM_CHANNEL1. +//! +//! The \e ulConfig parameter is the logical OR of four values: The PWM mode, +//! Inverter or not,and use dead zero or not and dead zone length. +//! \b PWM_ONE_SHOT_MODE,\b PWM_TOGGLE_MODE is the mode selecet. +//! \b PWM_OUTPUT_INVERTER_EN, +//! \b PWM_OUTPUT_INVERTER_DIS is to enable Inverter or not.\b PWM_DEAD_ZONE_EN +//! \b PWM_DEAD_ZONE_DIS is to enable dead zone Generator or not. +//! The dead zone length will be set at the 16~23 bits of the ulConfig. +//! +//! \note When Dead-Zone Generator is enabled, the pair of PWM0 and PWM1 +//! becomes a complementary pair for PWM group A and the pair of PWM4 and +//! PWM5 becomes a complementary pair for PWM group B. +//! +//! \return None. +// +//***************************************************************************** +void +xPWMInitConfigure(unsigned long ulBase, unsigned long ulChannel, + unsigned long ulConfig) +{ + unsigned long ulChannelTemp; + + ulChannelTemp = ulChannel; + + // + // Check the arguments. + // + xASSERT(ulBase == PWMA_BASE); + xASSERT(((ulChannelTemp >= 0) || (ulChannelTemp <= 1))); + xASSERT((ulConfig & 0xFFFFFF00) == 0); + xASSERT(((ulConfig & PWM_PCR_CH0INV) == PWM_OUTPUT_INVERTER_EN) || + ((ulConfig & PWM_PCR_CH0INV) == PWM_OUTPUT_INVERTER_DIS)); + + xASSERT(((ulConfig & PWM_PCR_CH0MOD) == PWM_ONE_SHOT_MODE) || + ((ulConfig & PWM_PCR_CH0MOD) == PWM_TOGGLE_MODE)); + + xASSERT(((ulConfig & PWM_DEAD_ZONE_EN) == PWM_DEAD_ZONE_EN) || + ((ulConfig & PWM_DEAD_ZONE_EN) == PWM_DEAD_ZONE_DIS)); + + xSysCtlPeripheralReset(xSYSCTL_PERIPH_PWMA); + + xHWREG(ulBase + PWM_PCR) |= ((ulConfig & 0xF) << (ulChannelTemp * 8)); + if (ulConfig & PWM_DEAD_ZONE_EN) + { + xHWREG(ulBase + PWM_PCR) |= (PWM_DEAD_ZONE_EN << (ulChannelTemp >> 1)); + xHWREG(ulBase + PWM_PPR) &= ~(PWM_PPR_DZI01_M << + (ulChannelTemp >> 1) * 8); + xHWREG(ulBase + PWM_PPR) |= ((ulConfig & PWM_PPR_DZI01_M) << + (ulChannelTemp >> 1) * 8); + } +} + + +//***************************************************************************** +// +//! \brief Set the PWM frequency of the PWM module. +//! +//! \param ulBase is the base address of the PWM port. +//! \param ulChannel is the PWM channel. +//! \param ulFrequency is the PWM frequency of PWM channel. +//! +//! This function is to set the PWM frequency of the PWM module. +//! +//! The \e ulChannel parameter can be values: xPWM_CHANNEL0 or xPWM_CHANNEL1. +//! +//! The \e ulFrequency parameter can be values: Any values ,ulFrequency > 0 && +//! ulFrequency < PWM module input clock. +//! +//! \note +//! +//! \return the Actual Frequency of PWM, if return 0 . +// +//***************************************************************************** +unsigned long +xPWMFrequencySet(unsigned long ulBase, unsigned long ulChannel, + unsigned long ulFrequency) +{ + unsigned long ulFrepDiv; + unsigned long ulActualFrep; + unsigned short usCNRData; + unsigned char ucDivider; + unsigned short usPreScale; + unsigned char i; + + // + // Check the arguments. + // + xASSERT(ulBase == PWMA_BASE); + xASSERT(((ulChannel >= 0) || (ulChannel <= 1))); + xASSERT(((ulFrequency > 0) || + (ulFrequency <= PWMClockGet(ulBase, ulChannel)))); + + ulFrepDiv = PWMClockGet(ulBase, ulChannel) / ulFrequency; + + xASSERT(ulFrepDiv <= 0x10000000); + + ucDivider = 1; + usPreScale = 1; + + if (ulFrepDiv < 0x100000) + { + i = 0; + while((ulFrepDiv/(ucDivider << i++)) > 65536); + ucDivider = ucDivider << (i - 1); + } + else + { + usPreScale = ulFrepDiv / 65536; + if (ulFrepDiv / usPreScale > 65536) + { + usPreScale++; + } + if (usPreScale > 256) + { + usPreScale = 256; + ulFrepDiv = ulFrepDiv / usPreScale; + ucDivider = ulFrepDiv / 65536; + + if(ulFrepDiv / ucDivider > 65536) + ucDivider++; + i = 0; + while(1) + { + if((1 << i++) > ucDivider) + { + break; + } + } + ucDivider = 1 << (i - 1); + + if (ucDivider > 16) + { + return 0; + } + + ulFrepDiv = ulFrepDiv * usPreScale; + } + } + usCNRData = (unsigned short)(ulFrepDiv / usPreScale / ucDivider); + ulActualFrep = (PWMClockGet(ulBase, ulChannel) / usPreScale / ucDivider / + usCNRData); + + xHWREG(ulBase + PWM_PPR) &= ~(PWM_PPR_CP01_M << (ulChannel / 2)); + xHWREG(ulBase + PWM_PPR) |= ((usPreScale - 1) << (ulChannel / 2)); + + switch(ucDivider) + { + case 1: + ucDivider = PWM_CLOCK_DIV_1; + break; + + case 2: + ucDivider = PWM_CLOCK_DIV_2; + break; + + case 4: + ucDivider = PWM_CLOCK_DIV_4; + break; + + case 8: + ucDivider = PWM_CLOCK_DIV_8; + break; + + case 16: + ucDivider = PWM_CLOCK_DIV_16; + break; + + } + xHWREG(ulBase + PWM_CSR) &= ~(PWM_CSR_CSR0_M << (ulChannel << 2)); + xHWREG(ulBase + PWM_CSR) |= (ucDivider << (ulChannel << 2)); + + xHWREG(ulBase + PWM_CNR0 +(ulChannel * 12)) = usCNRData - 1; + + return ulActualFrep; +} + +//***************************************************************************** +// +//! \brief Set the PWM frequency of the PWM module. +//! +//! \param ulBase is the base address of the PWM port. +//! \param ulChannel is the PWM channel. +//! \param ulConfig is the configuration of PWM channel' frequency. +//! +//! This function is to set the PWM frequency of the PWM module. +//! +//! The \e ulChannel parameter can be values: xPWM_CHANNEL0 or xPWM_CHANNEL1. +//! +//! The \e ulConfig parameter is the logical OR of three values: The PreScale +//! value, The Divider value and the PWM Counter Register value. +//! +//! \note +//! +//! \return the Actual Frequency of PWM. +// +//***************************************************************************** +unsigned long +xPWMFrequencyConfig(unsigned long ulBase, unsigned long ulChannel, + unsigned long ulConfig) +{ + // + // Check the arguments. + // + xASSERT(ulBase == PWMA_BASE)); + xASSERT(((ulChannel >= 0) || (ulChannel <= 1))); + + xHWREG(ulBase + PWM_PPR) &= ~(PWM_PPR_CP01_M << (ulChannel / 2 * 8)); + xHWREG(ulBase + PWM_PPR) |= (((ulConfig & 0xFF0000) >> 16) + << (ulChannel / 2 * 8)); + + xHWREG(ulBase + PWM_CSR) &= ~(PWM_CSR_CSR0_M << (ulChannel << 2)); + xHWREG(ulBase + PWM_CSR) |= (((ulConfig & 0x7000000) >> 24) + << (ulChannel << 2)); + + xHWREG(ulBase + PWM_CNR0 +(ulChannel * 12)) = (ulConfig & 0xFFFF); + + switch(((ulConfig & 0x7000000) >> 24)) + { + case PWM_CLOCK_DIV_1: + ulChannel = 1; + break; + + case PWM_CLOCK_DIV_2: + ulChannel = 2; + break; + + case PWM_CLOCK_DIV_4: + ulChannel = 4; + break; + + case PWM_CLOCK_DIV_8: + ulChannel = 8; + break; + + case PWM_CLOCK_DIV_16: + ulChannel = 16; + break; + } + + return (PWMClockGet(ulBase, ulChannel) / (((ulConfig & 0xFF0000) >> 16) + 1) + / ulChannel / ((ulConfig & 0xFFFF) + 1)); +} + +//***************************************************************************** +// +//! \brief Set the PWM duty of the PWM module. +//! +//! \param ulBase is the base address of the PWM port. +//! \param ulChannel is the PWM channel. +//! \param ulDuty is the duty of PWM channel. +//! +//! This function is to set the PWM duty of the PWM module. +//! +//! The \e ulChannel parameter can be values: xPWM_CHANNEL0 or xPWM_CHANNEL1. +//! +//! The \e ulDuty parameter can be values: duty > 0 && duty <= 100. +//! +//! \note Duty should not be 0; +//! +//! \return None. +// +//***************************************************************************** +void +xPWMDutySet(unsigned long ulBase, unsigned long ulChannel, + unsigned char ulDuty) +{ + unsigned long ulCMRData; + + // + // Check the arguments. + // + xASSERT(ulBase == PWMA_BASE); + xASSERT(((ulChannel >= 0) || (ulChannel <= 1))); + xASSERT(((ulDuty > 0) || (ulDuty <= 100))); + + ulCMRData = (xHWREG(ulBase + PWM_CNR0 +(ulChannel * 12)) + 1) * + ulDuty / 100 - 1; + if ((xHWREG(ulBase + PWM_CNR0 +(ulChannel * 12)) + 1) *ulDuty / 100 == 0) + { + ulCMRData = 0; + } + xHWREG(ulBase + PWM_CMR0 +(ulChannel * 12)) = ulCMRData; +} + +//***************************************************************************** +// +//! \brief Get the PWM duty of the PWM module. +//! +//! \param ulBase is the base address of the PWM port. +//! \param ulChannel is the PWM channel. +//! +//! This function is to get the PWM duty of the PWM module. +//! +//! The \e ulChannel parameter can be values: xPWM_CHANNEL0 or xPWM_CHANNEL1. +//! +//! \note None +//! +//! \return the Actual duty of PWM. +// +//***************************************************************************** +unsigned long +xPWMDutyGet(unsigned long ulBase, unsigned long ulChannel) +{ + unsigned long ulCMRData; + unsigned long ulCNRData; + + // + // Check the arguments. + // + xASSERT(ulBase == PWMA_BASE); + xASSERT(((ulChannel >= 0) || (ulChannel <= 1))); + + ulCNRData = (xHWREG(ulBase + PWM_CNR0 +(ulChannel * 12))); + ulCMRData = (xHWREG(ulBase + PWM_CMR0 +(ulChannel * 12))); + ulChannel = (ulCMRData + 1) * 100 / (ulCNRData + 1); + return ulChannel; +} + +//***************************************************************************** +// +//! \brief get the PWM frequency of the PWM module. +//! +//! \param ulBase is the base address of the PWM port. +//! \param ulChannel is the PWM channel. +//! +//! This function is to get the PWM frequency of the PWM module. +//! +//! The \e ulChannel parameter can be values: xPWM_CHANNEL0 or xPWM_CHANNEL1. +//! +//! \note None +//! +//! \return the Actual Frequency of PWM. +// +//***************************************************************************** +unsigned long +xPWMFrequencyGet(unsigned long ulBase, unsigned long ulChannel) +{ + unsigned long ulCNRData; + unsigned char ucDivider; + unsigned short usPreScale; + + // + // Check the arguments. + // + xASSERT(ulBase == PWMA_BASE); + xASSERT(((ulChannel >= 0) || (ulChannel <= 1))); + + usPreScale = ((xHWREG(ulBase + PWM_PPR) >> (ulChannel << 2)) & + PWM_CSR_CSR0_M); + + ucDivider = (xHWREG(ulBase + PWM_CSR) >> (ulChannel << 2)) & + PWM_CSR_CSR0_M; + + switch(ucDivider) + { + case PWM_CLOCK_DIV_1: + ucDivider = 1; + break; + + case PWM_CLOCK_DIV_2: + ucDivider = 2; + break; + + case PWM_CLOCK_DIV_4: + ucDivider = 4; + break; + + case PWM_CLOCK_DIV_8: + ucDivider = 8; + break; + + case PWM_CLOCK_DIV_16: + ucDivider = 16; + break; + default: + break; + } + ulCNRData = xHWREG(ulBase + PWM_CNR0 +(ulChannel * 12)); + return (PWMClockGet(ulBase, ulChannel) / (usPreScale + 1) / ucDivider / + ulCNRData); +} + +//***************************************************************************** +// +//! \brief Enable the PWM output of the PWM module. +//! +//! \param ulBase is the base address of the PWM port. +//! \param ulChannel is the PWM channel. +//! +//! This function is to enable the PWM output of the PWM module. +//! +//! The \e ulChannel parameter can be values: xPWM_CHANNEL0 or xPWM_CHANNEL1. +//! +//! \note None +//! +//! \return None. +// +//***************************************************************************** +void +xPWMOutputEnable(unsigned long ulBase, unsigned long ulChannel) +{ + // + // Check the arguments. + // + xASSERT(ulBase == PWMA_BASE); + xASSERT(((ulChannel >= 0) || (ulChannel <= 1))); + + xHWREG(ulBase + PWM_POE) |= (PWM_POE_PWM0 << (ulChannel)); +} + +//***************************************************************************** +// +//! \brief Disable the PWM output of the PWM module. +//! +//! \param ulBase is the base address of the PWM port. +//! \param ulChannel is the PWM channel. +//! +//! This function is to disable the PWM output of the PWM module. +//! +//! The \e ulChannel parameter can be values: xPWM_CHANNEL0 or xPWM_CHANNEL1. +//! +//! \note None +//! +//! \return None. +// +//***************************************************************************** +void +xPWMOutputDisable(unsigned long ulBase, unsigned long ulChannel) +{ + // + // Check the arguments. + // + xASSERT(ulBase == PWMA_BASE); + xASSERT(((ulChannel >= 0) || (ulChannel <= 1))); + + xHWREG(ulBase + PWM_POE) &= ~(PWM_POE_PWM0 << (ulChannel)); +} + +//***************************************************************************** +// +//! \brief Start the PWM of the PWM module. +//! +//! \param ulBase is the base address of the PWM port. +//! \param ulChannel is the PWM channel. +//! +//! This function is to start the PWM of the PWM module. +//! +//! The \e ulChannel parameter can be values: xPWM_CHANNEL0 or xPWM_CHANNEL1. +//! +//! \note None +//! +//! \return None. +// +//***************************************************************************** +void +xPWMStart(unsigned long ulBase, unsigned long ulChannel) +{ + // + // Check the arguments. + // + xASSERT(ulBase == PWMA_BASE); + xASSERT(((ulChannel >= 0) || (ulChannel <= 1))); + + xHWREG(ulBase + PWM_PCR) |= (PWM_PCR_CH0EN << (ulChannel << 3)); +} + +//***************************************************************************** +// +//! \brief Stop the PWM of the PWM module. +//! +//! \param ulBase is the base address of the PWM port. +//! \param ulChannel is the PWM channel. +//! +//! This function is to stop the PWM of the PWM module. +//! +//! The \e ulChannel parameter can be values: xPWM_CHANNEL0 or xPWM_CHANNEL1. +//! +//! \note None +//! +//! \return None. +// +//***************************************************************************** +void +xPWMStop(unsigned long ulBase, unsigned long ulChannel) +{ + // + // Check the arguments. + // + xASSERT(ulBase == PWMA_BASE); + xASSERT(((ulChannel >= 0) || (ulChannel <= 1))); + + xHWREG(ulBase + PWM_PCR) &= ~(PWM_PCR_CH0EN << (ulChannel << 3)); +} + +//***************************************************************************** +// +//! \brief Enable the PWM interrupt of the PWM module. +//! +//! \param ulBase is the base address of the PWM port. +//! \param ulChannel is the PWM channel. +//! \param ulIntType is the PWM channel interrupt type. +//! +//! This function is to enable the PWM interrupt of the PWM module. +//! +//! The \e ulChannel parameter can be values: xPWM_CHANNEL0 or xPWM_CHANNEL1. +//! +//! //! The \e ulIntType parameter can be values: +//! \b PWM_INT_CAP_BOTH, \b PWM_INT_CAP_FALL, \b PWM_INT_CAP_RISE and +//! \b PWM_INT_PWM. +//! +//! \note None +//! +//! \return None. +// +//***************************************************************************** +void +xPWMIntEnable(unsigned long ulBase, unsigned long ulChannel, + unsigned long ulIntType) +{ + // + // Check the arguments. + // + xASSERT(ulBase == PWMA_BASE); + xASSERT(((ulChannel >= 0) || (ulChannel <= 3))); + xASSERT((ulIntType == PWM_INT_CAP_BOTH) || (ulIntType == PWM_INT_CAP_FALL) || + (ulIntType == PWM_INT_CAP_RISE) || (ulIntType == PWM_INT_PWM)); + + if (ulIntType == PWM_INT_PWM) + { + xHWREG(ulBase + PWM_PIER) |= (PWM_PIER_PWMIE0 << ulChannel); + } + else + { + xHWREG(ulBase + PWM_CCR0 + (ulChannel >> 1)*4) |= + (ulIntType << ((ulChannel % 2) ? 16 : 0)); + } +} + +//***************************************************************************** +// +//! \brief Disable the PWM interrupt of the PWM module. +//! +//! \param ulBase is the base address of the PWM port. +//! \param ulChannel is the PWM channel. +//! \param ulIntType is the PWM channel interrupt type. +//! +//! This function is to disable the PWM interrupt of the PWM module. +//! +//! The \e ulChannel parameter can be values: xPWM_CHANNEL0 or xPWM_CHANNEL1. +//! +//! //! The \e ulIntType parameter can be values: +//! \b PWM_INT_CAP_BOTH, \b PWM_INT_CAP_FALL, \b PWM_INT_CAP_RISE and +//! \b PWM_INT_PWM. +//! +//! \note None +//! +//! \return None. +// +//***************************************************************************** +void +xPWMIntDisable(unsigned long ulBase, unsigned long ulChannel, + unsigned long ulIntType) +{ + // + // Check the arguments. + // + xASSERT(ulBase == PWMA_BASE); + xASSERT(((ulChannel >= 0) || (ulChannel <= 3))); + + xASSERT((ulIntType == PWM_INT_CAP_BOTH) || (ulIntType == PWM_INT_CAP_FALL) || + (ulIntType == PWM_INT_CAP_RISE) || (ulIntType == PWM_INT_PWM)); + + if (ulIntType == PWM_INT_PWM) + { + xHWREG(ulBase + PWM_PIER) &= ~(PWM_PIER_PWMIE0 << ulChannel); + } + else + { + xHWREG(ulBase + PWM_CCR0 + (ulChannel >> 1)*4) &= + ~(ulIntType << ((ulChannel % 2) ? 16 : 0)); + } +} + +//***************************************************************************** +// +//! \brief Get the PWM interrupt flag of the PWM module. +//! +//! \param ulBase is the base address of the PWM port. +//! \param ulChannel is the PWM channel. +//! \param ulIntType is the PWM channel interrupt type. +//! +//! This function is to get the PWM interrupt flag of the PWM module. +//! +//! The \e ulChannel parameter can be values: xPWM_CHANNEL0 or xPWM_CHANNEL1. +//! +//! //! The \e ulIntType parameter can be values: +//! \b PWM_INT_CAP_BOTH, \b PWM_INT_CAP_FALL, \b PWM_INT_CAP_RISE and +//! \b PWM_INT_PWM. +//! +//! \note None +//! +//! \return None. +// +//***************************************************************************** +xtBoolean +xPWMIntFlagGet(unsigned long ulBase, unsigned long ulChannel, + unsigned long ulIntType) +{ + // + // Check the arguments. + // + xASSERT((ulBase == PWMA_BASE) || (ulBase == PWMB_BASE)); + xASSERT(((ulChannel >= 0) || (ulChannel <= 3))); + + xASSERT((ulIntType == PWM_INT_CAP_BOTH) || (ulIntType == PWM_INT_CAP_FALL) || + (ulIntType == PWM_INT_CAP_RISE) || (ulIntType == PWM_INT_PWM)); + + if (ulIntType == PWM_INT_PWM) + { + return ((xHWREG(ulBase + PWM_PIER) & (PWM_PIER_PWMIE0 << ulChannel)) + ? xtrue : xfalse); + } + else + { + return ((xHWREG(ulBase + PWM_CCR0 + (ulChannel << 1)) & + (PWM_CCR0_CAPIF0 << ((ulChannel % 2) ? 16 : 0))) ? xtrue : xfalse); + } +} + +//***************************************************************************** +// +//! \brief Clear the PWM interrupt flag of the PWM module. +//! +//! \param ulBase is the base address of the PWM port. +//! \param ulChannel is the PWM channel. +//! \param ulIntType is the PWM channel interrupt type. +//! +//! This function is to Clear the PWM interrupt flag of the PWM module. +//! +//! The \e ulChannel parameter can be values: xPWM_CHANNEL0 or xPWM_CHANNEL1. +//! +//! The \e ulIntType parameter can be values: +//! \b PWM_INT_CAP_BOTH, \b PWM_INT_CAP_FALL, \b PWM_INT_CAP_RISE and +//! \b PWM_INT_PWM. +//! +//! \note None +//! +//! \return None. +// +//***************************************************************************** +void +PWMIntFlagClear(unsigned long ulBase, unsigned long ulChannel, + unsigned long ulIntType) +{ + // + // Check the arguments. + // + xASSERT(ulBase == PWMA_BASE); + xASSERT(((ulChannel >= 0) || (ulChannel <= 3))); + + xASSERT((ulIntType == PWM_INT_CAP_BOTH) || (ulIntType == PWM_INT_CAP_FALL) || + (ulIntType == PWM_INT_CAP_RISE) || (ulIntType == PWM_INT_PWM)); + + if (ulIntType == PWM_INT_PWM) + { + xHWREG(ulBase + PWM_PIIR) |= (PWM_PIER_PWMIE0 << ulChannel); + } + else + { + xHWREG(ulBase + PWM_CCR0 + (ulChannel << 1)) |= + (PWM_CCR0_CAPIF0 << ((ulChannel % 2) ? 16 : 0)) ; + } +} + +//***************************************************************************** +// +//! \brief Init interrupts callback for the PWM timer. +//! +//! \param xtPortCallback is callback for the PWM timer. +//! +//! This function is to init interrupts callback for the PWM timer. +//! +//! \return None. +// +//***************************************************************************** +void +xPWMIntCallbackInit(unsigned long ulBase, xtEventCallback xtPWMCallback) +{ + // + // Check the arguments. + // + xASSERT(ulBase == PWMA_BASE); + + if (xtPWMCallback != 0) + { + if (ulBase == PWMA_BASE) + { + g_pfnPWMHandlerCallbacks[0] = xtPWMCallback; + } + else + { + g_pfnPWMHandlerCallbacks[1] = xtPWMCallback; + } + } +} + +//***************************************************************************** +// +//! \brief Enable the Capture of the PWM module. +//! +//! \param ulBase is the base address of the PWM port. +//! \param ulChannel is the PWM channel. +//! +//! This function is to Enable the Capture of the PWM module. +//! +//! The \e ulChannel parameter can be values: xPWM_CHANNEL0 or xPWM_CHANNEL1. +//! +//! \note None +//! +//! \return None. +// +//***************************************************************************** +void +PWMCAPEnable(unsigned long ulBase, unsigned long ulChannel) +{ + // + // Check the arguments. + // + xASSERT(ulBase == PWMA_BASE); + xASSERT(((ulChannel >= 0) || (ulChannel <= 3))); + + xHWREG(ulBase + PWM_CCR0 + (ulChannel >> 1)*4) |= + (PWM_CCR0_CAPCH0EN << ((ulChannel % 2) ? 16 : 0)); + xHWREG(ulBase + PWM_PCR) |= (PWM_PCR_CH0EN << (ulChannel << 3)); +} + +//***************************************************************************** +// +//! \brief Disable the Capture of the PWM module. +//! +//! \param ulBase is the base address of the PWM port. +//! \param ulChannel is the PWM channel. +//! +//! This function is to disable the Capture of the PWM module. +//! +//! The \e ulChannel parameter can be values: xPWM_CHANNEL0 or xPWM_CHANNEL1. +//! +//! \note None +//! +//! \return None. +// +//***************************************************************************** +void +PWMCAPDisable(unsigned long ulBase, unsigned long ulChannel) +{ + // + // Check the arguments. + // + xASSERT(ulBase == PWMA_BASE); + xASSERT(((ulChannel >= 0) || (ulChannel <= 3))); + + xHWREG(ulBase + PWM_CCR0 + (ulChannel >> 1)*4) &= + ~(PWM_CCR0_CAPCH0EN << ((ulChannel % 2) ? 16 : 0)); + xHWREG(ulBase + PWM_PCR) &= ~(PWM_PCR_CH0EN << (ulChannel << 3)); +} + +//***************************************************************************** +// +//! \brief Enable the Capture input of the PWM module. +//! +//! \param ulBase is the base address of the PWM port. +//! \param ulChannel is the PWM channel. +//! +//! This function is to enable the Capture input of the PWM module. +//! +//! The \e ulChannel parameter can be values: xPWM_CHANNEL0 or xPWM_CHANNEL1. +//! +//! \note None +//! +//! \return None. +// +//***************************************************************************** +void +PWMCAPInputEnable(unsigned long ulBase, unsigned long ulChannel) +{ + // + // Check the arguments. + // + xASSERT(ulBase == PWMA_BASE); + xASSERT(((ulChannel >= 0) || (ulChannel <= 3))); + + xHWREG(ulBase + PWM_CAPENR) |= (PWM_CAPENR_CAPIE_0 << (ulChannel)); +} + +//***************************************************************************** +// +//! \brief Disable the Capture input of the PWM module. +//! +//! \param ulBase is the base address of the PWM port. +//! \param ulChannel is the PWM channel. +//! +//! This function is to disable the Capture input of the PWM module. +//! +//! The \e ulChannel parameter can be values: xPWM_CHANNEL0 or xPWM_CHANNEL1. +//! +//! \note None +//! +//! \return None. +// +//***************************************************************************** +void +PWMCAPInputDisable(unsigned long ulBase, unsigned long ulChannel) +{ + // + // Check the arguments. + // + xASSERT(ulBase == PWMA_BASE); + xASSERT(((ulChannel >= 0) || (ulChannel <= 3))); + + xHWREG(ulBase + PWM_CAPENR) &= ~(PWM_CAPENR_CAPIE_0 << (ulChannel)); +} + +//***************************************************************************** +// +//! \brief Get the Rising Latched PWM counter of the PWM module. +//! +//! \param ulBase is the base address of the PWM port. +//! \param ulChannel is the PWM channel. +//! +//! This function is to Get the Rising Latched PWM counter of the PWM module. +//! +//! The \e ulChannel parameter can be values: xPWM_CHANNEL0 or xPWM_CHANNEL1. +//! +//! \note None +//! +//! \return PWM counter when Channel \b ulChannel has rising transition. +// +//***************************************************************************** +unsigned long +PWMCAPRisingCounterGet(unsigned long ulBase, unsigned long ulChannel) +{ + // + // Check the arguments. + // + xASSERT(ulBase == PWMA_BASE); + xASSERT(((ulChannel >= 0) || (ulChannel <= 3))); + + return xHWREG(ulBase + PWM_CRLR0 + ulChannel * 8); +} + +//***************************************************************************** +// +//! \brief Get the Falling Latched PWM counter of the PWM module. +//! +//! \param ulBase is the base address of the PWM port. +//! \param ulChannel is the PWM channel. +//! +//! This function is to Get the Falling Latched PWM counter of the PWM module. +//! +//! The \e ulChannel parameter can be values: xPWM_CHANNEL0 or xPWM_CHANNEL1. +//! +//! \note None +//! +//! \return PWM counter when Channel \b ulChannel has Falling transition. +// +//***************************************************************************** +unsigned long +PWMCAPFallingCounterGet(unsigned long ulBase, unsigned long ulChannel) +{ + // + // Check the arguments. + // + xASSERT(ulBase == PWMA_BASE); + xASSERT(((ulChannel >= 0) || (ulChannel <= 3))); + + return xHWREG(ulBase + PWM_CFLR0 + ulChannel * 8); +} diff --git a/CoX/CoX_Peripheral/CoX_Peripehral_AU9110/startup/src/startup_coide.c b/CoX/CoX_Peripheral/CoX_Peripehral_AU9110/startup/src/startup_coide.c index a1f308fb..0fca744b 100644 --- a/CoX/CoX_Peripheral/CoX_Peripehral_AU9110/startup/src/startup_coide.c +++ b/CoX/CoX_Peripheral/CoX_Peripehral_AU9110/startup/src/startup_coide.c @@ -1,481 +1,302 @@ -/** - ****************************************************************************** - * @file startup_Cortex_M4.c - * @author Coocox - * @version V1.0 - * @date 06/06/2014 - * @brief Cortex M4 Devices Startup code. - * This module performs: - * - Set the initial SP - * - Set the vector table entries with the exceptions ISR address - * - Initialize data and bss - * - Call the application's entry point. - * After Reset the Cortex-M4 processor is in Thread mode, - * priority is Privileged, and the Stack is set to Main. - ******************************************************************************* - */ - -//#ifdef __cplusplus -// extern "C" { -//#endif +//***************************************************************************** +// +//! \file startup_coide.c +//! \brief NUC122 Devices Startup code for CooCox CoIDE. +//! This module performs: +//! - Set the initial SP +//! - Set the vector table entries with the exceptions ISR address +//! - Initialize data and bss +//! - Setup the microcontroller system. +//! - Call the application's entry point. +//! . +//! \version V2.1.1.0 +//! \date 7/22/2012 +//! \author CooCox +//! \copy +//! +//! Copyright (c) 2011, CooCox +//! All rights reserved. +//! +//! Redistribution and use in source and binary forms, with or without +//! modification, are permitted provided that the following conditions +//! are met: +//! +//! * Redistributions of source code must retain the above copyright +//! notice, this list of conditions and the following disclaimer. +//! * Redistributions in binary form must reproduce the above copyright +//! notice, this list of conditions and the following disclaimer in the +//! documentation and/or other materials provided with the distribution. +//! * Neither the name of the nor the names of its +//! contributors may be used to endorse or promote products derived +//! from this software without specific prior written permission. +//! +//! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +//! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +//! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +//! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +//! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +//! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +//! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +//! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +//! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +//! THE POSSIBILITY OF SUCH DAMAGE. +// +//***************************************************************************** -/*----------Stack Configuration-----------------------------------------------*/ -#define STACK_SIZE 0x00000800 /*!< Stack size (in Words) */ +//***************************************************************************** +// +// Stack Configuration +// +//***************************************************************************** +// +// Stack size (in Words) +// +#define STACK_SIZE 0x00000100 __attribute__ ((section(".co_stack"))) unsigned long pulStack[STACK_SIZE]; - - -/*----------Macro definition--------------------------------------------------*/ + #define WEAK __attribute__ ((weak)) +//***************************************************************************** +// +// Declaration of the default fault handlers +// +//***************************************************************************** +void WEAK ResetHandler(void); +void WEAK NMIIntHandler(void); +void WEAK HardFaultIntHandler(void); +void WEAK MemManageIntHandler(void); +void WEAK BusFaultIntHandler(void); +void WEAK UsageFaultIntHandler(void); +void WEAK SVCIntHandler(void); +void WEAK DebugMonIntHandler(void); +void WEAK PendSVIntHandler(void); +void WEAK SysTickIntHandler(void); +void WEAK BODIntHandler(void); +void WEAK WDTIntHandler(void); +void WEAK EINT0IntHandler(void); +void WEAK EINT1IntHandler(void); +void WEAK GPABIntHandler(void); +void WEAK GPCDIntHandler(void); +void WEAK PWMAIntHandler(void); +void WEAK TIMER0IntHandler(void); +void WEAK TIMER1IntHandler(void); +void WEAK TIMER2IntHandler(void); +void WEAK TIMER3IntHandler(void); +void WEAK UART0IntHandler(void); +void WEAK UART1IntHandler(void); +void WEAK SPI0IntHandler(void); +void WEAK SPI1IntHandler(void); +void WEAK I2C0IntHandler(void); +void WEAK USBDIntHandler(void); +void WEAK PS2IntHandler(void); +void WEAK PWRWUIntHandler(void); +void WEAK RTCIntHandler(void); -/*----------Declaration of the default fault handlers-------------------------*/ -/* System exception vector handler */ -__attribute__ ((used)) -void WEAK Reset_Handler(void); -void WEAK NMI_Handler(void); -void WEAK HardFault_Handler(void); -void WEAK MemManage_Handler(void); -void WEAK BusFault_Handler(void); -void WEAK UsageFault_Handler(void); -void WEAK SVC_Handler(void); -void WEAK DebugMon_Handler(void); -void WEAK PendSV_Handler(void); -void WEAK SysTick_Handler(void); +//***************************************************************************** +// +// Symbols defined in linker script +// +//***************************************************************************** +// +// Start address for the initialization values of the .data section. +// +extern unsigned long _sidata; -void WEAK BOD_IRQHandler(void); -void WEAK IRC_IRQHandler(void); -void WEAK PWRWU_IRQHandler(void); -void WEAK SRAMF_IRQHandler(void); -void WEAK CLKF_IRQHandler(void); -void WEAK RTC_IRQHandler(void); -void WEAK TAMPER_IRQHandler(void); -void WEAK EINT0_IRQHandler(void); -void WEAK EINT1_IRQHandler(void); -void WEAK EINT2_IRQHandler(void); -void WEAK EINT3_IRQHandler(void); -void WEAK EINT4_IRQHandler(void); -void WEAK EINT5_IRQHandler(void); -void WEAK EINT6_IRQHandler(void); -void WEAK EINT7_IRQHandler(void); -void WEAK GPA_IRQHandler(void); -void WEAK GPB_IRQHandler(void); -void WEAK GPC_IRQHandler(void); -void WEAK GPD_IRQHandler(void); -void WEAK GPE_IRQHandler(void); -void WEAK GPF_IRQHandler(void); -void WEAK GPG_IRQHandler(void); -void WEAK GPH_IRQHandler(void); -void WEAK GPI_IRQHandler(void); -void WEAK TMR0_IRQHandler(void); -void WEAK TMR1_IRQHandler(void); -void WEAK TMR2_IRQHandler(void); -void WEAK TMR3_IRQHandler(void); -void WEAK PDMA_IRQHandler(void); -void WEAK ADC_IRQHandler(void); -void WEAK WDT_IRQHandler(void); -void WEAK WWDT_IRQHandler(void); -void WEAK EADC0_IRQHandler(void); -void WEAK EADC1_IRQHandler(void); -void WEAK EADC2_IRQHandler(void); -void WEAK EADC3_IRQHandler(void); -void WEAK ACMP_IRQHandler(void); -void WEAK OPA0_IRQHandler(void); -void WEAK OPA1_IRQHandler(void); -void WEAK ICAP0_IRQHandler(void); -void WEAK ICAP1_IRQHandler(void); -void WEAK PWM0CH0_IRQHandler(void); -void WEAK PWM0CH1_IRQHandler(void); -void WEAK PWM0CH2_IRQHandler(void); -void WEAK PWM0CH3_IRQHandler(void); -void WEAK PWM0CH4_IRQHandler(void); -void WEAK PWM0CH5_IRQHandler(void); -void WEAK PWM0_BRK_IRQHandler(void); -void WEAK QEI0_IRQHandler(void); -void WEAK PWM1CH0_IRQHandler(void); -void WEAK PWM1CH1_IRQHandler(void); -void WEAK PWM1CH2_IRQHandler(void); -void WEAK PWM1CH3_IRQHandler(void); -void WEAK PWM1CHCH4_IRQHandler(void); -void WEAK PWM1CH5_IRQHandler(void); -void WEAK PWM1_BRK_IRQHandler(void); -void WEAK QEI1_IRQHandler(void); -void WEAK EPWM0_IRQHandler(void); -void WEAK EPWM0BRK_IRQHandler(void); -void WEAK EPWM1_IRQHandler(void); -void WEAK EPWM1BRK_IRQHandler(void); -void WEAK USBD_IRQHandler(void); -void WEAK USBH_IRQHandler(void); -void WEAK USB_OTG_IRQHandler(void); -void WEAK EMAC_TX_IRQHandler(void); -void WEAK EMAC_RX_IRQHandler(void); -void WEAK SPI0_IRQHandler(void); -void WEAK SPI1_IRQHandler(void); -void WEAK SPI2_IRQHandler(void); -void WEAK SPI3_IRQHandler(void); -void WEAK UART0_IRQHandler(void); -void WEAK UART1_IRQHandler(void); -void WEAK UART2_IRQHandler(void); -void WEAK UART3_IRQHandler(void); -void WEAK UART4_IRQHandler(void); -void WEAK UART5_IRQHandler(void); -void WEAK I2C0_IRQHandler(void); -void WEAK I2C1_IRQHandler(void); -void WEAK I2C2_IRQHandler(void); -void WEAK I2C3_IRQHandler(void); -void WEAK I2C4_IRQHandler(void); -void WEAK SC0_IRQHandler(void); -void WEAK SC1_IRQHandler(void); -void WEAK SC2_IRQHandler(void); -void WEAK SC3_IRQHandler(void); -void WEAK SC4_IRQHandler(void); -void WEAK SC5_IRQHandler(void); -void WEAK CAN0_IRQHandler(void); -void WEAK CAN1_IRQHandler(void); -void WEAK I2S0_IRQHandler(void); -void WEAK I2S1_IRQHandler(void); -void WEAK SD_IRQHandler(void); -void WEAK PS2D_IRQHandler(void); -void WEAK CAP_IRQHandler(void); -void WEAK CRYPTO_IRQHandler(void); -void WEAK CRC_IRQHandler(void); +// +// Start address for the .data section +// +extern unsigned long _sdata; -/*----------Symbols defined in linker script----------------------------------*/ -extern unsigned long _sidata; /*!< Start address for the initialization - values of the .data section. */ -extern unsigned long _sdata; /*!< Start address for the .data section */ -extern unsigned long _edata; /*!< End address for the .data section */ -extern unsigned long _sbss; /*!< Start address for the .bss section */ -extern unsigned long _ebss; /*!< End address for the .bss section */ -extern void _eram; /*!< End address for ram */ +// +// End address for the .data section +// +extern unsigned long _edata; +// +// Start address for the .bss section +// +extern unsigned long _sbss; -/*----------Function prototypes-----------------------------------------------*/ -extern int main(void); /*!< The entry point for the application. */ -void Default_Reset_Handler(void); /*!< Default reset handler */ -static void Default_Handler(void); /*!< Default exception handler */ +// +// End address for the .bss section +// +extern unsigned long _ebss; +// +// End address for ram +// +extern void _eram; -/** - *@brief The minimal vector table for a Cortex M4. Note that the proper constructs - * must be placed on this to ensure that it ends up at physical address - * 0x00000000. - */ -__attribute__ ((used,section(".isr_vector"))) +//***************************************************************************** +// +// Function prototypes +// +//***************************************************************************** +extern int main(void); +void ResetHandler(void); +static void DefaultIntHandler(void); + +// +// The minimal vector table for a Cortex M0. Note that the proper constructs +// must be placed on this to ensure that it ends up at physical address +// 0x00000000. +// +__attribute__ ((section(".isr_vector"))) void (* const g_pfnVectors[])(void) = -{ - /*----------Core Exceptions------------------------------------------------ */ - (void *)&pulStack[STACK_SIZE-1], /*!< The initial stack pointer */ - Reset_Handler, /*!< Reset Handler */ - NMI_Handler, /*!< NMI Handler */ - HardFault_Handler, /*!< Hard Fault Handler */ - MemManage_Handler, /*!< MPU Fault Handler */ - BusFault_Handler, /*!< Bus Fault Handler */ - UsageFault_Handler, /*!< Usage Fault Handler */ - 0,0,0,0, /*!< Reserved */ - SVC_Handler, /*!< SVCall Handler */ - DebugMon_Handler, /*!< Debug Monitor Handler */ - 0, /*!< Reserved */ - PendSV_Handler, /*!< PendSV Handler */ - SysTick_Handler, /*!< SysTick Handler */ - BOD_IRQHandler, - IRC_IRQHandler, - PWRWU_IRQHandler, - SRAMF_IRQHandler, - CLKF_IRQHandler, - 0, - RTC_IRQHandler, - TAMPER_IRQHandler, - EINT0_IRQHandler, - EINT1_IRQHandler, - EINT2_IRQHandler, - EINT3_IRQHandler, - EINT4_IRQHandler, - EINT5_IRQHandler, - EINT6_IRQHandler, - EINT7_IRQHandler, - GPA_IRQHandler, - GPB_IRQHandler, - GPC_IRQHandler, - GPD_IRQHandler, - GPE_IRQHandler, - GPF_IRQHandler, - GPG_IRQHandler, - GPH_IRQHandler, - GPI_IRQHandler, - 0,0,0,0,0,0,0, - TMR0_IRQHandler, - TMR1_IRQHandler, - TMR2_IRQHandler, - TMR3_IRQHandler, - 0,0,0,0, - PDMA_IRQHandler, - 0, - ADC_IRQHandler, - 0,0,0, - WDT_IRQHandler, - WWDT_IRQHandler, - EADC0_IRQHandler, - EADC1_IRQHandler, - EADC2_IRQHandler, - EADC3_IRQHandler, - 0,0,0,0, - ACMP_IRQHandler, - 0,0,0, - OPA0_IRQHandler, - OPA1_IRQHandler, - ICAP0_IRQHandler, - ICAP1_IRQHandler, - PWM0CH0_IRQHandler, - PWM0CH1_IRQHandler, - PWM0CH2_IRQHandler, - PWM0CH3_IRQHandler, - PWM0CH4_IRQHandler, - PWM0CH5_IRQHandler, - PWM0_BRK_IRQHandler, - QEI0_IRQHandler, - PWM1CH0_IRQHandler, - PWM1CH1_IRQHandler, - PWM1CH2_IRQHandler, - PWM1CH3_IRQHandler, - PWM1CHCH4_IRQHandler, - PWM1CH5_IRQHandler, - PWM1_BRK_IRQHandler, - QEI1_IRQHandler, - EPWM0_IRQHandler, - EPWM0BRK_IRQHandler, - EPWM1_IRQHandler, - EPWM1BRK_IRQHandler, - 0,0,0,0, - USBD_IRQHandler, - USBH_IRQHandler, - USB_OTG_IRQHandler, - 0, - EMAC_TX_IRQHandler, - EMAC_RX_IRQHandler, - 0,0, - SPI0_IRQHandler, - SPI1_IRQHandler, - SPI2_IRQHandler, - SPI3_IRQHandler, - 0,0,0,0, - UART0_IRQHandler, - UART1_IRQHandler, - UART2_IRQHandler, - UART3_IRQHandler, - UART4_IRQHandler, - UART5_IRQHandler, - 0,0, - I2C0_IRQHandler, - I2C1_IRQHandler, - I2C2_IRQHandler, - I2C3_IRQHandler, - I2C4_IRQHandler, - 0,0,0, - SC0_IRQHandler, - SC1_IRQHandler, - SC2_IRQHandler, - SC3_IRQHandler, - SC4_IRQHandler, - SC5_IRQHandler, - 0,0, - CAN0_IRQHandler, - CAN1_IRQHandler, - 0,0, - I2S0_IRQHandler, - I2S1_IRQHandler, - 0,0, - SD_IRQHandler, - 0, - PS2D_IRQHandler, - CAP_IRQHandler, - CRYPTO_IRQHandler, - CRC_IRQHandler, - /*----------External Exceptions---------------------------------------------*/ +{ + (void *)&pulStack[STACK_SIZE], // The initial stack pointer + ResetHandler, // The reset handler + NMIIntHandler, // The NMI handler + HardFaultIntHandler, // The hard fault handler + MemManageIntHandler, // The MPU fault handler + BusFaultIntHandler, // The bus fault handler + UsageFaultIntHandler, // The usage fault handler + 0,0,0,0, // Reserved + SVCIntHandler, // SVCall handler + DebugMonIntHandler, // Debug monitor handler + 0, // Reserved + PendSVIntHandler, // The PendSV handler + SysTickIntHandler, // The SysTick handler + BODIntHandler, // Brownout low voltage detected + WDTIntHandler, // Watch Dog Timer + EINT0IntHandler, // External signal interrupt from + // PB.14 pin + EINT1IntHandler, // External signal interrupt from + // PB.15 pin + GPABIntHandler, // External signal interrupt from + // PA[15:0] / PB[13:0] + GPCDIntHandler, // External interrupt from + // PC[15:0]/PD[15:0] + PWMAIntHandler, // PWM0 or PWM2,PWM1 or PWM3 + DefaultIntHandler, // Reserved + TIMER0IntHandler, // Timer 0 + TIMER1IntHandler, // Timer 1 + TIMER2IntHandler, // Timer 2 + TIMER3IntHandler, // Timer 3 + UART0IntHandler, // UART0 + UART1IntHandler, // UART1 + SPI0IntHandler, // SPI0 + SPI1IntHandler, // SPI1 + DefaultIntHandler, // Reserved + DefaultIntHandler, // Reserved + DefaultIntHandler, // Reserved + I2C0IntHandler, // I2C + DefaultIntHandler, // Reserved + DefaultIntHandler, // Reserved + DefaultIntHandler, // Reserved + USBDIntHandler, // USB Device + PS2IntHandler, // PS2 + DefaultIntHandler, // Reserved + DefaultIntHandler, // Reserved + DefaultIntHandler, // Reserved + PWRWUIntHandler, // Clock controller + DefaultIntHandler, // Reserved + DefaultIntHandler, // Reserved + RTCIntHandler, // RTC }; - -/** - * @brief This is the code that gets called when the processor first - * starts execution following a reset event. Only the absolutely - * necessary set is performed, after which the application - * supplied main() routine is called. - * @param None - * @retval None - */ -void Default_Reset_Handler(void) +//***************************************************************************** +// +//! \brief This is the code that gets called when the processor first +//! starts execution following a reset event. +//! +//! \param None. +//! +//! Only the absolutely necessary set is performed, after which the +//! application supplied main() routine is called. +//! +//! \return None. +// +//***************************************************************************** +void Default_ResetHandler(void) { - /* Initialize data and bss */ + // + // Initialize data and bss + // unsigned long *pulSrc, *pulDest; - /* Copy the data segment initializers from flash to SRAM */ + // + // Copy the data segment initializers from flash to SRAM + // pulSrc = &_sidata; for(pulDest = &_sdata; pulDest < &_edata; ) { - *(pulDest++) = *(pulSrc++); + *(pulDest++) = *(pulSrc++); } - - /* Zero fill the bss segment. This is done with inline assembly since this - will clear the value of pulDest if it is not kept in a register. */ - __asm(" ldr r0, =_sbss\n" - " ldr r1, =_ebss\n" - " mov r2, #0\n" - " .thumb_func\n" - "zero_loop:\n" - " cmp r0, r1\n" - " it lt\n" - " strlt r2, [r0], #4\n" - " blt zero_loop"); -#ifdef __FPU_USED - /* Enable FPU.*/ - __asm(" LDR.W R0, =0xE000ED88\n" - " LDR R1, [R0]\n" - " ORR R1, R1, #(0xF << 20)\n" - " STR R1, [R0]"); -#endif + // + // Zero fill the bss segment. + // + for(pulDest = &_sbss; pulDest < &_ebss; ) + { + *(pulDest++) = 0; + } -#ifdef SUPPORT_CPLUSPLUS - extern void __libc_init_array(void); - __libc_init_array(); -#endif - - /* Call the application's entry point.*/ + // + // Call the application's entry point. + // main(); } +//***************************************************************************** +// +// Provide weak aliases for each Exception handler to the DefaultIntHandler. +// As they are weak aliases, any function with the same name will override +// this definition. +// +//***************************************************************************** +#pragma weak ResetHandler = Default_ResetHandler +#pragma weak NMIIntHandler = DefaultIntHandler +#pragma weak HardFaultIntHandler = DefaultIntHandler +#pragma weak MemManageIntHandler = DefaultIntHandler +#pragma weak BusFaultIntHandler = DefaultIntHandler +#pragma weak UsageFaultIntHandler = DefaultIntHandler +#pragma weak SVCIntHandler = DefaultIntHandler +#pragma weak DebugMonIntHandler = DefaultIntHandler +#pragma weak PendSVIntHandler = DefaultIntHandler +#pragma weak SysTickIntHandler = DefaultIntHandler +#pragma weak BODIntHandler = DefaultIntHandler +#pragma weak WDTIntHandler = DefaultIntHandler +#pragma weak EINT0IntHandler = DefaultIntHandler +#pragma weak EINT1IntHandler = DefaultIntHandler +#pragma weak GPABIntHandler = DefaultIntHandler +#pragma weak GPCDIntHandler = DefaultIntHandler +#pragma weak PWMAIntHandler = DefaultIntHandler +#pragma weak TIMER0IntHandler = DefaultIntHandler +#pragma weak TIMER1IntHandler = DefaultIntHandler +#pragma weak TIMER2IntHandler = DefaultIntHandler +#pragma weak TIMER3IntHandler = DefaultIntHandler +#pragma weak UART0IntHandler = DefaultIntHandler +#pragma weak UART1IntHandler = DefaultIntHandler +#pragma weak SPI0IntHandler = DefaultIntHandler +#pragma weak SPI1IntHandler = DefaultIntHandler +#pragma weak I2C0IntHandler = DefaultIntHandler +#pragma weak USBDIntHandler = DefaultIntHandler +#pragma weak PS2IntHandler = DefaultIntHandler +#pragma weak PWRWUIntHandler = DefaultIntHandler +#pragma weak RTCIntHandler = DefaultIntHandler -/** - *@brief Provide weak aliases for each Exception handler to the Default_Handler. - * As they are weak aliases, any function with the same name will override - * this definition. - */ -#pragma weak Reset_Handler = Default_Reset_Handler -#pragma weak NMI_Handler = Default_Handler -#pragma weak HardFault_Handler = Default_Handler -#pragma weak MemManage_Handler = Default_Handler -#pragma weak BusFault_Handler = Default_Handler -#pragma weak UsageFault_Handler = Default_Handler -#pragma weak SVC_Handler = Default_Handler -#pragma weak DebugMon_Handler = Default_Handler -#pragma weak PendSV_Handler = Default_Handler -#pragma weak SysTick_Handler = Default_Handler - -#pragma weak BOD_IRQHandler= Default_Handler -#pragma weak IRC_IRQHandler= Default_Handler -#pragma weak PWRWU_IRQHandler= Default_Handler -#pragma weak SRAMF_IRQHandler= Default_Handler -#pragma weak CLKF_IRQHandler= Default_Handler -#pragma weak RTC_IRQHandler= Default_Handler -#pragma weak TAMPER_IRQHandler= Default_Handler -#pragma weak EINT0_IRQHandler= Default_Handler -#pragma weak EINT1_IRQHandler= Default_Handler -#pragma weak EINT2_IRQHandler= Default_Handler -#pragma weak EINT3_IRQHandler= Default_Handler -#pragma weak EINT4_IRQHandler= Default_Handler -#pragma weak EINT5_IRQHandler= Default_Handler -#pragma weak EINT6_IRQHandler= Default_Handler -#pragma weak EINT7_IRQHandler= Default_Handler -#pragma weak GPA_IRQHandler= Default_Handler -#pragma weak GPB_IRQHandler= Default_Handler -#pragma weak GPC_IRQHandler= Default_Handler -#pragma weak GPD_IRQHandler= Default_Handler -#pragma weak GPE_IRQHandler= Default_Handler -#pragma weak GPF_IRQHandler= Default_Handler -#pragma weak GPG_IRQHandler= Default_Handler -#pragma weak GPH_IRQHandler= Default_Handler -#pragma weak GPI_IRQHandler= Default_Handler -#pragma weak TMR0_IRQHandler= Default_Handler -#pragma weak TMR1_IRQHandler= Default_Handler -#pragma weak TMR2_IRQHandler= Default_Handler -#pragma weak TMR3_IRQHandler= Default_Handler -#pragma weak PDMA_IRQHandler= Default_Handler -#pragma weak ADC_IRQHandler= Default_Handler -#pragma weak WDT_IRQHandler= Default_Handler -#pragma weak WWDT_IRQHandler= Default_Handler -#pragma weak EADC0_IRQHandler= Default_Handler -#pragma weak EADC1_IRQHandler= Default_Handler -#pragma weak EADC2_IRQHandler= Default_Handler -#pragma weak EADC3_IRQHandler= Default_Handler -#pragma weak ACMP_IRQHandler= Default_Handler -#pragma weak OPA0_IRQHandler= Default_Handler -#pragma weak OPA1_IRQHandler= Default_Handler -#pragma weak ICAP0_IRQHandler= Default_Handler -#pragma weak ICAP1_IRQHandler= Default_Handler -#pragma weak PWM0CH0_IRQHandler= Default_Handler -#pragma weak PWM0CH1_IRQHandler= Default_Handler -#pragma weak PWM0CH2_IRQHandler= Default_Handler -#pragma weak PWM0CH3_IRQHandler= Default_Handler -#pragma weak PWM0CH4_IRQHandler= Default_Handler -#pragma weak PWM0CH5_IRQHandler= Default_Handler -#pragma weak PWM0_BRK_IRQHandler= Default_Handler -#pragma weak QEI0_IRQHandler= Default_Handler -#pragma weak PWM1CH0_IRQHandler= Default_Handler -#pragma weak PWM1CH1_IRQHandler= Default_Handler -#pragma weak PWM1CH2_IRQHandler= Default_Handler -#pragma weak PWM1CH3_IRQHandler= Default_Handler -#pragma weak PWM1CHCH4_IRQHandler= Default_Handler -#pragma weak PWM1CH5_IRQHandler= Default_Handler -#pragma weak PWM1_BRK_IRQHandler= Default_Handler -#pragma weak QEI1_IRQHandler= Default_Handler -#pragma weak EPWM0_IRQHandler= Default_Handler -#pragma weak EPWM0BRK_IRQHandler= Default_Handler -#pragma weak EPWM1_IRQHandler= Default_Handler -#pragma weak EPWM1BRK_IRQHandler= Default_Handler -#pragma weak USBD_IRQHandler= Default_Handler -#pragma weak USBH_IRQHandler= Default_Handler -#pragma weak USB_OTG_IRQHandler= Default_Handler -#pragma weak EMAC_TX_IRQHandler= Default_Handler -#pragma weak EMAC_RX_IRQHandler= Default_Handler -#pragma weak SPI0_IRQHandler= Default_Handler -#pragma weak SPI1_IRQHandler= Default_Handler -#pragma weak SPI2_IRQHandler= Default_Handler -#pragma weak SPI3_IRQHandler= Default_Handler -#pragma weak UART0_IRQHandler= Default_Handler -#pragma weak UART1_IRQHandler= Default_Handler -#pragma weak UART2_IRQHandler= Default_Handler -#pragma weak UART3_IRQHandler= Default_Handler -#pragma weak UART4_IRQHandler= Default_Handler -#pragma weak UART5_IRQHandler= Default_Handler -#pragma weak I2C0_IRQHandler= Default_Handler -#pragma weak I2C1_IRQHandler= Default_Handler -#pragma weak I2C2_IRQHandler= Default_Handler -#pragma weak I2C3_IRQHandler= Default_Handler -#pragma weak I2C4_IRQHandler= Default_Handler -#pragma weak SC0_IRQHandler= Default_Handler -#pragma weak SC1_IRQHandler= Default_Handler -#pragma weak SC2_IRQHandler= Default_Handler -#pragma weak SC3_IRQHandler= Default_Handler -#pragma weak SC4_IRQHandler= Default_Handler -#pragma weak SC5_IRQHandler= Default_Handler -#pragma weak CAN0_IRQHandler= Default_Handler -#pragma weak CAN1_IRQHandler= Default_Handler -#pragma weak I2S0_IRQHandler= Default_Handler -#pragma weak I2S1_IRQHandler= Default_Handler -#pragma weak SD_IRQHandler= Default_Handler -#pragma weak PS2D_IRQHandler= Default_Handler -#pragma weak CAP_IRQHandler= Default_Handler -#pragma weak CRYPTO_IRQHandler= Default_Handler -#pragma weak CRC_IRQHandler= Default_Handler - -/** - * @brief This is the code that gets called when the processor receives an - * unexpected interrupt. This simply enters an infinite loop, - * preserving the system state for examination by a debugger. - * @param None - * @retval None - */ -static void Default_Handler(void) +//***************************************************************************** +// +//! \brief This is the code that gets called when the processor receives an +//! unexpected interrupt. +//! +//! \param None. +//! +//! This simply enters an infinite loop, preserving the system state for +//! examination by a debugger. +//! +//! \return None. +//***************************************************************************** +static void DefaultIntHandler(void) { - /* Go into an infinite loop. */ - while (1) + // + // Go into an infinite loop. + // + while (1) { } -} - -//#ifdef __cplusplus -//} -//#endif - -/*********************** (C) COPYRIGHT 2014 Coocox ************END OF FILE*****/ +} \ No newline at end of file From 1b8917559f1a2c3be9bf23185c8e878ea9f6d566 Mon Sep 17 00:00:00 2001 From: xinyun Date: Tue, 29 Jul 2014 16:17:28 +0800 Subject: [PATCH 09/13] change name of the cox files --- .../CoX_Peripheral_NUC4xx/libcox/acmp.c | 548 ++++++++++++++++++ .../libcox/{xadc.c => adc.c} | 6 +- .../libcox/{xcore.c => core.c} | 2 +- .../libcox/{xdma.c => dma.c} | 4 +- .../libcox/{xgpio.c => gpio.c} | 6 +- .../CoX_Peripheral_NUC4xx/libcox/gpio.h | 166 ++++++ .../CoX_Peripheral_NUC4xx/libcox/hw_acmp.h | 190 ++++++ .../libcox/{xhw_adc.h => hw_adc.h} | 2 +- .../libcox/{xhw_dma.h => hw_dma.h} | 2 +- .../libcox/{xhw_gpio.h => hw_gpio.h} | 2 +- .../libcox/{xhw_i2c.h => hw_i2c.h} | 2 +- .../libcox/{xhw_pwm.h => hw_pwm.h} | 2 +- .../libcox/{xhw_rtc.h => hw_rtc.h} | 2 +- .../libcox/{xhw_spi.h => hw_spi.h} | 2 +- .../libcox/{xhw_sysctl.h => hw_sysctl.h} | 2 +- .../libcox/{xhw_timer.h => hw_timer.h} | 2 +- .../libcox/{xhw_uart.h => hw_uart.h} | 2 +- .../libcox/{xhw_wdt.h => hw_wdt.h} | 2 +- .../libcox/{xi2c.c => i2c.c} | 6 +- .../libcox/{xpwm.c => pwm.c} | 8 +- .../libcox/{xrtc.c => rtc.c} | 8 +- .../libcox/{xspi.c => spi.c} | 6 +- .../libcox/{xsysctl.c => sysctl.c} | 4 +- .../libcox/{xtimer.c => timer.c} | 24 +- .../libcox/{xuart.c => uart.c} | 6 +- .../libcox/{xwdt.c => wdt.c} | 8 +- .../pwm/example/led/src/led.c | 25 + .../pwm/example/led/src/main.c | 6 + 28 files changed, 990 insertions(+), 55 deletions(-) create mode 100644 CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/acmp.c rename CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/{xadc.c => adc.c} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/{xcore.c => core.c} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/{xdma.c => dma.c} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/{xgpio.c => gpio.c} (99%) create mode 100644 CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/hw_acmp.h rename CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/{xhw_adc.h => hw_adc.h} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/{xhw_dma.h => hw_dma.h} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/{xhw_gpio.h => hw_gpio.h} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/{xhw_i2c.h => hw_i2c.h} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/{xhw_pwm.h => hw_pwm.h} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/{xhw_rtc.h => hw_rtc.h} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/{xhw_spi.h => hw_spi.h} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/{xhw_sysctl.h => hw_sysctl.h} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/{xhw_timer.h => hw_timer.h} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/{xhw_uart.h => hw_uart.h} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/{xhw_wdt.h => hw_wdt.h} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/{xi2c.c => i2c.c} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/{xpwm.c => pwm.c} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/{xrtc.c => rtc.c} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/{xspi.c => spi.c} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/{xsysctl.c => sysctl.c} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/{xtimer.c => timer.c} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/{xuart.c => uart.c} (99%) rename CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/{xwdt.c => wdt.c} (99%) create mode 100644 CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/pwm/example/led/src/led.c create mode 100644 CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/pwm/example/led/src/main.c diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/acmp.c b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/acmp.c new file mode 100644 index 00000000..8c4b205e --- /dev/null +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/acmp.c @@ -0,0 +1,548 @@ +//***************************************************************************** +// +//! \file acmp.c +//! \brief Driver for the analog comparator. +//! \version V2.1.1.0 +//! \date 1/3/2012 +//! \author CooCox +//! \copy +//! +//! Copyright (c) 2009-2011 CooCox. All rights reserved. +// +//***************************************************************************** + +#include "hw_acmp.h" +#include "CoX.h" + + +//***************************************************************************** +// +// The Interrupt Callback functions +// +//***************************************************************************** +static xtEventCallback g_pfnACMPHandlerCallbacks[2] = {0}; + +//***************************************************************************** +// +//! \brief Init the Comp n Interrupt Callback function. +//! +//! \param ulBase is the base address of the ADC. +//! \param ulCompID is the ID(index) of the comparator. +//! Refrence \ref xACMP_Comparator_IDs. +//! \param pfnCallback is the callback function. +//! +//! When there is any ADC interrupt occrus, Interrupt Handler will +//! call the callback function. +//! +//! param of pfnCallback +//! - pvCBData not used, always 0. +//! - ulEvent not used, always 0. +//! - ulMsgParam not used, always 0. +//! - pvMsgData not used, always 0. +//! . +//! +//! \return None. +// +//***************************************************************************** +void +xACMPIntCallbackInit(unsigned long ulBase, unsigned long ulCompID, + xtEventCallback pfnCallback) +{ + unsigned long Base; + // + // Check the arguments. + // + xASSERT((ulBase == ACMP_BASE)); + xASSERT((ulCompID == xACMP_0) || (ulCompID == xACMP_1)); + Base = ((ulBase == ACMP_BASE) ? 0 : 2); + + switch(ulCompID) + { + case xACMP_0: + { + g_pfnACMPHandlerCallbacks[Base+0] = pfnCallback; + break; + } + case xACMP_1: + { + g_pfnACMPHandlerCallbacks[Base+1] = pfnCallback; + break; + } + } +} + +#ifdef __cplusplus +extern "C" +{ +#endif + +//***************************************************************************** +// +//! \brief Comparator Interrupt Handler. +//! +//! If users want to user the ACMP Interrupt Callback feature, Users should +//! promise that the ACMP Handle in the vector table is ACMPIntHandler. +//! +//! \return None. +// +//***************************************************************************** +void +ACMP_IRQHandler(void) +{ + unsigned long ulBase = ACMP_BASE; + unsigned long ulIntFlags; + + // + // Get the Interrupt flags + // + ulIntFlags = xHWREG(ulBase + ACMP_SR); + + // + // Clear the Interrrupt flags + // + xHWREG(ulBase + ACMP_SR) = ulIntFlags; + + // + // Call user event callback function + // + if((ulIntFlags & ACMP_SR_CMPF0) && g_pfnACMPHandlerCallbacks[0]) + { + g_pfnACMPHandlerCallbacks[0](0, 0, 0, 0); + } + + if((ulIntFlags & ACMP_SR_CMPF1) && g_pfnACMPHandlerCallbacks[1]) + { + g_pfnACMPHandlerCallbacks[1](0, 0, 0, 0); + } +} +// +////***************************************************************************** +//// +////! \brief Comparator Interrupt Handler. +////! +////! If users want to user the ACMP Interrupt Callback feature, Users should +////! promise that the ACMP Handle in the vector table is ACMPIntHandler. +////! +////! \return None. +//// +////***************************************************************************** +//void +//ACMP23IntHandler(void) +//{ +// unsigned long ulBase = ACMP23_BASE; +// unsigned long ulIntFlags; +// +// // +// // Get the Interrupt flags +// // +// ulIntFlags = xHWREG(ulBase + ACMP_SR); +// +// // +// // Clear the Interrrupt flags +// // +// xHWREG(ulBase + ACMP_SR) = ulIntFlags; +// +// // +// // Call user event callback function +// // +// if((ulIntFlags & ACMP_SR_CMPF0) && g_pfnACMPHandlerCallbacks[0]) +// { +// g_pfnACMPHandlerCallbacks[3](0, 0, 0, 0); +// } +// +// if((ulIntFlags & ACMP_SR_CMPF1) && g_pfnACMPHandlerCallbacks[1]) +// { +// g_pfnACMPHandlerCallbacks[4](0, 0, 0, 0); +// } +//} +#ifdef __cplusplus +} +#endif +//***************************************************************************** +// +//! \brief Select the ACMP- input source of the comparator. +//! +//! \param ulBase is the base address of the comparator module. +//! \param ulComp is the index(0 - 1) of the comparator to configure. +//! \param ulSource is the source of Comp- input. +//! Refrence \ref M051_ACMP_Analog_Src_negative. +//! +//! This function configures the Comp- input source of a comparator. +//! +//! \return None. +// +//***************************************************************************** +void +ACMPNegativeSrcSet(unsigned long ulBase, unsigned long ulComp, + unsigned long ulSource) +{ + unsigned long ulCRAddr; + + xASSERT((ulBase == ACMP_BASE)); + xASSERT((ulComp >= 0) && (ulComp < 2)); + xASSERT((ulSource == ACMP_ASRCN_PIN) || (ulSource == ACMP_ASRCN_REF)); + + // + // Get the corresponding CR register address + // + ulCRAddr = ulBase + ACMP_CR0 + (4 * ulComp); + + // + // Set the comp- input source + // + xHWREG(ulCRAddr) &= ~ACMP_CR_CN; + xHWREG(ulCRAddr) |= ulSource; +} + +//***************************************************************************** +// +//! \brief Enable the comparator hysteresis function. +//! +//! \param ulBase is the base address of the comparator module. +//! \param ulComp is the index(0 - 1) of the comparator. +//! +//! This function enables hysteresis function of the comparator. +//! +//! \return None. +// +//***************************************************************************** +void +ACMPHysEnable(unsigned long ulBase, unsigned long ulComp) +{ + unsigned long ulCRAddr; + + xASSERT((ulBase == ACMP_BASE)); + xASSERT((ulComp >= 0) && (ulComp < 2)); + + // + // Get the corresponding CR register address + // + ulCRAddr = ulBase + ACMP_CR0 + (4 * ulComp); + + // + // Enable hysteresis function. The typical range is 20mV. + // + xHWREG(ulCRAddr) |= ACMP_CR_HYSEN; +} + +//***************************************************************************** +// +//! \brief Disable the comparator hysteresis function. +//! +//! \param ulBase is the base address of the comparator module. +//! \param ulComp is the index(0 - 1) of the comparator. +//! +//! This function disables hysteresis function of the comparator. +//! +//! \return None. +// +//***************************************************************************** +void +ACMPHysDisable(unsigned long ulBase, unsigned long ulComp) +{ + unsigned long ulCRAddr; + + xASSERT((ulBase == ACMP_BASE)); + xASSERT((ulComp >= 0) && (ulComp < 2)); + + // + // Get the corresponding CR register address + // + ulCRAddr = ulBase + ACMP_CR0 + (4 * ulComp); + + // + // Enable hysteresis function. The typical range is 20mV. + // + xHWREG(ulCRAddr) &= ~ACMP_CR_HYSEN; + +} + +//***************************************************************************** +// +//! \brief Enable the comparator. +//! +//! \param ulBase is the base address of the comparator module. +//! \param ulComp is the index(0 - 1) of the comparator. +//! +//! This function enables comparator. +//! +//! \return None. +// +//***************************************************************************** +void +ACMPEnable(unsigned long ulBase, unsigned long ulComp) +{ + unsigned long ulCRAddr; + + xASSERT((ulBase == ACMP_BASE)); + xASSERT((ulComp >= 0) && (ulComp < 2)); + + // + // Get the corresponding CR register address + // + ulCRAddr = ulBase + ACMP_CR0 + (4 * ulComp); + + // + // Enable the comparator + // + xHWREG(ulCRAddr) |= ACMP_CR_CMPEN; +} + +//***************************************************************************** +// +//! \brief Disable the comparator. +//! +//! \param ulBase is the base address of the comparator module. +//! \param ulComp is the index(0 - 1) of the comparator. +//! +//! This function disables comparator. +//! +//! \return None. +// +//***************************************************************************** +void +ACMPDisable(unsigned long ulBase, unsigned long ulComp) +{ + unsigned long ulCRAddr; + + xASSERT((ulBase == ACMP_BASE)); + xASSERT((ulComp >= 0) && (ulComp < 2)); + + // + // Get the corresponding CR register address + // + ulCRAddr = ulBase + ACMP_CR0 + (4 * ulComp); + + // + // Disable the comparator + // + xHWREG(ulCRAddr) &= ~ACMP_CR_CMPEN; +} + +//***************************************************************************** +// +//! \brief Enable the comparator interrupt. +//! +//! \param ulBase is the base address of the comparator module. +//! \param ulComp is the index(0 - 1) of the comparator. +//! +//! This function enables generation of an interrupt from the specified +//! comparator. Only comparators whose interrupts are enabled can be reflected +//! to the processor. +//! +//! \return None. +// +//***************************************************************************** +void +ACMPIntEnable(unsigned long ulBase, unsigned long ulComp) +{ + unsigned long ulCRAddr; + + xASSERT((ulBase == ACMP_BASE)); + xASSERT((ulComp >= 0) && (ulComp < 2)); + + // + // Get the corresponding CR register address + // + ulCRAddr = ulBase + ACMP_CR0 + (4 * ulComp); + + // + // Enable the comparator interrupt + // + xHWREG(ulCRAddr) |= ACMP_CR_CMPIE; + +} + +//***************************************************************************** +// +//! \brief Disable the comparator interrupt. +//! +//! \param ulBase is the base address of the comparator module. +//! \param ulComp is the index(0 - 1) of the comparator. +//! +//! This function disables generation of an interrupt from the specified +//! comparator. Only comparators whose interrupts are enabled can be reflected +//! to the processor. +//! +//! \return None. +// +//***************************************************************************** +void +ACMPIntDisable(unsigned long ulBase, unsigned long ulComp) +{ + unsigned long ulCRAddr; + + xASSERT((ulBase == ACMP_BASE)); + xASSERT((ulComp >= 0) && (ulComp < 2)); + + // + // Get the corresponding CR register address + // + ulCRAddr = ulBase + ACMP_CR0 + (4 * ulComp); + + // + // Disable the comparator interrupt + // + xHWREG(ulCRAddr) &= ~ACMP_CR_CMPIE; +} + +//***************************************************************************** +// +//! \brief Get the current interrupt status. +//! +//! \param ulBase is the base address of the comparator module. +//! \param ulComp is the index(0 - 1) of the comparator. +//! +//! This returns the interrupt status for the comparator. +//! +//! \return \b xtrue if the comp flag is asserted and \b xfalse if it is not +//! asserted. +// +//***************************************************************************** +xtBoolean +ACMPIntStatus(unsigned long ulBase, unsigned long ulComp) +{ + unsigned long ulStatus; + + xASSERT((ulBase == ACMP_BASE)); + xASSERT((ulComp >= 0) && (ulComp < 2)); + + // + // Get the comp flag + // + ulStatus = xHWREG(ulBase + ACMP_SR) & (1 << ulComp); + + return (ulStatus ? xtrue : xfalse); +} + +//***************************************************************************** +// +//! \brief Clear a comparator interrupt. +//! +//! \param ulBase is the base address of the comparator module. +//! \param ulComp is the index(0 - 1) of the comparator. +//! +//! The comparator interrupt is cleared, so that it no longer asserts. This +//! fucntion must be called in the interrupt handler to keep the handler from +//! being called again immediately upon exit. +//! +//! \return None. +// +//***************************************************************************** +void +ACMPIntClear(unsigned long ulBase, unsigned long ulComp) +{ + xASSERT((ulBase == ACMP_BASE)); + xASSERT((ulComp >= 0) && (ulComp < 2)); + + // + // Wirte 1 to clear the comp flag + // + xHWREG(ulBase + ACMP_SR) |= (1 << ulComp); +} + + +//***************************************************************************** +// +//! \brief Configures a comparator. +//! +//! \param ulBase is the base address of the comparator module. +//! \param ulCompID is the ID(index) of the comparator to configure. +//! Refrence \ref xACMP_Comparator_IDs. +//! \param ulConfig is the configuration of the comparator. +//! +//! This function configures a comparator. The \e ulConfig parameter is the +//! result of a logical OR operation between the \b ACMP_ASRCP_xxx, +//! and \b ACMP_ASRCN_xxx values. +//! +//! The \b ACMP_ASRCP_xxx is determines the ACMP+ source, +//! values refrence \ref xACMP_Analog_Src_Positive. +//! +//! The \b ACMP_ASRCP_xxx is determines the ACMP- source: +//! values refrence \ref xACMP_Analog_Src_Negative. +//! +//! \return None. +// +//***************************************************************************** + +void xACMPConfigure(unsigned long ulBase, unsigned long ulCompID, + unsigned long ulConfig) +{ + ACMPNegativeSrcSet(ulBase, ulCompID, ulConfig); +} + +//***************************************************************************** +// +//! \brief Enable the comparator. +//! +//! \param ulBase is the base address of the comparator module. +//! \param ulCompID is the ID of the comparator. +//! Refrence \ref xACMP_Comparator_IDs. +//! +//! This function enables a comparator. +//! +//! \return None. +// +//***************************************************************************** +void xACMPEnable(unsigned long ulBase, unsigned long ulCompID) +{ + ACMPEnable(ulBase, ulCompID); +} + +//***************************************************************************** +// +//! \brief Disable the comparator. +//! +//! \param ulBase is the base address of the comparator module. +//! \param ulCompID is the ID of the comparator. +//! Refrence \ref xACMP_Comparator_IDs. +//! +//! This function disables a comparator. +//! +//! \return None. +// +//***************************************************************************** +void xACMPDisable(unsigned long ulBase, unsigned long ulCompID) +{ + ACMPDisable(ulBase, ulCompID); +} + +//***************************************************************************** +// +//! \brief Enable the comparator interrupt. +//! +//! \param ulBase is the base address of the comparator module. +//! \param ulCompID is the ID(index) of the comparator. +//! Refrence \ref xACMP_Comparator_IDs. +//! +//! This function enables generation of an interrupt from the specified +//! comparator. Only comparators whose interrupts are enabled can be reflected +//! to the processor. +//! +//! \return None. +// +//***************************************************************************** +void xACMPIntEnable(unsigned long ulBase, unsigned long ulCompID) +{ + ACMPIntEnable(ulBase, ulCompID); +} + +//***************************************************************************** +// +//! \brief Disable the comparator interrupt. +//! +//! \param ulBase is the base address of the comparator module. +//! \param ulCompID is the ID(index) of the comparator. +//! Refrence \ref xACMP_Comparator_IDs. +//! +//! This function disables generation of an interrupt from the specified +//! comparator. Only comparators whose interrupts are enabled can be reflected +//! to the processor. +//! +//! \return None. +// +//***************************************************************************** +void xACMPIntDisable(unsigned long ulBase, unsigned long ulCompID) +{ + ACMPIntDisable(ulBase, ulCompID); +} diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xadc.c b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/adc.c similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xadc.c rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/adc.c index 4c2db1dc..0b677816 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xadc.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/adc.c @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xadc.c +//! \file adc.c //! \brief Driver for the ADC Controller. //! \version V2.1.1.1 //! \date 6/28/2014 @@ -38,7 +38,7 @@ //***************************************************************************** #include "CoX.h" -#include "xhw_adc.h" +#include "hw_adc.h" static xtEventCallback g_pfnADCHandlerCallbacks[2] = {0}; @@ -300,7 +300,7 @@ xADCIntCallbackInit(unsigned long ulBase, // //***************************************************************************** void -ADCIntHandler(void) +ADC_IRQHandler(void) { unsigned long ulBase = ADC0_BASE; unsigned long ulIntFlags; diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xcore.c b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/core.c similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xcore.c rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/core.c index 4a9c3aef..dc2cbebf 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xcore.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/core.c @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xcore.c +//! \file core.c //! \brief Instruction wrappers for special CPU instructions. //! Driver for the NVIC Interrupt Controller. //! Driver for the SysTick driver. diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xdma.c b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/dma.c similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xdma.c rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/dma.c index 51e9935c..709bf6f6 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xdma.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/dma.c @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xdma.c +//! \file dma.c //! \brief Driver for the DMA Controller. //! \version V2.1.1.1 //! \date 11/14/2011 @@ -38,7 +38,7 @@ //***************************************************************************** #include "CoX.h" -#include "xhw_dma.h" +#include "hw_dma.h" typedef struct { diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xgpio.c b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/gpio.c similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xgpio.c rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/gpio.c index c4908fef..9acc617e 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xgpio.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/gpio.c @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xgpio.c +//! \file gpio.c //! \brief Driver for the GPIO controller //! \version V2.2.1.0 //! \date 11/15/2013 @@ -38,8 +38,8 @@ //***************************************************************************** #include "CoX.h" -#include "xhw_gpio.h" -#include "xhw_sysctl.h" +#include "hw_gpio.h" +#include "hw_sysctl.h" int test0,test1; diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/gpio.h b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/gpio.h index 382f815a..9f79f4cf 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/gpio.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/gpio.h @@ -396,6 +396,172 @@ extern "C" // //***************************************************************************** + +//***************************************************************************** +// +//! \addtogroup GPIO_GP_Short_Pin NUC4xx General Purpose Short Pin +//! @{ +// +//***************************************************************************** +#define GPA0 GPIO_PORTA_BASE, GPIO_PIN_0 +#define GPA1 GPIO_PORTA_BASE, GPIO_PIN_1 +#define GPA2 GPIO_PORTA_BASE, GPIO_PIN_2 +#define GPA3 GPIO_PORTA_BASE, GPIO_PIN_3 +#define GPA4 GPIO_PORTA_BASE, GPIO_PIN_4 +#define GPA5 GPIO_PORTA_BASE, GPIO_PIN_5 +#define GPA6 GPIO_PORTA_BASE, GPIO_PIN_6 +#define GPA7 GPIO_PORTA_BASE, GPIO_PIN_7 +#define GPA8 GPIO_PORTA_BASE, GPIO_PIN_8 +#define GPA9 GPIO_PORTA_BASE, GPIO_PIN_9 +#define GPA10 GPIO_PORTA_BASE, GPIO_PIN_10 +#define GPA11 GPIO_PORTA_BASE, GPIO_PIN_11 +#define GPA12 GPIO_PORTA_BASE, GPIO_PIN_12 +#define GPA13 GPIO_PORTA_BASE, GPIO_PIN_13 +#define GPA14 GPIO_PORTA_BASE, GPIO_PIN_14 +#define GPA15 GPIO_PORTA_BASE, GPIO_PIN_15 + +#define GPB0 GPIO_PORTB_BASE, GPIO_PIN_0 +#define GPB1 GPIO_PORTB_BASE, GPIO_PIN_1 +#define GPB2 GPIO_PORTB_BASE, GPIO_PIN_2 +#define GPB3 GPIO_PORTB_BASE, GPIO_PIN_3 +#define GPB4 GPIO_PORTB_BASE, GPIO_PIN_4 +#define GPB5 GPIO_PORTB_BASE, GPIO_PIN_5 +#define GPB6 GPIO_PORTB_BASE, GPIO_PIN_6 +#define GPB7 GPIO_PORTB_BASE, GPIO_PIN_7 +#define GPB8 GPIO_PORTB_BASE, GPIO_PIN_8 +#define GPB9 GPIO_PORTB_BASE, GPIO_PIN_9 +#define GPB10 GPIO_PORTB_BASE, GPIO_PIN_10 +#define GPB11 GPIO_PORTB_BASE, GPIO_PIN_11 +#define GPB12 GPIO_PORTB_BASE, GPIO_PIN_12 +#define GPB13 GPIO_PORTB_BASE, GPIO_PIN_13 +#define GPB14 GPIO_PORTB_BASE, GPIO_PIN_14 +#define GPB15 GPIO_PORTB_BASE, GPIO_PIN_15 + +#define GPC0 GPIO_PORTC_BASE, GPIO_PIN_0 +#define GPC1 GPIO_PORTC_BASE, GPIO_PIN_1 +#define GPC2 GPIO_PORTC_BASE, GPIO_PIN_2 +#define GPC3 GPIO_PORTC_BASE, GPIO_PIN_3 +#define GPC4 GPIO_PORTC_BASE, GPIO_PIN_4 +#define GPC5 GPIO_PORTC_BASE, GPIO_PIN_5 +#define GPC6 GPIO_PORTC_BASE, GPIO_PIN_6 +#define GPC7 GPIO_PORTC_BASE, GPIO_PIN_7 +#define GPC8 GPIO_PORTC_BASE, GPIO_PIN_8 +#define GPC9 GPIO_PORTC_BASE, GPIO_PIN_9 +#define GPC10 GPIO_PORTC_BASE, GPIO_PIN_10 +#define GPC11 GPIO_PORTC_BASE, GPIO_PIN_11 +#define GPC12 GPIO_PORTC_BASE, GPIO_PIN_12 +#define GPC13 GPIO_PORTC_BASE, GPIO_PIN_13 +#define GPC14 GPIO_PORTC_BASE, GPIO_PIN_14 +#define GPC15 GPIO_PORTC_BASE, GPIO_PIN_15 + +#define GPD0 GPIO_PORTD_BASE, GPIO_PIN_0 +#define GPD1 GPIO_PORTD_BASE, GPIO_PIN_1 +#define GPD2 GPIO_PORTD_BASE, GPIO_PIN_2 +#define GPD3 GPIO_PORTD_BASE, GPIO_PIN_3 +#define GPD4 GPIO_PORTD_BASE, GPIO_PIN_4 +#define GPD5 GPIO_PORTD_BASE, GPIO_PIN_5 +#define GPD6 GPIO_PORTD_BASE, GPIO_PIN_6 +#define GPD7 GPIO_PORTD_BASE, GPIO_PIN_7 +#define GPD8 GPIO_PORTD_BASE, GPIO_PIN_8 +#define GPD9 GPIO_PORTD_BASE, GPIO_PIN_9 +#define GPD10 GPIO_PORTD_BASE, GPIO_PIN_10 +#define GPD11 GPIO_PORTD_BASE, GPIO_PIN_11 +#define GPD12 GPIO_PORTD_BASE, GPIO_PIN_12 +#define GPD13 GPIO_PORTD_BASE, GPIO_PIN_13 +#define GPD14 GPIO_PORTD_BASE, GPIO_PIN_14 +#define GPD15 GPIO_PORTD_BASE, GPIO_PIN_15 + +#define GPE0 GPIO_PORTE_BASE, GPIO_PIN_0 +#define GPE1 GPIO_PORTE_BASE, GPIO_PIN_1 +#define GPE2 GPIO_PORTE_BASE, GPIO_PIN_2 +#define GPE3 GPIO_PORTE_BASE, GPIO_PIN_3 +#define GPE4 GPIO_PORTE_BASE, GPIO_PIN_4 +#define GPE5 GPIO_PORTE_BASE, GPIO_PIN_5 +#define GPE6 GPIO_PORTE_BASE, GPIO_PIN_6 +#define GPE7 GPIO_PORTE_BASE, GPIO_PIN_7 +#define GPE8 GPIO_PORTE_BASE, GPIO_PIN_8 +#define GPE9 GPIO_PORTE_BASE, GPIO_PIN_9 +#define GPE10 GPIO_PORTE_BASE, GPIO_PIN_10 +#define GPE11 GPIO_PORTE_BASE, GPIO_PIN_11 +#define GPE12 GPIO_PORTE_BASE, GPIO_PIN_12 +#define GPE13 GPIO_PORTE_BASE, GPIO_PIN_13 +#define GPE14 GPIO_PORTE_BASE, GPIO_PIN_14 +#define GPE15 GPIO_PORTE_BASE, GPIO_PIN_15 + +#define GPF0 GPIO_PORTF_BASE, GPIO_PIN_0 +#define GPF1 GPIO_PORTF_BASE, GPIO_PIN_1 +#define GPF2 GPIO_PORTF_BASE, GPIO_PIN_2 +#define GPF3 GPIO_PORTF_BASE, GPIO_PIN_3 +#define GPF4 GPIO_PORTF_BASE, GPIO_PIN_4 +#define GPF5 GPIO_PORTF_BASE, GPIO_PIN_5 +#define GPF6 GPIO_PORTF_BASE, GPIO_PIN_6 +#define GPF7 GPIO_PORTF_BASE, GPIO_PIN_7 +#define GPF8 GPIO_PORTF_BASE, GPIO_PIN_8 +#define GPF9 GPIO_PORTF_BASE, GPIO_PIN_9 +#define GPF10 GPIO_PORTF_BASE, GPIO_PIN_10 +#define GPF11 GPIO_PORTF_BASE, GPIO_PIN_11 +#define GPF12 GPIO_PORTF_BASE, GPIO_PIN_12 +#define GPF13 GPIO_PORTF_BASE, GPIO_PIN_13 +#define GPF14 GPIO_PORTF_BASE, GPIO_PIN_14 +#define GPF15 GPIO_PORTF_BASE, GPIO_PIN_15 + +#define GPG0 GPIO_PORTG_BASE, GPIO_PIN_0 +#define GPG1 GPIO_PORTG_BASE, GPIO_PIN_1 +#define GPG2 GPIO_PORTG_BASE, GPIO_PIN_2 +#define GPG3 GPIO_PORTG_BASE, GPIO_PIN_3 +#define GPG4 GPIO_PORTG_BASE, GPIO_PIN_4 +#define GPG5 GPIO_PORTG_BASE, GPIO_PIN_5 +#define GPG6 GPIO_PORTG_BASE, GPIO_PIN_6 +#define GPG7 GPIO_PORTG_BASE, GPIO_PIN_7 +#define GPG8 GPIO_PORTG_BASE, GPIO_PIN_8 +#define GPG9 GPIO_PORTG_BASE, GPIO_PIN_9 +#define GPG10 GPIO_PORTG_BASE, GPIO_PIN_10 +#define GPG11 GPIO_PORTG_BASE, GPIO_PIN_11 +#define GPG12 GPIO_PORTG_BASE, GPIO_PIN_12 +#define GPG13 GPIO_PORTG_BASE, GPIO_PIN_13 +#define GPG14 GPIO_PORTG_BASE, GPIO_PIN_14 +#define GPG15 GPIO_PORTG_BASE, GPIO_PIN_15 + +#define GPH0 GPIO_PORTH_BASE, GPIO_PIN_0 +#define GPH1 GPIO_PORTH_BASE, GPIO_PIN_1 +#define GPH2 GPIO_PORTH_BASE, GPIO_PIN_2 +#define GPH3 GPIO_PORTH_BASE, GPIO_PIN_3 +#define GPH4 GPIO_PORTH_BASE, GPIO_PIN_4 +#define GPH5 GPIO_PORTH_BASE, GPIO_PIN_5 +#define GPH6 GPIO_PORTH_BASE, GPIO_PIN_6 +#define GPH7 GPIO_PORTH_BASE, GPIO_PIN_7 +#define GPH8 GPIO_PORTH_BASE, GPIO_PIN_8 +#define GPH9 GPIO_PORTH_BASE, GPIO_PIN_9 +#define GPH10 GPIO_PORTH_BASE, GPIO_PIN_10 +#define GPH11 GPIO_PORTH_BASE, GPIO_PIN_11 +#define GPH12 GPIO_PORTH_BASE, GPIO_PIN_12 +#define GPH13 GPIO_PORTH_BASE, GPIO_PIN_13 +#define GPH14 GPIO_PORTH_BASE, GPIO_PIN_14 +#define GPH15 GPIO_PORTH_BASE, GPIO_PIN_15 + +#define GPI0 GPIO_PORTI_BASE, GPIO_PIN_0 +#define GPI1 GPIO_PORTI_BASE, GPIO_PIN_1 +#define GPI2 GPIO_PORTI_BASE, GPIO_PIN_2 +#define GPI3 GPIO_PORTI_BASE, GPIO_PIN_3 +#define GPI4 GPIO_PORTI_BASE, GPIO_PIN_4 +#define GPI5 GPIO_PORTI_BASE, GPIO_PIN_5 +#define GPI6 GPIO_PORTI_BASE, GPIO_PIN_6 +#define GPI7 GPIO_PORTI_BASE, GPIO_PIN_7 +#define GPI8 GPIO_PORTI_BASE, GPIO_PIN_8 +#define GPI9 GPIO_PORTI_BASE, GPIO_PIN_9 +#define GPI10 GPIO_PORTI_BASE, GPIO_PIN_10 +#define GPI11 GPIO_PORTI_BASE, GPIO_PIN_11 +#define GPI12 GPIO_PORTI_BASE, GPIO_PIN_12 +#define GPI13 GPIO_PORTI_BASE, GPIO_PIN_13 +#define GPI14 GPIO_PORTI_BASE, GPIO_PIN_14 +#define GPI15 GPIO_PORTI_BASE, GPIO_PIN_15 + +//***************************************************************************** +// +//! @} +// +//***************************************************************************** + //***************************************************************************** // //! \addtogroup NUC4xx_GPIO_Pin_Config NUC4xx GPIO Pin Config diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/hw_acmp.h b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/hw_acmp.h new file mode 100644 index 00000000..dffc9aeb --- /dev/null +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/hw_acmp.h @@ -0,0 +1,190 @@ +//***************************************************************************** +// +//! \file hw_acmp.h +//! \brief Macros used when accessing the comparator hardware. +//! \version V2.1.1.0 +//! \date 1/3/2012 +//! \author CooCox +//! \copy +//! +//! Copyright (c) 2011, CooCox +//! All rights reserved. +//! +//! Redistribution and use in source and binary forms, with or without +//! modification, are permitted provided that the following conditions +//! are met: +//! +//! * Redistributions of source code must retain the above copyright +//! notice, this list of conditions and the following disclaimer. +//! * Redistributions in binary form must reproduce the above copyright +//! notice, this list of conditions and the following disclaimer in the +//! documentation and/or other materials provided with the distribution. +//! * Neither the name of the nor the names of its +//! contributors may be used to endorse or promote products derived +//! from this software without specific prior written permission. +//! +//! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +//! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +//! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +//! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +//! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +//! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +//! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +//! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +//! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +//! THE POSSIBILITY OF SUCH DAMAGE. +// +//***************************************************************************** + +#ifndef __XHW_ACMP_H__ +#define __XHW_ACMP_H__ + +//***************************************************************************** +// +//! \addtogroup CoX_Peripheral_Lib +//! @{ +// +//***************************************************************************** + +//***************************************************************************** +// +//! \addtogroup ACMP +//! @{ +// +//***************************************************************************** + +//***************************************************************************** +// +//! \addtogroup NUC4xx_ACMP_Register NUC4xx Analog Comparator Register +//! \brief Here are the detailed info of ACMP registers. +//! +//! it contains: +//! - Register offset. +//! - detailed bit-field of the registers. +//! - Enum and mask of the registers. +//! . +//! Users can read or write the registers through xHWREG(). +//! +//! @{ +// +//***************************************************************************** + +//***************************************************************************** +// +//! \addtogroup NUC4xx_ACMP_Register_Offset ACMP Register Offset(Map) +//! \brief Here is the ACMP register offset, users can get the register address +//! through ACMP_BASE + offset. +//! @{ +// +//***************************************************************************** + +// +//! Comparator0 Control Register +// +#define ACMP_CR0 0x00000000 + +// +//! Comparator1 Control Register +// +#define ACMP_CR1 0x00000004 + +// +//! Comparator Status Register +// +#define ACMP_SR 0x00000008 + +//***************************************************************************** +// +//! @} +// +//***************************************************************************** + +//***************************************************************************** +// +//! \addtogroup NUC4xx_ACMP_Register_CR Comparator Control Register(ACMP_CR0/1) +//! \brief Definition for the bit fields in the ACMP_O_CR0 or ACMP_O_CR1 register. +//! @{ +// +//***************************************************************************** + +// +//! Comparator0 negative input select +// +#define ACMP_CR_CN 0x00000010 + +// +//! Comparator0 Hysteresis Enable +// +#define ACMP_CR_HYSEN 0x00000004 + +// +//! Comparator0 Interrupt Enable +// +#define ACMP_CR_CMPIE 0x00000002 + +// +//! Comparator0 Enable +// +#define ACMP_CR_CMPEN 0x00000001 + +//***************************************************************************** +// +//! @} +// +//***************************************************************************** + +//***************************************************************************** +// +//! \addtogroup NUC4xx_ACMP_Register_SR Comparator Status Register(ACMP_SR) +//! \brief Definition for the bit fields in the ACMP_O_SR register. +//! @{ +// +//***************************************************************************** + +// +//! Comparator1 Output +// +#define ACMP_SR_CO1 0x00000008 + +// +//! Comparator0 Output +// +#define ACMP_SR_CO0 0x00000004 + +// +//! Comparator1 Flag +// +#define ACMP_SR_CMPF1 0x00000002 + +// +//! Comparator0 Flag +// +#define ACMP_SR_CMPF0 0x00000001 + +//***************************************************************************** +// +//! @} +// +//***************************************************************************** + +//***************************************************************************** +// +//! @} +// +//***************************************************************************** + +//***************************************************************************** +// +//! @} +// +//***************************************************************************** + +//***************************************************************************** +// +//! @} +// +//***************************************************************************** + +#endif // __XHW_ACMP_H__ + diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xhw_adc.h b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/hw_adc.h similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xhw_adc.h rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/hw_adc.h index 1b76e7f4..c42ea0a7 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xhw_adc.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/hw_adc.h @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xhw_adc.h +//! \file hw_adc.h //! \brief Macros used when accessing the ADC hardware. //! \version V2.1.1.1 //! \date 11/14/2011 diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xhw_dma.h b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/hw_dma.h similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xhw_dma.h rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/hw_dma.h index 4171d48e..799281c5 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xhw_dma.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/hw_dma.h @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xhw_dma.h +//! \file hw_dma.h //! \brief Macros and defines used when accessing the DMA hardware. //! \version V2.1.1.1 //! \date 7/1/2014 diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xhw_gpio.h b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/hw_gpio.h similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xhw_gpio.h rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/hw_gpio.h index 860ddc67..c0bb63b5 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xhw_gpio.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/hw_gpio.h @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xhw_gpio.h +//! \file hw_gpio.h //! \brief Macros used when accessing the GPIO control hardware. //! \version V2.2.1.0 //! \date 11/15/2013 diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xhw_i2c.h b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/hw_i2c.h similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xhw_i2c.h rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/hw_i2c.h index c711a75d..77582f3f 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xhw_i2c.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/hw_i2c.h @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xhw_i2c.h +//! \file hw_i2c.h //! \brief Macros and defines used when accessing the I2C hardware. //! \version V2.1.1.1 //! \date 6/14/2014 diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xhw_pwm.h b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/hw_pwm.h similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xhw_pwm.h rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/hw_pwm.h index 941c4ec7..d9eca9e2 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xhw_pwm.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/hw_pwm.h @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xhw_pwm.h +//! \file hw_pwm.h //! \brief Macros and defines used when accessing the PWM hardware. //! \version V2.2.1.0 //! \date 11/15/2013 diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xhw_rtc.h b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/hw_rtc.h similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xhw_rtc.h rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/hw_rtc.h index ab582f0d..93aa91ba 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xhw_rtc.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/hw_rtc.h @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xhw_rtc.h +//! \file hw_rtc.h //! \brief Macros and defines used when accessing the RTC hardware. //! \version V2.2.1.0 //! \date 11/15/2013 diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xhw_spi.h b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/hw_spi.h similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xhw_spi.h rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/hw_spi.h index 4bbf96a0..861500c6 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xhw_spi.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/hw_spi.h @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xhw_spi.h +//! \file hw_spi.h //! \brief Macros used when accessing the SPI hardware. //! \version V2.2.1.0 //! \date 6/15/2014 diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xhw_sysctl.h b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/hw_sysctl.h similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xhw_sysctl.h rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/hw_sysctl.h index b32614b1..ccaebe7b 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xhw_sysctl.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/hw_sysctl.h @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xhw_sysctl.h +//! \file hw_sysctl.h //! \brief Macros used when accessing the system control hardware. //! \version V2.2.1.0 //! \date 6/15/2014 diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xhw_timer.h b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/hw_timer.h similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xhw_timer.h rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/hw_timer.h index e8f65442..deb7e473 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xhw_timer.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/hw_timer.h @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xhw_timer.h +//! \file hw_timer.h //! \brief Macros and defines used when accessing the TIMER hardware. //! \version V2.2.1.0 //! \date 11/15/2013 diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xhw_uart.h b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/hw_uart.h similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xhw_uart.h rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/hw_uart.h index 74ffafa4..04947d63 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xhw_uart.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/hw_uart.h @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xhw_uart.h +//! \file hw_uart.h //! \brief Macros used when accessing the UART hardware. //! \version V2.2.1.0 //! \date 6/15/2014 diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xhw_wdt.h b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/hw_wdt.h similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xhw_wdt.h rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/hw_wdt.h index 293e1922..87f03060 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xhw_wdt.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/hw_wdt.h @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xhw_wdt.h +//! \file hw_wdt.h //! \brief Macros and defines used when accessing the WATCHDOG hardware. //! \version V2.2.1.0 //! \date 11/15/2013 diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xi2c.c b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/i2c.c similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xi2c.c rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/i2c.c index 807116fa..7a5081aa 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xi2c.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/i2c.c @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xi2c.c +//! \file i2c.c //! \brief Driver for the I2C //! \version V2.1.1.1 //! \date 6/14/2014 @@ -37,8 +37,8 @@ // //***************************************************************************** #include "CoX.h" -#include "xhw_sysctl.h" -#include "xhw_i2c.h" +#include "hw_sysctl.h" +#include "hw_i2c.h" //***************************************************************************** // diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xpwm.c b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/pwm.c similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xpwm.c rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/pwm.c index 4a2d4a7c..ad3c697b 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xpwm.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/pwm.c @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xpwm.c +//! \file pwm.c //! \brief Driver for the PWM //! \version V2.2.1.0 //! \date 11/15/2013 @@ -37,9 +37,9 @@ // //***************************************************************************** #include "CoX.h" -#include "xhw_gpio.h" -#include "xhw_sysctl.h" -#include "xhw_pwm.h" +#include "hw_gpio.h" +#include "hw_sysctl.h" +#include "hw_pwm.h" diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xrtc.c b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/rtc.c similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xrtc.c rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/rtc.c index 14a63455..681df708 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xrtc.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/rtc.c @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xrtc.c +//! \file rtc.c //! \brief Driver for the RTC //! \version V2.2.1.0 //! \date 11/15/2013 @@ -37,9 +37,9 @@ // //***************************************************************************** #include "CoX.h" -#include "xhw_sysctl.h" +#include "hw_sysctl.h" #include "sysctl.h" -#include "xhw_rtc.h" +#include "hw_rtc.h" //***************************************************************************** @@ -272,7 +272,7 @@ xRTCConvertCounterToTime(xtTime *xtTime, unsigned long ultimeCounter) // //***************************************************************************** void -RTCIntHandler(void) +RTC_IRQHandler(void) { unsigned long ulEventFlags; diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xspi.c b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/spi.c similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xspi.c rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/spi.c index 1a9ac0d6..4da3299e 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xspi.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/spi.c @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xspi.c +//! \file spi.c //! \brief Driver for the SPI //! \version V2.2.1.0 //! \date 6/15/2014 @@ -37,8 +37,8 @@ // //***************************************************************************** #include "CoX.h" -#include "xhw_sysctl.h" -#include "xhw_spi.h" +#include "hw_sysctl.h" +#include "hw_spi.h" //***************************************************************************** // diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xsysctl.c b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/sysctl.c similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xsysctl.c rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/sysctl.c index 881a3da3..3f64df81 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xsysctl.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/sysctl.c @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xsysctl.c +//! \file sysctl.c //! \brief Driver for the system controller //! \version V2.2.1.0 //! \date 6/15/2014 @@ -37,7 +37,7 @@ // //***************************************************************************** #include "CoX.h" -#include "xhw_sysctl.h" +#include "hw_sysctl.h" static unsigned long s_ulExtClockMHz = 12; diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xtimer.c b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/timer.c similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xtimer.c rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/timer.c index d05b1800..88dc4348 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xtimer.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/timer.c @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xtimer.c +//! \file timer.c //! \brief Driver for the Timer //! \version V2.2.1.0 //! \date 11/15/2013 @@ -37,9 +37,9 @@ // //***************************************************************************** #include "CoX.h" -#include "xhw_gpio.h" -#include "xhw_sysctl.h" -#include "xhw_timer.h" +#include "hw_gpio.h" +#include "hw_sysctl.h" +#include "hw_timer.h" //***************************************************************************** // @@ -64,7 +64,7 @@ static unsigned long ulEXTClockFreq; // //***************************************************************************** void -TIMER0IntHandler(void) +TMR0_IRQHandler(void) { unsigned long ulBase = TIMER0_BASE; unsigned long ulTemp0,ulTemp1; @@ -96,7 +96,7 @@ TIMER0IntHandler(void) // //***************************************************************************** void -TIMER1IntHandler(void) +TMR1_IRQHandler(void) { unsigned long ulBase = TIMER1_BASE; unsigned long ulTemp0,ulTemp1; @@ -129,7 +129,7 @@ TIMER1IntHandler(void) // //***************************************************************************** void -TIMER2IntHandler(void) +TMR2_IRQHandler(void) { unsigned long ulBase = TIMER2_BASE; unsigned long ulTemp0,ulTemp1; @@ -162,7 +162,7 @@ TIMER2IntHandler(void) // //***************************************************************************** void -TIMER3IntHandler(void) +TMR3_IRQHandler(void) { unsigned long ulBase = TIMER3_BASE; unsigned long ulTemp0,ulTemp1; @@ -1277,9 +1277,9 @@ void xTimerPrescaleSet(unsigned long ulBase, unsigned long ulChannel, //! \return the Prescale Value will be get. // //***************************************************************************** -void xTimerPrescaleGet(unsigned long ulBase, unsigned long ulChannel) +unsigned long xTimerPrescaleGet(unsigned long ulBase, unsigned long ulChannel) { - TimerPrescaleGet(ulBase); + return TimerPrescaleGet(ulBase); } //***************************************************************************** @@ -1315,9 +1315,9 @@ void xTimerLoadSet(unsigned long ulBase, unsigned long ulChannel, //! \return the counter Value will be get. // //***************************************************************************** -void xTimerLoadGet(unsigned long ulBase, unsigned long ulChannel) +unsigned long xTimerLoadGet(unsigned long ulBase, unsigned long ulChannel) { - return; + return 0; } diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xuart.c b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/uart.c similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xuart.c rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/uart.c index 7ef5a582..bc020cfe 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xuart.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/uart.c @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xuart.c +//! \file uart.c //! \brief Driver for the UART //! \version V2.2.1.0 //! \date 6/15/2014 @@ -38,8 +38,8 @@ //***************************************************************************** #include "CoX.h" -#include "xhw_sysctl.h" -#include "xhw_uart.h" +#include "hw_sysctl.h" +#include "hw_uart.h" //***************************************************************************** // diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xwdt.c b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/wdt.c similarity index 99% rename from CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xwdt.c rename to CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/wdt.c index ad09e977..c4cd31e2 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/xwdt.c +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/libcox/wdt.c @@ -1,6 +1,6 @@ //***************************************************************************** // -//! \file xwdt.c +//! \file wdt.c //! \brief Driver for the WDT //! \version V2.2.1.0 //! \date 11/15/2013 @@ -37,8 +37,8 @@ // //***************************************************************************** #include "CoX.h" -#include "xhw_sysctl.h" -#include "xhw_wdt.h" +#include "hw_sysctl.h" +#include "hw_wdt.h" @@ -62,7 +62,7 @@ static xtEventCallback g_pfnWATCHDOGHandlerCallbacks[1]={0}; // //***************************************************************************** void -WDTIntHandler(void) +WDT_IRQHandler(void) { // // Clear the WDT INT Flag diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/pwm/example/led/src/led.c b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/pwm/example/led/src/led.c new file mode 100644 index 00000000..7f97fc4f --- /dev/null +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/pwm/example/led/src/led.c @@ -0,0 +1,25 @@ +#include "CoX.h" + +void uartprinntf() +{ + xSysCtlClockSet(84000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_12MHZ); + xSysCtlDelay(10000); + + xSPinTypeUART(UART0RX,PG1); + xSPinTypeUART(UART0TX,PG2); + + xSysCtlPeripheralReset(xSYSCTL_PERIPH_UART0); + xSysCtlPeripheralEnable(xSYSCTL_PERIPH_UART0); + + // + // Config 8 bit word length, 1 stop bit, + // and none parity bit, receive FIFO 1 byte. + // + xUARTConfigSet(xUART0_BASE, 115200, (xUART_CONFIG_WLEN_8 | \ + xUART_CONFIG_STOP_1 | \ + xUART_CONFIG_PAR_NONE)); + + xUARTEnable(xUART0_BASE, (xUART_BLOCK_UART | xUART_BLOCK_TX | xUART_BLOCK_RX)); + + UARTBufferWrite(UART0_BASE, "NUC1xx.UART.BAUDRATE EXAMPLE \r\n", sizeof("NUC1xx.UART.BAUDRATE EXAMPLE \r\n")); +} diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/pwm/example/led/src/main.c b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/pwm/example/led/src/main.c new file mode 100644 index 00000000..e8d4676a --- /dev/null +++ b/CoX/CoX_Peripheral/CoX_Peripheral_NUC4xx/pwm/example/led/src/main.c @@ -0,0 +1,6 @@ +extern void uartprinntf(); + +int main() +{ + uartprinntf(); +} \ No newline at end of file From c94e4a65417301b76a02108be5a9eeea3663ef70 Mon Sep 17 00:00:00 2001 From: xinyun Date: Fri, 1 Aug 2014 14:58:09 +0800 Subject: [PATCH 10/13] Add USB standard interface --- .../CoX_Peripheral_Template/inc/xusb.h | 514 ++++++++++++++++++ 1 file changed, 514 insertions(+) create mode 100644 CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xusb.h diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xusb.h b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xusb.h new file mode 100644 index 00000000..ce522dbb --- /dev/null +++ b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xusb.h @@ -0,0 +1,514 @@ +//***************************************************************************** +// +//! \file xusb.h +//! \brief Prototypes for the USB Driver. +//! \version V2.3 +//! \date 08/01/2014 +//! \author CooCox +//! \copyright +//! +//! Copyright (c) 2014, CooCox +//! All rights reserved. +//! +//! Redistribution and use in source and binary forms, with or without +//! modification, are permitted provided that the following conditions +//! are met: +//! * Redistributions of source code must retain the above copyright +//! notice, this list of conditions and the following disclaimer. +//! * Redistributions in binary form must reproduce the above copyright +//! notice, this list of conditions and the following disclaimer in the +//! documentation and/or other materials provided with the distribution. +//! * Neither the name of the nor the names of its +//! contributors may be used to endorse or promote products derived +//! from this software without specific prior written permission. +//! +//! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +//! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +//! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +//! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +//! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +//! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +//! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +//! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +//! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +//! THE POSPIBILITY OF SUCH DAMAGE. +// +//***************************************************************************** + +#ifndef __XUSB_H__ +#define __XUSB_H__ + +#include "usb.h" +#include "xPort.h" + +//***************************************************************************** +// +// If building with a C++ compiler, make all of the definitions in this header +// have a C binding. +// +//***************************************************************************** +#ifdef __cplusplus +extern "C" +{ +#endif + +//***************************************************************************** +// +//! \addtogroup CoX_Peripheral_Interface +//! @{ +// +//***************************************************************************** + +//***************************************************************************** +// +//! \addtogroup xUSB +//! @{ +// +//***************************************************************************** + +//***************************************************************************** +// +//! \addtogroup xUSB_Event xUSB Event +//! +//! more please refer to [xUSB Event in MD file](@ref xUSB_Event_md). +//! +//! @{ +// +//***************************************************************************** + +// +// Setup Packet +// +#define xUSB_EVENT_SETUP 1 + +// +// OUT Packet +// +#define xUSB_EVENT_OUT 2 + +// +// In Packet +// +#define xUSB_EVENT_IN 3 + +// +// OUT Packet - Not Acknowledged +// +#define xUSB_EVENT_OUT_NAK 4 + +// +// IN Packet - Not Acknowledged +// +#define xUSB_EVENT_IN_NAK 5 + +// +// OUT Packet - Stalled +// +#define xUSB_EVENT_OUT_STALL 6 + +// +// IN Packet - Stalled +// +#define xUSB_EVENT_IN_STALL 7 + +//***************************************************************************** +// +//! @} +// +//***************************************************************************** + +//***************************************************************************** +// +//! \addtogroup xUSB_Endpoint_Descriptor xUSB Standard Endpoint Descriptor +//! \brief Define the type of Standard Endpoint Descriptor +//! +//! more please refer to [xUSB Standard Endpoint Descriptor](@ref xUSB_Endpoint_Descriptor_md). +//! +//! @{ +// +//***************************************************************************** + +typedef struct _USB_ENDPOINT_DESCRIPTOR { + unsigned char bLength; + unsigned char bDescriptorType; + unsigned char bEndpointAddress; + unsigned char bmAttributes; + unsigned short wMaxPacketSize; + unsigned char bInterval; +} __attribute__((packed)) USB_ENDPOINT_DESCRIPTOR; + +//***************************************************************************** +// +//! @} +// +//***************************************************************************** + +//***************************************************************************** +// +//! \addtogroup xUSB_Exported_APIs xUSB API +//! \brief xUSB API Reference. +//! +//! \section xUSB_Exported_APIs_Port CoX Port Details +//! +//! | xUSB API | CoX | +//! |------------------------------------|--------------| +//! | \ref xUSBIOClkConfig | Mandatory | +//! | \ref xUSBInit | Mandatory | +//! | \ref xUSBConnect | Mandatory | +//! | \ref xUSBReset | Mandatory | +//! | \ref xUSBSuspend | Mandatory | +//! | \ref xUSBResume | Mandatory | +//! | \ref xUSBWakeUp | Mandatory | +//! | \ref xUSBWakeUpConfig | Mandatory | +//! | \ref xUSBSetAddress | Mandatory | +//! | \ref xUSBIsConfigured | Mandatory | +//! | \ref xUSBEndpointConfig | Mandatory | +//! | \ref xUSBEndpointEnable | Mandatory | +//! | \ref xUSBEndpointDisable | Mandatory | +//! | \ref xUSBEndpointReset | Mandatory | +//! | \ref xUSBEndpointStallSet | Mandatory | +//! | \ref xUSBEndpointStallClear | Mandatory | +//! | \ref xUSBControlOutEnble | Mandatory | +//! | \ref xUSBEndpointBufferClear | Mandatory | +//! | \ref xUSBEndpointRead | Mandatory | +//! | \ref xUSBEndpointWrite | Mandatory | +//! | \ref xUSBFrameGet | Mandatory | +//! | \ref xUSBEventHandler | Mandatory | +//! more please refer to [xUSB API in MD file](@ref xUSB_Exported_APIs_md). +//! +//! @{ +// +//***************************************************************************** + +//***************************************************************************** +// +//! \brief USB and IO Clock configuration only. +//! +//! \return xtrue or xfalse. +// +//***************************************************************************** +extern xtBoolean xUSBIOClkConfig(void); + +//***************************************************************************** +// +//! \brief USB Initialize Function +//! +//! \return None. +// +//***************************************************************************** +extern void xUSBInit(void); + +//***************************************************************************** +// +//! \brief Disables the USB master block. +//! This function will disable operation of the USB Master block. +//! +//! \param [in] ulBase is the USB Connect/Disconnect. +//! - \ref xUSB_CONNECT +//! - \ref xUSB_DISCONNECT +//! +//! \return xtrue or xfalse. +// +//***************************************************************************** +extern xtBoolean xUSBConnect(unsigned long ulConnect); + +//***************************************************************************** +// +//! \brief USB Reset Function +//! +//! \param None +//! +//! \return xtrue or xfalse. +// +//***************************************************************************** +extern xtBoolean xUSBReset(void); + +//***************************************************************************** +// +//! \brief USB Suspend Function +//! +//! \param None +//! +//! \return xtrue or xfalse. +// +//***************************************************************************** +extern xtBoolean xUSBSuspend(void); + +//***************************************************************************** +// +//! \brief USB Wakeup Function +//! +//! \param None +//! +//! \return xtrue or xfalse. +// +//***************************************************************************** +extern xtBoolean xUSBWakeUp(void); + +//***************************************************************************** +// +//! \brief USB Resume Function +//! +//! \param None +//! +//! \return xtrue or xfalse. +// +//***************************************************************************** +extern xtBoolean xUSBResume(void); + +//***************************************************************************** +// +//! \brief USB Remote Wakeup Enbale Function +//! +//! \param None +//! +//! \return The status: +//! - xtrue +//! - xfalse +// +//***************************************************************************** +extern xtBoolean xUSBWakeUpEnable(void); + +//***************************************************************************** +// +//! \brief USB Remote Wakeup Disable Function +//! +//! \param None +//! +//! \return The status: +//! - xtrue +//! - xfalse +// +//***************************************************************************** +extern xtBoolean xUSBWakeUpDisable(void); + +//***************************************************************************** +// +//! \brief USB Set Address Function. +//! +//! \param [in] ulBase is the USB Address. +//! +//! \return The status: +//! - xtrue +//! - xfalse +// +//***************************************************************************** +extern xtBoolean xUSBSetAddress(unsigned long ulAddr); + +//***************************************************************************** +// +//! \brief USB Set Configure Function. +//! +//! \param [in] ulBase is the USB Configure/Deconfigure. +//! +//! \return The status: +//! - xtrue +//! - xfalse +// +//***************************************************************************** +extern xtBoolean xUSBConfigure(unsigned long ulConfig); + +//***************************************************************************** +// +//! \brief Configure USB Endpoint according to Descriptor +//! +//! \param [in] ulBase Pointer to Endpoint Descriptor +//! ulDir: Out (dir == 0), In (dir <> 0) +//! +//! \return The status: +//! - xtrue +//! - xfalse +// +//***************************************************************************** +extern xtBoolean xUSBEndpointConfig(USB_ENDPOINT_DESCRIPTOR *epConfig, unsigned long ulDir); + +//***************************************************************************** +// +//! \brief Enable USB Endpoint +//! +//! \param [in] ulBase Endpoint Number. +//! bit 0-3 Address +//! bit 7 Dir +//! +//! \return The status: +//! - xtrue +//! - xfalse +// +//***************************************************************************** +extern xtBoolean xUSBEndpointEnable(unsigned long ulNum); + +//***************************************************************************** +// +//! \brief Disable USB Endpoint +//! +//! \param [in] ulBase Endpoint Number. +//! bit 0-3 Address +//! bit 7 Dir +//! +//! \return The status: +//! - xtrue +//! - xfalse +// +//***************************************************************************** +extern xtBoolean xUSBEndpointDisable(unsigned long ulNum); + +//***************************************************************************** +// +//! \brief Reset USB Endpoint +//! +//! \param [in] ulBase Endpoint Number. +//! bit 0-3 Address +//! bit 7 Dir +//! +//! \return The status: +//! - xtrue +//! - xfalse +// +//***************************************************************************** +extern xtBoolean xUSBEndpointReset(unsigned long ulNum); + +//***************************************************************************** +// +//! \brief Set Stall for USB Endpoint +//! +//! \param [in] ulBase Endpoint Number. +//! bit 0-3 Address +//! bit 7 Dir +//! +//! \return The status: +//! - xtrue +//! - xfalse +// +//***************************************************************************** +extern xtBoolean xUSBEndpointStallSet(unsigned long ulNum); + +//***************************************************************************** +// +//! \brief Clear Stall for USB Endpoint +//! +//! \param [in] ulBase Endpoint Number. +//! bit 0-3 Address +//! bit 7 Dir +//! +//! \return The status: +//! - xtrue +//! - xfalse +// +//***************************************************************************** +extern xtBoolean xUSBEndpointStallClear(unsigned long ulNum); + +//***************************************************************************** +// +//! \brief Set max packet size for control out +//! +//! \param [in] None +//! +//! \return The status: +//! - xtrue +//! - xfalse +// +//***************************************************************************** +extern xtBoolean xUSBControlOutEnble(void); + +//***************************************************************************** +// +//! \brief Clear USB Endpoint Buffer +//! +//! \param [in] ulBase Endpoint Number. +//! bit 0-3 Address +//! bit 7 Dir +//! +//! \return The status: +//! - xtrue +//! - xfalse +// +//***************************************************************************** +extern xtBoolean xUSBEndpointBufferClear(unsigned long ulNum); + +//***************************************************************************** +// +//! \brief Read USB Endpoint Data +//! +//! \param [in] ulBase Endpoint Number. +//! bit 0-3 Address +//! bit 7 Dir +//! ucpData: Pointer to Data Buffer +//! +//! \return Number of bytes read +// +//***************************************************************************** +extern unsigned long xUSBEndpointRead(unsigned long ulNum,unsigned char *ucpData); + +//***************************************************************************** +// +//! \brief Write USB Endpoint Data +//! +//! \param [in] ulBase Endpoint Number. +//! bit 0-3 Address +//! bit 7 Dir +//! ucpData: Pointer to Data Buffer +//! ulLen Number of bytes +//! +//! \return Number of bytes written +// +//***************************************************************************** +extern unsigned long xUSBEndpointWrite(unsigned long ulNum,unsigned char *ucpData, + unsigned long ulLen); + +//***************************************************************************** +// +//! \brief Get USB Last Frame Number +//! +//! \param [in] None +//! +//! \return number of last frame +// +//***************************************************************************** +extern unsigned long xUSBFrameGet(void); + +//***************************************************************************** +// +//! \brief Set max packet size for control out +//! +//! \param [in] event: The logic number of USB endpoint +//! handler: The callback function of USB endpoint +//! data: The extern type which is using here +//! +//! \return The status: +//! - xtrue +//! - xfalse +// +//***************************************************************************** +extern xtBoolean xUSBEventHandler(unsigned char event, xtEventCallback handler, void *data); + + + +//***************************************************************************** +// +//! @} +// +//***************************************************************************** + +//***************************************************************************** +// +//! @} +// +//***************************************************************************** + +//***************************************************************************** +// +//! @} +// +//***************************************************************************** + +//***************************************************************************** +// +// Mark the end of the C bindings section for C++ compilers. +// +//***************************************************************************** +#ifdef __cplusplus +} +#endif + +#endif // __XUSB_H__ From 7f471e9104fd042fd841a9e41251bcc0d3b577a3 Mon Sep 17 00:00:00 2001 From: xinyun Date: Wed, 17 Sep 2014 09:45:19 +0800 Subject: [PATCH 11/13] add usb stack of init version --- .../CoX_Peripheral_LPC17xx/libcox/hw_usb.h | 396 ++++ .../CoX_Peripheral_LPC17xx/libcox/xusb.c | 803 +++++++ .../libcox/xusb_config.h | 40 + .../CoX_Peripheral_Template/inc/xusb.h | 40 +- .../USB_CLASS/USB_ADC/adc_callback.c | 255 +++ .../USB_CLASS/USB_ADC/adc_callback.h | 56 + .../USB_CLASS/USB_ADC/usb_adc_config.h | 20 + CoX/middleware/USB_CLASS/USB_ADC/usb_audio.h | 903 ++++++++ .../USB_CLASS/USB_CDC/cdc_callback.c | 909 ++++++++ .../USB_CLASS/USB_CDC/cdc_callback.h | 79 + CoX/middleware/USB_CLASS/USB_CDC/usb_cdc.h | 846 ++++++++ .../USB_CLASS/USB_CDC/usb_cdc_config.h | 35 + .../USB_CLASS/USB_HID/hid_callback.c | 245 +++ .../USB_CLASS/USB_HID/hid_callback.h | 53 + CoX/middleware/USB_CLASS/USB_HID/usb_hid.h | 383 ++++ .../USB_CLASS/USB_HID/usb_hid_config.h | 31 + .../USB_CLASS/USB_MSC/msc_callback.c | 776 +++++++ .../USB_CLASS/USB_MSC/msc_callback.h | 58 + CoX/middleware/USB_CLASS/USB_MSC/usb_msc.h | 149 ++ .../USB_CLASS/USB_MSC/usb_msc_config.h | 38 + CoX/middleware/USB_ENUMERATE/type.h | 54 + CoX/middleware/USB_ENUMERATE/usb.h | 265 +++ CoX/middleware/USB_ENUMERATE/usb_Enumerate.c | 1852 +++++++++++++++++ CoX/middleware/USB_ENUMERATE/usb_Enumerate.h | 185 ++ CoX/middleware/USB_ENUMERATE/usb_com_config.h | 36 + CoX/middleware/USB_ENUMERATE/usb_desc.h | 41 + 26 files changed, 8544 insertions(+), 4 deletions(-) create mode 100644 CoX/CoX_Peripheral/CoX_Peripheral_LPC17xx/libcox/hw_usb.h create mode 100644 CoX/CoX_Peripheral/CoX_Peripheral_LPC17xx/libcox/xusb.c create mode 100644 CoX/CoX_Peripheral/CoX_Peripheral_LPC17xx/libcox/xusb_config.h create mode 100644 CoX/middleware/USB_CLASS/USB_ADC/adc_callback.c create mode 100644 CoX/middleware/USB_CLASS/USB_ADC/adc_callback.h create mode 100644 CoX/middleware/USB_CLASS/USB_ADC/usb_adc_config.h create mode 100644 CoX/middleware/USB_CLASS/USB_ADC/usb_audio.h create mode 100644 CoX/middleware/USB_CLASS/USB_CDC/cdc_callback.c create mode 100644 CoX/middleware/USB_CLASS/USB_CDC/cdc_callback.h create mode 100644 CoX/middleware/USB_CLASS/USB_CDC/usb_cdc.h create mode 100644 CoX/middleware/USB_CLASS/USB_CDC/usb_cdc_config.h create mode 100644 CoX/middleware/USB_CLASS/USB_HID/hid_callback.c create mode 100644 CoX/middleware/USB_CLASS/USB_HID/hid_callback.h create mode 100644 CoX/middleware/USB_CLASS/USB_HID/usb_hid.h create mode 100644 CoX/middleware/USB_CLASS/USB_HID/usb_hid_config.h create mode 100644 CoX/middleware/USB_CLASS/USB_MSC/msc_callback.c create mode 100644 CoX/middleware/USB_CLASS/USB_MSC/msc_callback.h create mode 100644 CoX/middleware/USB_CLASS/USB_MSC/usb_msc.h create mode 100644 CoX/middleware/USB_CLASS/USB_MSC/usb_msc_config.h create mode 100644 CoX/middleware/USB_ENUMERATE/type.h create mode 100644 CoX/middleware/USB_ENUMERATE/usb.h create mode 100644 CoX/middleware/USB_ENUMERATE/usb_Enumerate.c create mode 100644 CoX/middleware/USB_ENUMERATE/usb_Enumerate.h create mode 100644 CoX/middleware/USB_ENUMERATE/usb_com_config.h create mode 100644 CoX/middleware/USB_ENUMERATE/usb_desc.h diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_LPC17xx/libcox/hw_usb.h b/CoX/CoX_Peripheral/CoX_Peripheral_LPC17xx/libcox/hw_usb.h new file mode 100644 index 00000000..40dea845 --- /dev/null +++ b/CoX/CoX_Peripheral/CoX_Peripheral_LPC17xx/libcox/hw_usb.h @@ -0,0 +1,396 @@ +//***************************************************************************** +// +//! \file xhw_usb.h +//! \brief Macros used when accessing the usb control hardware. +//! \version V2.2.1.0 +//! \date $CURRENTTIME$ +//! \author CooCox +//! \copyright +//! +//! Copyright (c) 2011, CooCox +//! All rights reserved. +//! +//! Redistribution and use in source and binary forms, with or without +//! modification, are permitted provided that the following conditions +//! are met: +//! * Redistributions of source code must retain the above copyright +//! notice, this list of conditions and the following disclaimer. +//! * Redistributions in binary form must reproduce the above copyright +//! notice, this list of conditions and the following disclaimer in the +//! documentation and/or other materials provided with the distribution. +//! * Neither the name of the nor the names of its +//! contributors may be used to endorse or promote products derived +//! from this software without specific prior written permission. +//! +//! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +//! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +//! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +//! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +//! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +//! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +//! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +//! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +//! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +//! THE POSSIBILITY OF SUCH DAMAGE. +// +//***************************************************************************** + +#ifndef __XHW_USB_H__ +#define __XHW_USB_H__ + +#include "xhw_types.h" +#include "xhw_ints.h" +#include "xcore.h" +#include "xhw_memmap.h" +#include "xhw_nvic.h" +#include "xhw_sysctl.h" +#include "xdebug.h" +#include "xsysctl.h" + +//***************************************************************************** +// +//! \addtogroup CoX_Peripheral_Lib +//! @{ +// +//***************************************************************************** + +//***************************************************************************** +// +//! \addtogroup USBD +//! @{ +// +//***************************************************************************** + +//***************************************************************************** +// +//! \addtogroup LPC17xx_usb_Register usb Register Hardware Layer. +//! \brief Here are detail register information. +//! it contains: +//! - Register offset. +//! - detailed bit-field of the registers. +//! - Enum and mask of the registers. +//! +//! \note Users can read or write the registers through xHWREG(). +//! +//! @{ +// +//***************************************************************************** + +//***************************************************************************** +// +//! \addtogroup LPC17xx_usb_Register_Offsets usb Register Offset(Map) +//! \brief Here is the register offset, users can get the register address +//! via usbx_BASE + offset, (x=A/B/C...). +//! @{ +// +//***************************************************************************** + +//! USB Clock Control +#define USB_CLK_CTRL ((unsigned long)0x5000CFF4) + +//! USB Clock Status +#define USB_CLK_ST ((unsigned long)0x5000CFF8) + +//! USB Interrupt Status +#define USB_INT_ST ((unsigned long)0x400FC1C0) + +//! USB Device Interrupt Status +#define USB_DEV_INT_ST ((unsigned long)0x5000C200) + +//! USB Device Interrupt Enable +#define USB_DEV_INT_EN ((unsigned long)0x5000C204) + +//! USB Device Interrupt Clear +#define USB_DEV_INT_CLR ((unsigned long)0x5000C208) + +//! USB Device Interrupt Set +#define USB_DEV_INT_SET ((unsigned long)0x5000C20C) + +//! USB Device Interrupt Priority +#define USB_DEV_INT_PRI ((unsigned long)0x5000C22C) + +//! USB Endpoint Interrupt Status +#define USB_EP_INT_ST ((unsigned long)0x5000C230) + +//! USB Endpoint Interrupt Enable +#define USB_EP_INT_EN ((unsigned long)0x5000C234) + +//! USB Endpoint Interrupt Clear +#define USB_EP_INT_CLR ((unsigned long)0x5000C238) + +//! USB Endpoint Interrupt Set +#define USB_EP_INT_SET ((unsigned long)0x5000C23C) + +//! USB Endpoint Priority +#define USB_EP_INT_PRI ((unsigned long)0x5000C240) + +//! USB Realize Endpoint +#define USB_RE_EP ((unsigned long)0x5000C244) + +//! USB Endpoint Index +#define USB_EP_INDEX ((unsigned long)0x5000C248) + +//! USB MaxPacketSize +#define USB_MAX_PSIZE ((unsigned long)0x5000C24C) + +//! USB Receive Data +#define USB_RX_DATA ((unsigned long)0x5000C218) + +//! USB Receive Packet Length +#define USB_RX_PLEN ((unsigned long)0x5000C220) + +//! USB Transmit Data +#define USB_TX_DATA ((unsigned long)0x5000C21C) + +//! USB Transmit Packet Length +#define USB_TX_PLEN ((unsigned long)0x5000C224) + +//! USB Control +#define USB_CTRL ((unsigned long)0x5000C228) + + +//! USB Command Code +#define USB_CMD_CODE ((unsigned long)0x5000C210) + +//! USB Command Data +#define USB_CMD_DATA ((unsigned long)0x5000C214) + +//! USB DMA Request Status +#define USB_DMA_RST ((unsigned long)0x5000C250) + +//! USB DMA Request Clear +#define USB_DMA_RCLR ((unsigned long)0x5000C254) + +//! USB DMA Request Set +#define USB_DMA_RSET ((unsigned long)0x5000C258) + +//! USB UDCA Head +#define USB_UDCAH ((unsigned long)0x5000C280) + +//! USB Endpoint DMA Status +#define USB_EP_DMA_ST ((unsigned long)0x5000C284) + +//! USB Endpoint DMA Enable +#define USB_EP_DMA_EN ((unsigned long)0x5000C288) + +//! USB Endpoint DMA Disable +#define USB_EP_DMA_DIS ((unsigned long)0x5000C28C) + +//! USB DMA Interrupt Status +#define USB_DMA_INT_ST ((unsigned long)0x5000C290) + +//! USB DMA Interrupt Enable +#define USB_DMA_INT_EN ((unsigned long)0x5000C294) + +//! USB End of Transfer Interrupt Status +#define USB_EOT_INT_ST ((unsigned long)0x5000C2A0) + +//! USB End of Transfer Interrupt Clear +#define USB_EOT_INT_CLR ((unsigned long)0x5000C2A4) + +//! USB End of Transfer Interrupt Set +#define USB_EOT_INT_SET ((unsigned long)0x5000C2A8) + +//! USB New DD Request Interrupt Status +#define USB_NDDR_INT_ST ((unsigned long)0x5000C2AC) + +//! USB New DD Request Interrupt Clear +#define USB_NDDR_INT_CLR ((unsigned long)0x5000C2B0) + +//! USB New DD Request Interrupt Set +#define USB_NDDR_INT_SET ((unsigned long)0x5000C2B4) + +//! USB System Error Interrupt Status +#define USB_SYS_ERR_INT_ST ((unsigned long)0x5000C2B8) + +//! USB System Error Interrupt Clear +#define USB_SYS_ERR_INT_CLR ((unsigned long)0x5000C2BC) + +//! USB System Error Interrupt Set +#define USB_SYS_ERR_INT_SET ((unsigned long)0x5000C2C0) + +//***************************************************************************** +// +//! @} +// +//***************************************************************************** + +//***************************************************************************** +// +//! \addtogroup LPC17xx_usb_Register_Mcrio usb Register usefull mcrio +//! @{ +// +//***************************************************************************** + +/* Device Interrupt Bit Definitions */ +#define FRAME_INT 0x00000001 +#define EP_FAST_INT 0x00000002 +#define EP_SLOW_INT 0x00000004 +#define DEV_STAT_INT 0x00000008 +#define CCEMTY_INT 0x00000010 +#define CDFULL_INT 0x00000020 +#define RxENDPKT_INT 0x00000040 +#define TxENDPKT_INT 0x00000080 +#define EP_RLZED_INT 0x00000100 +#define ERR_INT 0x00000200 + +/* Rx & Tx Packet Length Definitions */ +#define PKT_LNGTH_MASK 0x000003FF +#define PKT_DV 0x00000400 +#define PKT_RDY 0x00000800 + +/* USB Control Definitions */ +#define CTRL_RD_EN 0x00000001 +#define CTRL_WR_EN 0x00000002 + +/* Command Codes */ +#define CMD_SET_ADDR 0x00D00500 +#define CMD_CFG_DEV 0x00D80500 +#define CMD_SET_MODE 0x00F30500 +#define CMD_RD_FRAME 0x00F50500 +#define DAT_RD_FRAME 0x00F50200 +#define CMD_RD_TEST 0x00FD0500 +#define DAT_RD_TEST 0x00FD0200 +#define CMD_SET_DEV_STAT 0x00FE0500 +#define CMD_GET_DEV_STAT 0x00FE0500 +#define DAT_GET_DEV_STAT 0x00FE0200 +#define CMD_GET_ERR_CODE 0x00FF0500 +#define DAT_GET_ERR_CODE 0x00FF0200 +#define CMD_RD_ERR_STAT 0x00FB0500 +#define DAT_RD_ERR_STAT 0x00FB0200 +#define DAT_WR_BYTE(x) (0x00000100 | ((x) << 16)) +#define CMD_SEL_EP(x) (0x00000500 | ((x) << 16)) +#define DAT_SEL_EP(x) (0x00000200 | ((x) << 16)) +#define CMD_SEL_EP_CLRI(x) (0x00400500 | ((x) << 16)) +#define DAT_SEL_EP_CLRI(x) (0x00400200 | ((x) << 16)) +#define CMD_SET_EP_STAT(x) (0x00400500 | ((x) << 16)) +#define CMD_CLR_BUF 0x00F20500 +#define DAT_CLR_BUF 0x00F20200 +#define CMD_VALID_BUF 0x00FA0500 + +/* Device Address Register Definitions */ +#define DEV_ADDR_MASK 0x7F +#define DEV_EN 0x80 + +/* Device Configure Register Definitions */ +#define CONF_DVICE 0x01 + +/* Device Mode Register Definitions */ +#define AP_CLK 0x01 +#define INAK_CI 0x02 +#define INAK_CO 0x04 +#define INAK_II 0x08 +#define INAK_IO 0x10 +#define INAK_BI 0x20 +#define INAK_BO 0x40 + +/* Device Status Register Definitions */ +#define DEV_CON 0x01 +#define DEV_CON_CH 0x02 +#define DEV_SUS 0x04 +#define DEV_SUS_CH 0x08 +#define DEV_RST 0x10 + +/* Error Code Register Definitions */ +#define ERR_EC_MASK 0x0F +#define ERR_EA 0x10 + +/* Error Status Register Definitions */ +#define ERR_PID 0x01 +#define ERR_UEPKT 0x02 +#define ERR_DCRC 0x04 +#define ERR_TIMOUT 0x08 +#define ERR_EOP 0x10 +#define ERR_B_OVRN 0x20 +#define ERR_BTSTF 0x40 +#define ERR_TGL 0x80 + +/* Endpoint Select Register Definitions */ +#define EP_SEL_F 0x01 +#define EP_SEL_ST 0x02 +#define EP_SEL_STP 0x04 +#define EP_SEL_PO 0x08 +#define EP_SEL_EPN 0x10 +#define EP_SEL_B_1_FULL 0x20 +#define EP_SEL_B_2_FULL 0x40 + +/* Endpoint Status Register Definitions */ +#define EP_STAT_ST 0x01 +#define EP_STAT_DA 0x20 +#define EP_STAT_RF_MO 0x40 +#define EP_STAT_CND_ST 0x80 + +/* Clear Buffer Register Definitions */ +#define CLR_BUF_PO 0x01 + + +/* DMA Interrupt Bit Definitions */ +#define EOT_INT 0x01 +#define NDD_REQ_INT 0x02 +#define SYS_ERR_INT 0x04 + + +/* USB RAM Definitions */ +#define USB_RAM_ADR 0x20080000 /* USB RAM Start Address */ +#define USB_RAM_SZ 0x00004000 /* USB RAM Size (4kB) */ + +/* DMA Endpoint Descriptors */ +#define DD_NISO_CNT 16 /* Non-Iso EP DMA Descr. Count (max. 32) */ +#define DD_ISO_CNT 8 /* Iso EP DMA Descriptor Count (max. 32) */ +#define DD_NISO_SZ (DD_NISO_CNT * 16) /* Non-Iso DMA Descr. Size */ +#define DD_ISO_SZ (DD_ISO_CNT * 20) /* Iso DMA Descriptor Size */ +#define DD_NISO_ADR (USB_RAM_ADR + 128) /* Non-Iso DMA Descr. Address */ +#define DD_ISO_ADR (DD_NISO_ADR + DD_NISO_SZ) /* Iso DMA Descr. Address */ +#define DD_SZ (128 + DD_NISO_SZ + DD_ISO_SZ) /* Descr. Size */ + +/* DMA Buffer Memory Definitions */ +#define DMA_BUF_ADR (USB_RAM_ADR + DD_SZ) /* DMA Buffer Start Address */ +#define DMA_BUF_SZ (USB_RAM_SZ - DD_SZ) /* DMA Buffer Size */ + +/* USB Error Codes */ +#define USB_ERR_PID 0x0001 /* PID Error */ +#define USB_ERR_UEPKT 0x0002 /* Unexpected Packet */ +#define USB_ERR_DCRC 0x0004 /* Data CRC Error */ +#define USB_ERR_TIMOUT 0x0008 /* Bus Time-out Error */ +#define USB_ERR_EOP 0x0010 /* End of Packet Error */ +#define USB_ERR_B_OVRN 0x0020 /* Buffer Overrun */ +#define USB_ERR_BTSTF 0x0040 /* Bit Stuff Error */ +#define USB_ERR_TGL 0x0080 /* Toggle Bit Error */ + +/* USB DMA Status Codes */ +#define USB_DMA_INVALID 0x0000 /* DMA Invalid - Not Configured */ +#define USB_DMA_IDLE 0x0001 /* DMA Idle - Waiting for Trigger */ +#define USB_DMA_BUSY 0x0002 /* DMA Busy - Transfer in progress */ +#define USB_DMA_DONE 0x0003 /* DMA Transfer Done (no Errors)*/ +#define USB_DMA_OVER_RUN 0x0004 /* Data Over Run */ +#define USB_DMA_UNDER_RUN 0x0005 /* Data Under Run (Short Packet) */ +#define USB_DMA_ERROR 0x0006 /* Error */ +#define USB_DMA_UNKNOWN 0xFFFF /* Unknown State */ + +//***************************************************************************** +// +//! @} +// +//***************************************************************************** + + +//***************************************************************************** +// +//! @} +// +//***************************************************************************** + +//***************************************************************************** +// +//! @} +// +//***************************************************************************** + +//***************************************************************************** +// +//! @} +// +//***************************************************************************** +#endif // __XHW_usb_H__ + diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_LPC17xx/libcox/xusb.c b/CoX/CoX_Peripheral/CoX_Peripheral_LPC17xx/libcox/xusb.c new file mode 100644 index 00000000..dce2b3c6 --- /dev/null +++ b/CoX/CoX_Peripheral/CoX_Peripheral_LPC17xx/libcox/xusb.c @@ -0,0 +1,803 @@ +//***************************************************************************** +// +//! \file xusb.c +//! \brief Driver for the USB driver. +//! \version V2.2.1.0 +//! \date 09/20/2014 +//! \author CooCox +//! \copy +//! +//! Copyright (c) 2014, CooCox +//! All rights reserved. +//! +//! Redistribution and use in source and binary forms, with or without +//! modification, are permitted provided that the following conditions +//! are met: +//! * Redistributions of source code must retain the above copyright +//! notice, this list of conditions and the following disclaimer. +//! * Redistributions in binary form must reproduce the above copyright +//! notice, this list of conditions and the following disclaimer in the +//! documentation and/or other materials provided with the distribution. +//! * Neither the name of the nor the names of its +//! contributors may be used to endorse or promote products derived +//! from this software without specific prior written permission. +//! +//! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +//! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +//! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +//! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +//! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +//! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +//! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +//! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +//! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +//! THE POSSIBILITY OF SUCH DAMAGE. +// +//***************************************************************************** +#include "xhw_types.h" +#include "xhw_ints.h" +#include "xcore.h" +#include "xhw_memmap.h" +#include "hw_usb.h" +#include "xhw_gpio.h" +#include "xusb.h" +#include "usb_com_config.h" +#include "cox_config.h" +#include "xhw_types.h" + +xtBoolean xUSBReset (void); +xtBoolean xUSBSetAddress (unsigned long ulAddr); + +static xtEventCallback g_pfnUSBEndPointEvent[USB_LOGIC_EP_NUM] = {0}; + +static xtEventCallback g_pfnUSBWakeUpEvent = NULL; +static xtEventCallback g_pfnUSBResetEvent = NULL; +static xtEventCallback g_pfnUSBSuspendEvent = NULL; +static xtEventCallback g_pfnUSBResumeEvent = NULL; +static xtEventCallback g_pfnUSBErrorEvent = NULL; +static xtEventCallback g_pfnUSBSOFEvent = NULL; + +static void *vpUSBEndPointEventData[USB_LOGIC_EP_NUM]={NULL}; + +#define EP_MSK_CTRL 0x0001 /* Control Endpoint Logical Address Mask */ +#define EP_MSK_BULK 0xC924 /* Bulk Endpoint Logical Address Mask */ +#define EP_MSK_INT 0x4492 /* Interrupt Endpoint Logical Address Mask */ +#define EP_MSK_ISO 0x1248 /* Isochronous Endpoint Logical Address Mask */ + +//***************************************************************************** +// +//! \brief Get Endpoint Physical Address +//! +//! \param ulEPNum Endpoint Number. +//! ulEPNum.0..3: Address +//! ulEPNum.7: Dir +//! +//! \return Endpoint Physical Address. +// +//***************************************************************************** +unsigned long EndPointAddressGet (unsigned long ulEPNum) { + unsigned long ulVal; + + ulVal = (ulEPNum & 0x0F) << 1; + if (ulEPNum & 0x80) { + ulVal += 1; + } + return (ulVal); +} + +/* + * Write Command + * Parameters: cmd: Command + * Return Value: None + */ +//***************************************************************************** +// +//! \brief Write Command +//! +//! \param cmd: Command +//! +//! \return None +// +//***************************************************************************** +void USBCommandCodeWrite (unsigned long cmd) { + + xHWREG(USB_DEV_INT_CLR) = CCEMTY_INT; + xHWREG(USB_CMD_CODE) = cmd; + while ((xHWREG(USB_DEV_INT_ST) & CCEMTY_INT) == 0); +} + +void USBCommandDataWrite (unsigned long cmd, unsigned long val) { + + xHWREG(USB_DEV_INT_CLR) = CCEMTY_INT; + xHWREG(USB_CMD_CODE) = cmd; + while ((xHWREG(USB_DEV_INT_ST) & CCEMTY_INT) == 0); + xHWREG(USB_DEV_INT_CLR) = CCEMTY_INT; + xHWREG(USB_CMD_CODE) = val; + while ((xHWREG(USB_DEV_INT_ST) & CCEMTY_INT) == 0); +} + +void USBCommandEndPointWrite (unsigned long EPNum, unsigned long cmd){ + + xHWREG(USB_DEV_INT_ST) = CCEMTY_INT; + xHWREG(USB_CMD_CODE)= CMD_SEL_EP(EndPointAddressGet(EPNum)); + while ((xHWREG(USB_DEV_INT_ST) & CCEMTY_INT) == 0); + xHWREG(USB_DEV_INT_CLR) = CCEMTY_INT; + xHWREG(USB_CMD_CODE) = cmd; + while ((xHWREG(USB_DEV_INT_ST) & CCEMTY_INT) == 0); +} +unsigned long USBCommandDataRead (unsigned long cmd) { + + xHWREG(USB_DEV_INT_CLR) = CCEMTY_INT | CDFULL_INT; + xHWREG(USB_CMD_CODE) = cmd; + while ((xHWREG(USB_DEV_INT_ST) & CDFULL_INT) == 0); + return (xHWREG(USB_CMD_DATA)); +} + +xtBoolean xUSBIOClkConfig(void) +{ + xHWREG(SCS) = 0x20; + if (xHWREG(SCS) & (1 << 5)) { /* If Main Oscillator is enabled */ + while ((xHWREG(SCS) & (1<<6)) == 0);/* Wait for Oscillator to be ready */ + } + + xHWREG(CCLKCFG) = 0x07; /* Setup Clock Divider */ + /* Periphral clock must be selected before PLL0 enabling and connecting + * - according errata.lpc1768-16.March.2010 - + */ + xHWREG(PCLKSEL0) = 0; /* Peripheral Clock Selection */ + xHWREG(PCLKSEL1) = 0; + + xHWREG(CLKSRCSEL) = 1; /* Select Clock Source for PLL0 */ + + xHWREG(PLL0CFG) = 0x2003f; /* configure PLL0 */ + xHWREG(PLL0FEED) = 0xAA; + xHWREG(PLL0FEED) = 0x55; + + xHWREG(PLL0CON) = 0x01; /* PLL0 Enable */ + xHWREG(PLL0FEED) = 0xAA; + xHWREG(PLL0FEED) = 0x55; + while (!(xHWREG(PLL0STAT) & (1<<26)));/* Wait for PLOCK0 */ + + xHWREG(PLL0CON) = 0x03; /* PLL0 Enable & Connect */ + xHWREG(PLL0FEED) = 0xAA; + xHWREG(PLL0FEED) = 0x55; + while (!(xHWREG(PLL0STAT) & ((1<<25) | (1<<24))));/* Wait for PLLC0_STAT & PLLE0_STAT */ + + /* Enable AHB clock to the GPIO domain. */ + xHWREG(PLL1CFG) = 0x00000023; + xHWREG(PLL1FEED) = 0xAA; + xHWREG(PLL1FEED) = 0x55; + + xHWREG(PLL1CON) = 0x01; /* PLL1 Enable */ + xHWREG(PLL1FEED) = 0xAA; + xHWREG(PLL1FEED) = 0x55; + while (!(xHWREG(PLL1STAT) & (1<<10)));/* Wait for PLOCK1 */ + + xHWREG(PLL1CON) = 0x03; /* PLL1 Enable & Connect */ + xHWREG(PLL1FEED) = 0xAA; + xHWREG(PLL1FEED) = 0x55; + while (!(xHWREG(PLL1STAT) & ((1<< 9) | (1<< 8))));/* Wait for PLLC1_STAT & PLLE1_STAT */ + + + xHWREG(PCONP) = 0x042887DE; /* Power Control for Peripherals */ + + xHWREG(CLKOUTCFG) = 0; /* Clock Output Configuration */ + return xtrue; +} + +//***************************************************************************** +// +//! \brief USB Initialize Function +//! +//! \return None. +// +//***************************************************************************** +void xUSBInit(void) +{ + //! P0.29 D+, P0.30 D- + xHWREG(PIN_CON_BASE + PINSEL1) &= ~((3<<26)|(3<<28)); + // PINSEL1 26.27, 28.29 = 01 + xHWREG(PIN_CON_BASE + PINSEL1) |= ((1<<26)|(1<<28)); + + + // P1.18 GoodLink, P1.30 VBUS + xHWREG(PIN_CON_BASE + PINSEL3) &= ~((3<< 4)|(3<<28)); + // PINSEL3 4.5 = 01, 28.29 = 10 + xHWREG(PIN_CON_BASE + PINSEL3) |= ((1<< 4)|(2<<28)); + + + // P2.9 SoftConnect + xHWREG(PIN_CON_BASE + PINSEL4) &= ~((3<<18) ); + xHWREG(PIN_CON_BASE + PINSEL4) |= ((1<<18) ); + + // USB PCLK -> enable USB Per. + xHWREG(PCONP) |= (1UL<<31); + xHWREG(USB_CLK_CTRL) = 0x1A; + while ((xHWREG(USB_CLK_ST) & 0x1A) != 0x1A); + + xIntEnable(xINT_USB); + + xUSBReset(); + xUSBSetAddress(0); +} + +//***************************************************************************** +// +//! \brief Disables the USB master block. +//! This function will disable operation of the USB Master block. +//! +//! \param [in] ulBase is the USB Connect/Disconnect. +//! - \ref xUSB_CONNECT +//! - \ref xUSB_DISCONNECT +//! +//! \return xtrue or xfalse. +// +//***************************************************************************** +xtBoolean xUSBConnect (unsigned long ulConnect) { + USBCommandDataWrite(CMD_SET_DEV_STAT, DAT_WR_BYTE(ulConnect ? DEV_CON : 0)); + return xtrue; +} + +//***************************************************************************** +// +//! \brief USB Reset Function +//! +//! \param None +//! +//! \return xtrue or xfalse. +// +//***************************************************************************** +xtBoolean xUSBReset(void) +{ + + xHWREG(USB_EP_INDEX) = 0; + xHWREG(USB_MAX_PSIZE) = USB_MAX_PACKET0; + xHWREG(USB_EP_INDEX) = 1; + xHWREG(USB_MAX_PSIZE) = USB_MAX_PACKET0; + while ((xHWREG(USB_DEV_INT_ST) & EP_RLZED_INT) == 0); + + xHWREG(USB_EP_INT_CLR) = 0xFFFFFFFF; + xHWREG(USB_EP_INT_EN) = 0xFFFFFFFF ^ 0; + xHWREG(USB_DEV_INT_CLR) = 0xFFFFFFFF; + xHWREG(USB_DEV_INT_EN) = DEV_STAT_INT | EP_SLOW_INT | + (USB_SOF_EVENT ? FRAME_INT : 0) | + (USB_ERROR_EVENT ? ERR_INT : 0); + return xtrue; + +} +//***************************************************************************** +// +//! \brief USB Suspend Function +//! +//! \param None +//! +//! \return xtrue or xfalse. +// +//***************************************************************************** +xtBoolean xUSBSuspend(void) +{ + return xtrue; +} + +//***************************************************************************** +// +//! \brief USB Resume Function +//! +//! \param None +//! +//! \return xtrue or xfalse. +// +//***************************************************************************** +xtBoolean xUSBResume(void) +{ + return xtrue; +} + +//***************************************************************************** +// +//! \brief USB Wakeup Function +//! +//! \param None +//! +//! \return xtrue or xfalse. +// +//***************************************************************************** +xtBoolean xUSBWakeUp(void) +{ + +// if (USB_DeviceStatus & USB_GETSTATUS_REMOTE_WAKEUP) { + USBCommandDataWrite(CMD_SET_DEV_STAT, DAT_WR_BYTE(DEV_CON)); +// } + return xtrue; +} + +//***************************************************************************** +// +//! \brief USB Remote Wakeup Enbale Function +//! +//! \param None +//! +//! \return The status: +//! - xtrue +//! - xfalse +// +//***************************************************************************** +xtBoolean xUSBWakeUpEnable(void) +{ + return xtrue; +} + +//***************************************************************************** +// +//! \brief USB Remote Wakeup Disable Function +//! +//! \param None +//! +//! \return The status: +//! - xtrue +//! - xfalse +// +//***************************************************************************** +xtBoolean xUSBWakeUpDisable(void) +{ + return xtrue; +} + +//***************************************************************************** +// +//! \brief USB Set Address Function. +//! +//! \param [in] ulBase is the USB Address. +//! +//! \return The status: +//! - xtrue +//! - xfalse +// +//***************************************************************************** +xtBoolean xUSBSetAddress(unsigned long ulAddr) +{ + USBCommandDataWrite(CMD_SET_ADDR, DAT_WR_BYTE(DEV_EN | ulAddr)); + USBCommandDataWrite(CMD_SET_ADDR, DAT_WR_BYTE(DEV_EN | ulAddr)); + return xtrue; +} + +//***************************************************************************** +// +//! \brief USB Set Configure Function. +//! +//! \param [in] ulBase is the USB Configure/Deconfigure. +//! +//! \return The status: +//! - xtrue +//! - xfalse +// +//***************************************************************************** +xtBoolean xUSBConfigure(unsigned long ulConfig) +{ + USBCommandDataWrite(CMD_CFG_DEV, DAT_WR_BYTE(ulConfig ? CONF_DVICE : 0)); + + xHWREG(USB_RE_EP) = 0x00000003; + while ((xHWREG(USB_DEV_INT_ST) & EP_RLZED_INT) == 0); + xHWREG(USB_DEV_INT_CLR) = EP_RLZED_INT; + return xtrue; +} + + +//***************************************************************************** +// +//! \brief Configure USB Endpoint according to Descriptor +//! +//! \param [in] ulBase Pointer to Endpoint Descriptor +//! ulDir: Out (dir == 0), In (dir <> 0) +//! +//! \return The status: +//! - xtrue +//! - xfalse +// +//***************************************************************************** +xtBoolean xUSBEndpointConfig(USB_ENDPOINT_DESCRIPTOR *epConfig, unsigned long ulDir) +{ + unsigned long num; + + num = EndPointAddressGet(epConfig->bEndpointAddress); + xHWREG(USB_RE_EP) |= (1 << num); + xHWREG(USB_EP_INDEX) = num; + xHWREG(USB_MAX_PSIZE) = epConfig->wMaxPacketSize; + while ((xHWREG(USB_DEV_INT_ST) & EP_RLZED_INT) == 0); + xHWREG(USB_DEV_INT_CLR) = EP_RLZED_INT; + return xtrue; +} +xtBoolean xUSBEndpointDirCtr(unsigned long ulDir) +{ + return xtrue; +} + +//***************************************************************************** +// +//! \brief Enable USB Endpoint +//! +//! \param [in] ulBase Endpoint Number. +//! bit 0-3 Address +//! bit 7 Dir +//! +//! \return The status: +//! - xtrue +//! - xfalse +// +//***************************************************************************** +xtBoolean xUSBEndpointEnable(unsigned long ulNum) +{ + USBCommandDataWrite(CMD_SET_EP_STAT(EndPointAddressGet(ulNum)), DAT_WR_BYTE(0)); + return xtrue; +} + +//***************************************************************************** +// +//! \brief Disable USB Endpoint +//! +//! \param [in] ulBase Endpoint Number. +//! bit 0-3 Address +//! bit 7 Dir +//! +//! \return The status: +//! - xtrue +//! - xfalse +// +//***************************************************************************** +xtBoolean xUSBEndpointDisable(unsigned long ulNum) +{ + USBCommandDataWrite(CMD_SET_EP_STAT(EndPointAddressGet(ulNum)), DAT_WR_BYTE(EP_STAT_DA)); + return xtrue; +} + +//***************************************************************************** +// +//! \brief Reset USB Endpoint +//! +//! \param [in] ulBase Endpoint Number. +//! bit 0-3 Address +//! bit 7 Dir +//! +//! \return The status: +//! - xtrue +//! - xfalse +// +//***************************************************************************** +xtBoolean xUSBEndpointReset(unsigned long ulNum) +{ + USBCommandDataWrite(CMD_SET_EP_STAT(EndPointAddressGet(ulNum)), DAT_WR_BYTE(0)); + return xtrue; +} + +//***************************************************************************** +// +//! \brief Set Stall for USB Endpoint +//! +//! \param [in] ulBase Endpoint Number. +//! bit 0-3 Address +//! bit 7 Dir +//! +//! \return The status: +//! - xtrue +//! - xfalse +// +//***************************************************************************** +xtBoolean xUSBEndpointStallSet(unsigned long ulNum) +{ + USBCommandDataWrite(CMD_SET_EP_STAT(EndPointAddressGet(ulNum)), DAT_WR_BYTE(EP_STAT_ST)); + return xtrue; +} + +//***************************************************************************** +// +//! \brief Clear Stall for USB Endpoint +//! +//! \param [in] ulBase Endpoint Number. +//! bit 0-3 Address +//! bit 7 Dir +//! +//! \return The status: +//! - xtrue +//! - xfalse +// +//***************************************************************************** +xtBoolean xUSBEndpointStallClear(unsigned long ulNum) +{ + USBCommandDataWrite(CMD_SET_EP_STAT(EndPointAddressGet(ulNum)), DAT_WR_BYTE(0)); + return xtrue; +} + +//***************************************************************************** +// +//! \brief Set max packet size for control out +//! +//! \param [in] None +//! +//! \return The status: +//! - xtrue +//! - xfalse +// +//***************************************************************************** +xtBoolean xUSBControlOutEnble(void) +{ + return xtrue; +} + +//***************************************************************************** +// +//! \brief Clear USB Endpoint Buffer +//! +//! \param [in] ulBase Endpoint Number. +//! bit 0-3 Address +//! bit 7 Dir +//! +//! \return The status: +//! - xtrue +//! - xfalse +// +//***************************************************************************** +xtBoolean xUSBEndpointBufferClear(unsigned long ulNum) +{ + return xtrue; +} + +//***************************************************************************** +// +//! \brief Read USB Endpoint Data +//! +//! \param [in] ulBase Endpoint Number. +//! bit 0-3 Address +//! bit 7 Dir +//! ucpData: Pointer to Data Buffer +//! +//! \return Number of bytes read +// +//***************************************************************************** +unsigned long xUSBEndpointRead(unsigned long ulNum,unsigned char *ucpData) +{ + unsigned long cnt, n; + + xHWREG(USB_CTRL) = ((ulNum & 0x0F) << 2) | CTRL_RD_EN; + + do { + cnt = xHWREG(USB_RX_PLEN); + } while ((cnt & PKT_RDY) == 0); + cnt &= PKT_LNGTH_MASK; + + for (n = 0; n < (cnt + 3) / 4; n++) { + *((__attribute__((packed)) unsigned long *)ucpData) = xHWREG(USB_RX_DATA); + ucpData += 4; + } + xHWREG(USB_CTRL) = 0; + + if (((EP_MSK_ISO >> ulNum) & 1) == 0) { /* Non-Isochronous Endpoint */ + USBCommandCodeWrite(CMD_SEL_EP(EndPointAddressGet(ulNum))); + USBCommandCodeWrite(CMD_CLR_BUF); + } + return (cnt); +} + +//***************************************************************************** +// +//! \brief Write USB Endpoint Data +//! +//! \param [in] ulBase Endpoint Number. +//! bit 0-3 Address +//! bit 7 Dir +//! ucpData: Pointer to Data Buffer +//! ulLen Number of bytes +//! +//! \return Number of bytes written +// +//***************************************************************************** +unsigned long xUSBEndpointWrite(unsigned long ulNum,unsigned char *ucpData, + unsigned long ulLen) +{ + unsigned long n; + + xHWREG(USB_CTRL) = ((ulNum & 0x0F) << 2) | CTRL_WR_EN; + + xHWREG(USB_TX_PLEN) = ulLen; + + for (n = 0; n < (ulLen + 3) / 4; n++) { + xHWREG(USB_TX_DATA) = *((__attribute__((packed)) unsigned long *)ucpData); + ucpData += 4; + } + xHWREG(USB_CTRL) = 0; + + USBCommandCodeWrite(CMD_SEL_EP(EndPointAddressGet(ulNum))); + USBCommandCodeWrite(CMD_VALID_BUF); + return (ulLen); +} + +//***************************************************************************** +// +//! \brief Get USB Last Frame Number +//! +//! \param [in] None +//! +//! \return number of last frame +// +//***************************************************************************** +unsigned long xUSBFrameGet(void) +{ + unsigned long val; + + USBCommandCodeWrite(CMD_RD_FRAME); + val = USBCommandDataRead(DAT_RD_FRAME); + val = val | (USBCommandDataRead(DAT_RD_FRAME) << 8); + return (val); +} + + +//***************************************************************************** +// +//! \brief Set max packet size for control out +//! +//! \param [in] event: The logic number of USB endpoint +//! handler: The callback function of USB endpoint +//! data: The extern type which is using here +//! +//! \return The status: +//! - xtrue +//! - xfalse +// +//***************************************************************************** +xtBoolean xUSBEventHandler(unsigned char event, xtEventCallback handler, void *data) +{ + xtBoolean err = xfalse; + if(event == 0) + { + g_pfnUSBEndPointEvent[0] = handler; + vpUSBEndPointEventData[0] = data; + err = xtrue; + return err; + } + switch(event) + { + case USB_EVENT_EP1 : + g_pfnUSBEndPointEvent[1] = handler; + vpUSBEndPointEventData[1] = data; + err = xtrue; + break; + case USB_EVENT_EP2 : + g_pfnUSBEndPointEvent[2] = handler; + vpUSBEndPointEventData[2] = data; + err = xtrue; + break; + case USB_EVENT_EP3 : + g_pfnUSBEndPointEvent[3] = handler; + vpUSBEndPointEventData[3] = data; + err = xtrue; + break; + case USB_EVENT_EP4 : + g_pfnUSBEndPointEvent[4] = handler; + vpUSBEndPointEventData[4] = data; + err = xtrue; + break; + case USB_EVENT_EP5 : + g_pfnUSBEndPointEvent[5] = handler; + vpUSBEndPointEventData[5] = data; + err = xtrue; + break; + case USB_EVENT_EP6 : + g_pfnUSBEndPointEvent[6] = handler; + vpUSBEndPointEventData[6] = data; + err = xtrue; + break; + case USB_EVENT_EP7 : + g_pfnUSBEndPointEvent[7] = handler; + vpUSBEndPointEventData[7] = data; + err = xtrue; + break; + } + return err; + +} + +unsigned long ulTest[100] = {0}; +int testIndex = 0; + +void USBIntHandler(void) { + unsigned long disr, val, n, m; + unsigned long episr, episrCur; + + disr = xHWREG(USB_DEV_INT_ST); /* Device Interrupt Status */ + xHWREG(USB_DEV_INT_CLR) = disr; + if(testIndex<100) + ulTest[testIndex++] = disr; + + /* Device Status Interrupt (Reset, Connect change, Suspend/Resume) */ + if (disr & DEV_STAT_INT) { +// LPC_USB->DevIntClr = DEV_STAT_INT; + USBCommandCodeWrite(CMD_GET_DEV_STAT); + val = USBCommandDataRead(DAT_GET_DEV_STAT); /* Device Status */ + if (val & DEV_RST) { /* Reset */ + ulTest[testIndex++] = 0xFF01; + xUSBReset(); +#if USB_RESET_EVENT + USB_Reset_Event(); +#endif + } + if (val & DEV_CON_CH) { /* Connect change */ +#if USB_POWER_EVENT + USB_Power_Event(val & DEV_CON); +#endif + } + if (val & DEV_SUS_CH) { /* Suspend/Resume */ + if (val & DEV_SUS) { /* Suspend */ + ulTest[testIndex++] = 0xFF02; + xUSBSuspend(); +#if USB_SUSPEND_EVENT + USB_Suspend_Event(); +#endif + } else { /* Resume */ + ulTest[testIndex++] = 0xFF03; + xUSBResume(); +#if USB_RESUME_EVENT + USB_Resume_Event(); +#endif + } + } + goto isr_end; + } + +#if USB_SOF_EVENT + /* Start of Frame Interrupt */ + if (disr & FRAME_INT) { + USB_SOF_Event(); + } +#endif + +#if USB_ERROR_EVENT + /* Error Interrupt */ + if (disr & ERR_INT) { + USBCommandCodeWrite(CMD_RD_ERR_STAT); + val = USBCommandDataRead(DAT_RD_ERR_STAT); + USB_Error_Event(val); + } +#endif + + /* Endpoint's Slow Interrupt */ + if (disr & EP_SLOW_INT) { +// while (LPC_USB->USBEpIntSt) { /* Endpoint Interrupt Status */ + episrCur = 0; + episr = xHWREG(USB_EP_INT_ST); + for (n = 0; n < USB_EP_NUM; n++) { /* Check All Endpoints */ + if (episr == episrCur) break; /* break if all EP interrupts handled */ + if (episr & (1 << n)) { + episrCur |= (1 << n); + m = n >> 1; + + xHWREG(USB_EP_INT_CLR) = (1 << n); + while ((xHWREG(USB_DEV_INT_ST) & CDFULL_INT) == 0); + val = xHWREG(USB_CMD_DATA); + + if ((n & 1) == 0) { /* OUT Endpoint */ + if (n == 0) { /* Control OUT Endpoint */ + if (val & EP_SEL_STP) { /* Setup Packet */ + if (g_pfnUSBEndPointEvent[0]) { + g_pfnUSBEndPointEvent[0](vpUSBEndPointEventData[0],USB_EVT_SETUP,0,0); + continue; + } + } + } + if (g_pfnUSBEndPointEvent[m]) { + g_pfnUSBEndPointEvent[m](vpUSBEndPointEventData[m],USB_EVT_OUT,0,0); + } + } else { /* IN Endpoint */ + if (g_pfnUSBEndPointEvent[m]) { + g_pfnUSBEndPointEvent[m](vpUSBEndPointEventData[m],USB_EVT_IN,0,0); + } + } + } + } + xHWREG(USB_DEV_INT_CLR) = EP_SLOW_INT; + } + + + +isr_end: + return; +} diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_LPC17xx/libcox/xusb_config.h b/CoX/CoX_Peripheral/CoX_Peripheral_LPC17xx/libcox/xusb_config.h new file mode 100644 index 00000000..0c9ca0ce --- /dev/null +++ b/CoX/CoX_Peripheral/CoX_Peripheral_LPC17xx/libcox/xusb_config.h @@ -0,0 +1,40 @@ +/***************************************************************************** + * U S B - N U C - C O X - C O M P O N E N T + ****************************************************************************/ +/** + * @file : cox_config.h + * @brief : config file + * @version : 1.0 + * @date : 28. Dec. 2010 + * @author : CooCox + ****************************************************************************/ + +#ifndef __COX_CONFIG_H +#define __COX_CONFIG_H + + +#define USB_EP_NUM 32 /*!< Max Number of Endpoints <1-32>*/ +#define USB_LOGIC_EP_NUM 16 /*! */ +#define USB_MAX_PACKET0 64 +//#define USB_DMA 1 +#define USB_DMA_EP 0x00000000 + +#define CTRL_EP_NUM 0 /*!< control Endpoint number <0> */ + + +#define USB_POWER_EVENT 0 +#define USB_RESET_EVENT 0 +#define USB_SUSPEND_EVENT 0 +#define USB_RESUME_EVENT 0 +#define USB_WAKEUP_EVENT 0 +#define USB_SOF_EVENT 0 +#define USB_ERROR_EVENT 0 +#define USB_EP_EVENT 0x0005 +#define USB_CONFIGURE_EVENT 0 +#define USB_INTERFACE_EVENT 0 +#define USB_FEATURE_EVENT 0 + + + + +#endif /* __COX_CONFIG_H */ diff --git a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xusb.h b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xusb.h index ce522dbb..b0eb1074 100644 --- a/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xusb.h +++ b/CoX/CoX_Peripheral/CoX_Peripheral_Template/inc/xusb.h @@ -39,8 +39,9 @@ #ifndef __XUSB_H__ #define __XUSB_H__ -#include "usb.h" -#include "xPort.h" +//#include "usb.h" +//#include "xPort.h" +#include "xhw_types.h" //***************************************************************************** // @@ -138,6 +139,33 @@ typedef struct _USB_ENDPOINT_DESCRIPTOR { unsigned char bInterval; } __attribute__((packed)) USB_ENDPOINT_DESCRIPTOR; +#define USB_EVENT_EP0 0 +#define USB_EVENT_EP1 1 +#define USB_EVENT_EP2 2 +#define USB_EVENT_EP3 3 +#define USB_EVENT_EP4 4 +#define USB_EVENT_EP5 5 +#define USB_EVENT_EP6 6 +#define USB_EVENT_EP7 7 +#define USB_EVENT_EP8 8 +#define USB_EVENT_EP9 9 +#define USB_EVENT_EP10 10 +#define USB_EVENT_EP11 11 + +#define USB_EVT_SETUP 1 /* Setup Packet */ +#define USB_EVT_OUT 2 /* OUT Packet */ +#define USB_EVT_IN 3 /* IN Packet */ +#define USB_EVT_OUT_NAK 4 /* OUT Packet - Not Acknowledged */ +#define USB_EVT_IN_NAK 5 /* IN Packet - Not Acknowledged */ +#define USB_EVT_OUT_STALL 6 /* OUT Packet - Stalled */ +#define USB_EVT_IN_STALL 7 /* IN Packet - Stalled */ +#define USB_EVT_OUT_DMA_EOT 8 /* DMA OUT EP - End of Transfer */ +#define USB_EVT_IN_DMA_EOT 9 /* DMA IN EP - End of Transfer */ +#define USB_EVT_OUT_DMA_NDR 10 /* DMA OUT EP - New Descriptor Request */ +#define USB_EVT_IN_DMA_NDR 11 /* DMA IN EP - New Descriptor Request */ +#define USB_EVT_OUT_DMA_ERR 12 /* DMA OUT EP - Error */ +#define USB_EVT_IN_DMA_ERR 13 /* DMA IN EP - Error */ + //***************************************************************************** // //! @} @@ -160,10 +188,12 @@ typedef struct _USB_ENDPOINT_DESCRIPTOR { //! | \ref xUSBSuspend | Mandatory | //! | \ref xUSBResume | Mandatory | //! | \ref xUSBWakeUp | Mandatory | -//! | \ref xUSBWakeUpConfig | Mandatory | +//! | \ref xUSBWakeUpEnable | Mandatory | +//! | \ref xUSBWakeUpDisable | Mandatory | //! | \ref xUSBSetAddress | Mandatory | -//! | \ref xUSBIsConfigured | Mandatory | +//! | \ref xUSBConfigure | Mandatory | //! | \ref xUSBEndpointConfig | Mandatory | +//! | \ref xUSBEndpointDirCtr | Mandatory | //! | \ref xUSBEndpointEnable | Mandatory | //! | \ref xUSBEndpointDisable | Mandatory | //! | \ref xUSBEndpointReset | Mandatory | @@ -323,6 +353,8 @@ extern xtBoolean xUSBConfigure(unsigned long ulConfig); //***************************************************************************** extern xtBoolean xUSBEndpointConfig(USB_ENDPOINT_DESCRIPTOR *epConfig, unsigned long ulDir); +extern xtBoolean xUSBEndpointDirCtr(unsigned long ulDir); + //***************************************************************************** // //! \brief Enable USB Endpoint diff --git a/CoX/middleware/USB_CLASS/USB_ADC/adc_callback.c b/CoX/middleware/USB_CLASS/USB_ADC/adc_callback.c new file mode 100644 index 00000000..33e990a4 --- /dev/null +++ b/CoX/middleware/USB_CLASS/USB_ADC/adc_callback.c @@ -0,0 +1,255 @@ +/***************************************************************************** + * U S B - A D C - C O M P O N E N T + ****************************************************************************/ +/** + * @file : adc_callback.c + * @brief : USB Audio Device Class call back componet + * @version : 1.1 + * @date : 13. Mar. 2011 + * @author : CooCox + ****************************************************************************/ +#include "adc_callback.h" + +//void Audio_Event(USBADC_Dev *dev); + + +/********************************************************************************************************//** + * @brief Audio Device Class Interface Get Request Callback + * @param[in] dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint8_t ADC_IF_GetRequest (USBADC_Dev *dev) { + + /* + Interface = SetupPacket.wIndex.WB.L; + EntityID = SetupPacket.wIndex.WB.H; + Request = SetupPacket.bRequest; + Value = SetupPacket.wValue.W; + ... + */ + if (dev->usb_enu.SetupPacket.wIndex.W == 0x0200) + { + /* Feature Unit: Interface = 0, ID = 2 */ + if (dev->usb_enu.SetupPacket.wValue.WB.L == 0) + { + /* Master Channel */ + switch (dev->usb_enu.SetupPacket.wValue.WB.H) + { + case AUDIO_FU_MUTE_CONTROL: + switch (dev->usb_enu.SetupPacket.bRequest) + { + case AUDIO_REQUEST_GET_CUR: + dev->usb_enu.EP0Buf[0] = dev->Mute; + return (TRUE); + } + break; + case AUDIO_FU_VOLUME_CONTROL: + switch (dev->usb_enu.SetupPacket.bRequest) + { + case AUDIO_REQUEST_GET_CUR: + *((__attribute__((packed)) uint16_t *)dev->usb_enu.EP0Buf) = dev->VolCur; + return (TRUE); + case AUDIO_REQUEST_GET_MIN: + *((__attribute__((packed)) uint16_t *)dev->usb_enu.EP0Buf) = dev->VolMin; + return (TRUE); + case AUDIO_REQUEST_GET_MAX: + *((__attribute__((packed)) uint16_t *)dev->usb_enu.EP0Buf) = dev->VolMax; + return (TRUE); + case AUDIO_REQUEST_GET_RES: + *((__attribute__((packed)) uint16_t *)dev->usb_enu.EP0Buf) = dev->VolRes; + return (TRUE); + } + break; + } + } + } + + return (FALSE); /* Not Supported */ +} + + +/********************************************************************************************************//** + * @brief Audio Device Class Interface Set Request Callback + * @param[in] dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint8_t ADC_IF_SetRequest (USBADC_Dev *dev) +{ + + /* + Interface = SetupPacket.wIndex.WB.L; + EntityID = SetupPacket.wIndex.WB.H; + Request = SetupPacket.bRequest; + Value = SetupPacket.wValue.W; + ... + */ + if (dev->usb_enu.SetupPacket.wIndex.W == 0x0200) + { + /* Feature Unit: Interface = 0, ID = 2 */ + if (dev->usb_enu.SetupPacket.wValue.WB.L == 0) + { + /* Master Channel */ + switch (dev->usb_enu.SetupPacket.wValue.WB.H) + { + case AUDIO_FU_MUTE_CONTROL: + switch (dev->usb_enu.SetupPacket.bRequest) + { + case AUDIO_REQUEST_SET_CUR: + dev->Mute = dev->usb_enu.EP0Buf[0]; + return (TRUE); + } + break; + case AUDIO_FU_VOLUME_CONTROL: + switch (dev->usb_enu.SetupPacket.bRequest) + { + case AUDIO_REQUEST_SET_CUR: + dev->VolCur = *((__attribute__((packed)) uint16_t *)dev->usb_enu.EP0Buf); + return (TRUE); + } + break; + } + } + } + + return (FALSE); /* Not Supported */ +} + + +/********************************************************************************************************//** + * @brief Audio Device Class EndPoint Get Request Callback + * @param[in] dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint8_t ADC_EP_GetRequest (USBADC_Dev *dev) +{ + + /* + EndPoint = SetupPacket.wIndex.WB.L; + Request = SetupPacket.bRequest; + Value = SetupPacket.wValue.W; + ... + */ + //TODO:Not Supported + return (FALSE); /* Not Supported */ +} + + +/********************************************************************************************************//** + * @brief Audio Device Class EndPoint Set Request Callback + * @param[in] dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint8_t ADC_EP_SetRequest (USBADC_Dev *dev) +{ + + /* + EndPoint = SetupPacket.wIndex.WB.L; + Request = SetupPacket.bRequest; + Value = SetupPacket.wValue.W; + ... + */ + //TODO:Not Supported + return (FALSE); /* Not Supported */ +} + +/********************************************************************************************************//** + * @brief ADC ISO output + * @param[in] dev : a point which contains all the global variables which using in this function + * Event : event type of endpoint + * @return None +************************************************************************************************************/ +void ADC_ISOOut(USBADC_Dev *dev,uint32_t Event) +{ + uint32_t len; + uint8_t wbuf[ADC_EP_MAXPAKET]; + len = dev->usb_enu.usb->USB_ReadEP(ADC_EP_OUT, wbuf); + if(dev->Audio_write != NULL) + { + dev->Audio_write(dev->Audio_device, wbuf, len); + } +} + +/********************************************************************************************************//** + * @brief ADC read,data transfer from host to device + * @param[in] dev : a point which contains all the global variables which using in this function + * wbuf : buffer of read + * len : byte length of read + * @return None +************************************************************************************************************/ +uint32_t Audio_Read (USBADC_Dev *dev, uint8_t *rbuf, uint32_t *len) +{ + //TODO: + *len = dev->usb_enu.usb->USB_ReadEP(ADC_EP_OUT, rbuf); + return *len; +} + +/********************************************************************************************************//** + * @brief ADC write,data transfer from device to host + * @param[in] dev : a point which contains all the global variables which using in this function + * wbuf : buffer of write + * len : byte length of write + * @return None +************************************************************************************************************/ +uint32_t Audio_Write (USBADC_Dev *dev, uint8_t *wbuf, uint32_t len) +{ + //TODO: + uint32_t wlen; + wlen = dev->usb_enu.usb->USB_WriteEP(ADC_EP_OUT, wbuf, len); + return wlen; +} + +/********************************************************************************************************//** + * @brief Initialization of the USB ADC + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +void Audio_Init (USBADC_Dev *dev) +{ + dev->usb_enu.adc_data = dev; + dev->usb_enu.g_pfn_adc_ep_getrequestt = (PFN_ADC_CALLBACK *)ADC_EP_GetRequest; + dev->usb_enu.g_pfn_adc_ep_setrequestt = (PFN_ADC_CALLBACK *)ADC_EP_SetRequest; + dev->usb_enu.g_pfn_adc_if_getrequestt = (PFN_ADC_CALLBACK *)ADC_IF_GetRequest; + dev->usb_enu.g_pfn_adc_if_setrequestt = (PFN_ADC_CALLBACK *)ADC_IF_SetRequest; + + dev->VolCur = 0x0100; + dev->VolMin = 0x0000; + dev->VolMax = 0x0100; + dev->VolRes = 0x0004; + if (dev->Audio_Init != NULL) + { + dev->Audio_Init(dev->Audio_device); + } + + USB_Init(&dev->usb_enu); +} + +/********************************************************************************************************//** + * @brief Connect ADC to the host + * @param[in] dev : a point which contains all the global variables which using in this function + * con : TRUE \FALSE + * @return None +************************************************************************************************************/ +void Audio_Connect(USBADC_Dev *dev,uint32_t con) +{ + dev->usb_enu.usb->USB_Connect(con); +} + +/********************************************************************************************************//** + * @brief Get ADC Configuration statue + * @param[in] dev : a point which contains all the global variables which using in this function + * @return Configuration statue +************************************************************************************************************/ +uint8_t Audio_Configurated(USBADC_Dev *dev) +{ + return dev->usb_enu.USB_Configuration; +} + +/********************************************************************************************************//** + * @brief ADC event callback setup + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +void Audio_Event(USBADC_Dev *dev) +{ + dev->usb_enu.usb->USB_Event((ADC_EP_OUT&0xf),(USB_Event_Handler)ADC_ISOOut,(void *)dev); +} diff --git a/CoX/middleware/USB_CLASS/USB_ADC/adc_callback.h b/CoX/middleware/USB_CLASS/USB_ADC/adc_callback.h new file mode 100644 index 00000000..8fb96c2d --- /dev/null +++ b/CoX/middleware/USB_CLASS/USB_ADC/adc_callback.h @@ -0,0 +1,56 @@ +/***************************************************************************** + * U S B - A D C - C O M P O N E N T + ****************************************************************************/ +/** + * @file : ADC_CALLBACK.h + * @brief : USB Audio Device Class Call Back Definitions + * @version : 1.1 + * @date : 13. Mar. 2011 + * @author : CooCox + ****************************************************************************/ + + +#ifndef __ADC_CALLBACK_H__ +#define __ADC_CALLBACK_H__ + +#include "usb_enumerate.h" + +/*********************************************************************** + * USB ADC call back function definition + **********************************************************************/ +typedef uint32_t (PFN_AUDIO_INIT_CALLBACK) (void *dev); +typedef uint32_t (PFN_AUDIO_READ_CALLBACK) (void *dev, uint8_t *rbuf, uint32_t rlen); +typedef uint32_t (PFN_AUDIO_WRITE_CALLBACK) (void *dev, uint8_t *wbuf, uint32_t wlen); + +/** + * @brief USB ADC Structure + */ +typedef struct +{ + USB_ENU_Dev usb_enu; + PFN_AUDIO_INIT_CALLBACK *Audio_Init; + PFN_AUDIO_READ_CALLBACK *Audio_Read; + PFN_AUDIO_WRITE_CALLBACK *Audio_write; + PFN_AUDIO_INIT_CALLBACK *Audio_DeInit; + + void *Audio_device; + + uint16_t VolCur; /* Volume Current Value */ + uint16_t VolMin; /* Volume Minimum Value */ + uint16_t VolMax; /* Volume Maximum Value */ + uint16_t VolRes; /* Volume Resolution */ + uint8_t Mute; +} USBADC_Dev; + + +/*********************************************************************** + * extern API of this component + **********************************************************************/ +extern uint32_t Audio_Read (USBADC_Dev *dev, uint8_t *rbuf, uint32_t *len); +extern uint32_t Audio_Write (USBADC_Dev *dev, uint8_t *wbuf, uint32_t len); +extern void Audio_Init (USBADC_Dev *dev); +extern void Audio_Connect(USBADC_Dev *dev,uint32_t con); +extern uint8_t Audio_Configurated(USBADC_Dev *dev); +extern void Audio_Event(USBADC_Dev *dev); + +#endif /* __ADC_CALLBACK_H__ */ diff --git a/CoX/middleware/USB_CLASS/USB_ADC/usb_adc_config.h b/CoX/middleware/USB_CLASS/USB_ADC/usb_adc_config.h new file mode 100644 index 00000000..22b6d136 --- /dev/null +++ b/CoX/middleware/USB_CLASS/USB_ADC/usb_adc_config.h @@ -0,0 +1,20 @@ +/***************************************************************************** + * U S B - A D C - C O M P O N E N T + ****************************************************************************/ +/** + * @file : usb_adc_config.h + * @brief : config + * @version : 1.1 + * @date : 13. Mar. 2011 + * @author : CooCox + ****************************************************************************/ +#ifndef __USB_ADC_CONFIG_H__ +#define __USB_ADC_CONFIG_H__ + +/********************************************************************** + * Audio Device In/Out Endpoint Address + **********************************************************************/ +#define ADC_EP_OUT 0x03 +#define ADC_EP_MAXPAKET 0x40 + +#endif /* __USB_ADC_CONFIG_H__ */ diff --git a/CoX/middleware/USB_CLASS/USB_ADC/usb_audio.h b/CoX/middleware/USB_CLASS/USB_ADC/usb_audio.h new file mode 100644 index 00000000..0c602acc --- /dev/null +++ b/CoX/middleware/USB_CLASS/USB_ADC/usb_audio.h @@ -0,0 +1,903 @@ +/***************************************************************************** + * U S B - C D C - C O M P O N E N T + ****************************************************************************/ +/** + * @file : ADC_Audio.h + * @brief : USB Audio Device Class Definitions + * @version : 1.1 + * @date : 13. Mar. 2011 + * @author : CooCox + ****************************************************************************/ + + +#ifndef __USB_AUDIO_H__ +#define __USB_AUDIO_H__ + + +/********************************************************************** + * Audio Interface Class Code in audio20 final.pdf A.1 + **********************************************************************/ +#define AUDIO 0x01 + + +/********************************************************************** + * Audio Function Class Code + **********************************************************************/ +#define AUDIO_FUNCTION AUDIO + + +/********************************************************************** + * Audio Function Subclass Codes + **********************************************************************/ +#define AUDIO_FUNCTION_SUBCLASS_UNDEFINED 0x00 + + +/********************************************************************** + * Audio Function Protocol Codes + **********************************************************************/ +#define AUDIO_FUNCTION_PROTOCOL_UNDEFINED 0x00 +#define AUDIO_AF_VERSION_02_00 0x0200 + +/********************************************************************** + * Audio Interface Subclass Codes + **********************************************************************/ +#define AUDIO_SUBCLASS_UNDEFINED 0x00 +#define AUDIO_SUBCLASS_AUDIOCONTROL 0x01 +#define AUDIO_SUBCLASS_AUDIOSTREAMING 0x02 +#define AUDIO_SUBCLASS_MIDISTREAMING 0x03 + +/********************************************************************** + * Audio Interface Protocol Codes + **********************************************************************/ +#define AUDIO_PROTOCOL_UNDEFINED 0x00 +#define AUDIO_PROTOCOL_IP_VERSION_02_00 0x20 + +/********************************************************************** + * Audio Function Category Codes + **********************************************************************/ +#define AUDIO_FUNCTION_SUBCLASS_UNDEFINED 0x00 +#define AUDIO_FUNCTION_DESKTOP_SPEAKER 0x01 +#define AUDIO_FUNCTION_HOME_THEATER 0x02 +#define AUDIO_FUNCTION_MICROPHONE 0x03 +#define AUDIO_FUNCTION_HEADSET 0x04 +#define AUDIO_FUNCTION_TELEPHONE 0x05 +#define AUDIO_FUNCTION_CONVERTER 0x06 +#define AUDIO_FUNCTION_SOUND_RECORDER 0x07 +#define AUDIO_FUNCTION_IO_BOX 0x08 +#define AUDIO_FUNCTION_MUSICAL_INSTRUMENT 0x09 +#define AUDIO_FUNCTION_PRO_AUDIO 0x0A +#define AUDIO_FUNCTION_AUDIO_VIDEO 0x0B +#define AUDIO_FUNCTION_CONTROL_PANEL 0x0C +#define AUDIO_FUNCTION_OTHER 0xFF + +/********************************************************************** + * Audio Class-Specific Descriptor Types + **********************************************************************/ +#define AUDIO_UNDEFINED_DESCRIPTOR_TYPE 0x20 +#define AUDIO_DEVICE_DESCRIPTOR_TYPE 0x21 +#define AUDIO_CONFIGURATION_DESCRIPTOR_TYPE 0x22 +#define AUDIO_STRING_DESCRIPTOR_TYPE 0x23 +#define AUDIO_INTERFACE_DESCRIPTOR_TYPE 0x24 +#define AUDIO_ENDPOINT_DESCRIPTOR_TYPE 0x25 + + +/********************************************************************** + * Audio Class-Specific AC Interface Descriptor Subtypes + **********************************************************************/ +#define AUDIO_CONTROL_UNDEFINED 0x00 +#define AUDIO_CONTROL_HEADER 0x01 +#define AUDIO_CONTROL_INPUT_TERMINAL 0x02 +#define AUDIO_CONTROL_OUTPUT_TERMINAL 0x03 +#define AUDIO_CONTROL_MIXER_UNIT 0x04 +#define AUDIO_CONTROL_SELECTOR_UNIT 0x05 +#define AUDIO_CONTROL_FEATURE_UNIT 0x06 +#define AUDIO_CONTROL_EFFECT_UNIT 0x07 +#define AUDIO_CONTROL_PROCESSING_UNIT 0x08 +#define AUDIO_CONTROL_EXTENSION_UNIT 0x09 +#define AUDIO_CONTROL_CLOCK_SOURCE 0x0A +#define AUDIO_CONTROL_CLOCK_SELECTOR 0x0B +#define AUDIO_CONTROL_CLOCK_MULTIPLIER 0x0C +#define AUDIO_CONTROL_SAMPLE_RATE_CONVERTER 0x0D + +/********************************************************************** + * Audio Class-Specific AS Interface Descriptor Subtypes + **********************************************************************/ +#define AUDIO_STREAMING_UNDEFINED 0x00 +#define AUDIO_STREAMING_GENERAL 0x01 +#define AUDIO_STREAMING_FORMAT_TYPE 0x02 +#define AUDIO_STREAMING_FORMAT_SPECIFIC 0x03 +#define AUDIO_STREAMING_FORMAT_DECODER 0x04 + +/********************************************************************** + * Effect Unit Effect Types + **********************************************************************/ +#define AUDIO_EFFECT_UNDEFINED 0x00 +#define AUDIO_EFFECT_PARAM_EQ_SECTION_EFFECT 0x01 +#define AUDIO_EFFECT_REVERBERATION_EFFECT 0x02 +#define AUDIO_EFFECT_MOD_DELAY_EFFECT 0x03 +#define AUDIO_EFFECT_DYN_RANGE_COMP_EFFECT 0x04 + +/********************************************************************** + * Processing Unit Process Types + **********************************************************************/ +#define AUDIO_PROCESS_UNDEFINED 0x00 +#define AUDIO_PROCESS_UP_DOWNMIX_PROCESS 0x01 +#define AUDIO_PROCESS_DOLBY_PROLOGIC_PROCESS 0x02 +#define AUDIO_PROCESS_STEREO_EXTENDER_PROCESS 0x03 + +/********************************************************************** + * Audio Class-Specific Endpoint Descriptor Subtypes + **********************************************************************/ +#define AUDIO_ENDPOINT_UNDEFINED 0x00 +#define AUDIO_ENDPOINT_GENERAL 0x01 + + +/* Audio Descriptor Sizes */ +//Table 4-1: Audio Channel Cluster Descriptor 6 +//Table 4-1: Dolby Prologic Cluster Descriptor 6 +//Table 4-2: Left Group Cluster Descriptor 6 +//Table 4-3: Standard Interface Association Descriptor 8 +//Table 4-4: Standard AC Interface Descriptor 9 +//Table 4-5: Class-Specific AC Interface Header Descriptor 9 +//Table 4-6: Clock Source Descriptor 8 +//Table 4-7: Clock Selector Descriptor 7+p +//Table 4-8: Clock Multiplier Descriptor 7 +//Table 4-9: Input Terminal Descriptor 17 +//Table 4-10: Output Terminal Descriptor 12 +//Table 4-11: Mixer Unit Descriptor 13+p+n +//Table 4-12: Selector Unit Descriptor 7+p +//Table 4-13: Feature Unit Descriptor 6+(ch+1)*4 +//Table 4-14: Sampling Rate Converter Unit Descriptor 8 +//Table 4-15: Common Part of the Effect Unit Descriptor 16+(ch*4) +//Table 4-16: Parametric Equalizer Section Effect Unit Descriptor 16+(ch*4) +//Table 4-17: Reverberation Effect Unit Descriptor 16+(ch*4) +//Table 4-18: Modulation Delay Effect Unit Descriptor 16+(ch*4) +//Table 4-19: Dynamic Range Compressor Effect Unit Descriptor 16+(ch*4) +//Table 4-20: Common Part of the Processing Unit Descriptor 17+p+x +//Table 4-21: Up/Down-mix Processing Unit Descriptor 18+4*m +//Table 4-22: Dolby Prologic Processing Unit Descriptor 18+4*m +//Table 4-23: Stereo Extender Processing Unit Descriptor 17 +//Table 4-24: Extension Unit Descriptor 16+p +//Table 4-25: Standard AC Interrupt Endpoint Descriptor 7 +//Table 4-26: Standard AS Interface Descriptor 9 +//Table 4-27: Class-Specific AS Interface Descriptor 16 +//Table 4-28: Encoder Descriptor 21 +//Table 4-29: MPEG Decoder Descriptor 10 +//Table 4-30: AC-3 Decoder Descriptor 12 +//Table 4-31: WMA Decoder Descriptor 9 +//Table 4-32: DTS Decoder Descriptor 8 +//Table 4-33: Standard AS Isochronous Audio Data Endpoint Descriptor 7 +//Table 4-34: Class-Specific AS Isochronous Audio Data Endpoint Descriptor 8 +//Table 4-35: Standard AS Isochronous Feedback Endpoint Descriptor 7 + +#define AUDIO_CONTROL_INTERFACE_DESC_SZ(n) 0x08+n +#define AUDIO_STREAMING_INTERFACE_DESC_SIZE 0x07 +#define AUDIO_INPUT_TERMINAL_DESC_SIZE 0x0C +#define AUDIO_OUTPUT_TERMINAL_DESC_SIZE 0x09 +#define AUDIO_MIXER_UNIT_DESC_SZ(p,n) 0x0A+p+n +#define AUDIO_SELECTOR_UNIT_DESC_SZ(p) 0x06+p +#define AUDIO_FEATURE_UNIT_DESC_SZ(ch,n) 0x07+(ch+1)*n +#define AUDIO_PROCESSING_UNIT_DESC_SZ(p,n,x) 0x0D+p+n+x +#define AUDIO_EXTENSION_UNIT_DESC_SZ(p,n) 0x0D+p+n +#define AUDIO_STANDARD_ENDPOINT_DESC_SIZE 0x09 +#define AUDIO_STREAMING_ENDPOINT_DESC_SIZE 0x07 + + +/* Audio Processing Unit Process Types */ +/*#define AUDIO_UNDEFINED_PROCESS 0x00 +#define AUDIO_UP_DOWN_MIX_PROCESS 0x01 +#define AUDIO_DOLBY_PROLOGIC_PROCESS 0x02 +#define AUDIO_3D_STEREO_PROCESS 0x03 +#define AUDIO_REVERBERATION_PROCESS 0x04 +#define AUDIO_CHORUS_PROCESS 0x05 +#define AUDIO_DYN_RANGE_COMP_PROCESS 0x06*/ + + +/********************************************************************** + * Audio Request Codes + **********************************************************************/ +#define AUDIO_REQUEST_UNDEFINED 0x00 +#define AUDIO_REQUEST_CUR 0x01 +#define AUDIO_REQUEST_RANGE 0x02 +#define AUDIO_REQUEST_MEM 0x03 + +#define AUDIO_REQUEST_UNDEFINED 0x00 +#define AUDIO_REQUEST_SET_CUR 0x01 +#define AUDIO_REQUEST_GET_CUR 0x81 +#define AUDIO_REQUEST_SET_MIN 0x02 +#define AUDIO_REQUEST_GET_MIN 0x82 +#define AUDIO_REQUEST_SET_MAX 0x03 +#define AUDIO_REQUEST_GET_MAX 0x83 +#define AUDIO_REQUEST_SET_RES 0x04 +#define AUDIO_REQUEST_GET_RES 0x84 +#define AUDIO_REQUEST_SET_MEM 0x05 +#define AUDIO_REQUEST_GET_MEM 0x85 +#define AUDIO_REQUEST_GET_STAT 0xFF + +/********************************************************************** + * Encoder Type Codes + **********************************************************************/ +#define AUDIO_ENCODER_UNDEFINED 0x00 +#define AUDIO_OTHER_ENCODER 0x01 +#define AUDIO_MPEG_ENCODER 0x02 +#define AUDIO_AC_3_ENCODER 0x03 +#define AUDIO_WMA_ENCODER 0x04 +#define AUDIO_DTS_ENCODER 0x05 + +/********************************************************************** + * Decoder Type Codes in audio20 final.pdf A.16 + **********************************************************************/ +#define AUDIO_DECODER_UNDEFINED 0x00 +#define AUDIO_OTHER_DECODER 0x01 +#define AUDIO_MPEG_DECODER 0x02 +#define AUDIO_AC_3_DECODER 0x03 +#define AUDIO_WMA_DECODER 0x04 +#define AUDIO_DTS_DECODER 0x05 + +/********************************************************************** + * Audio Control Selector Codes in audio20 final.pdf A.17 + **********************************************************************/ +#define AUDIO_CONTROL_UNDEFINED 0x00 /* Common Selector */ + +/********************************************************************** + * Clock Source Control Selectors Codes in audio20 final.pdf A.17.1 + **********************************************************************/ +#define AUDIO_CS_CONTROL_UNDEFINED 0x00 /* Common Selector */ +#define AUDIO_CS_SAM_FREQ_CONTROL 0x01 +#define AUDIO_CS_CLOCK_VALID_CONTROL 0x02 + + +/********************************************************************** + * Clock Selector Control Selectors Codes in audio20 final.pdf A.17.2 + **********************************************************************/ +#define AUDIO_CX_CONTROL_UNDEFINED 0x00 /* Common Selector */ +#define AUDIO_CX_CLOCK_SELECTOR_CONTROL 0x01 + + +/********************************************************************** + * Clock Multiplier Control Selectors Codes in audio20 final.pdf A.17.3 + **********************************************************************/ +#define AUDIO_CM_CONTROL_UNDEFINED 0x00 /* Common Selector */ +#define AUDIO_CM_NUMERATOR_CONTROL 0x01 +#define AUDIO_CM_DENOMINATOR_CONTROL 0x02 + +/********************************************************************** + * Terminal Control Selectors Codes in audio20 final.pdf A.17.4 + **********************************************************************/ +#define AUDIO_TE_CONTROL_UNDEFINED 0x00 +#define AUDIO_TE_COPY_PROTECT_CONTROL 0x01 +#define AUDIO_TE_CONNECTOR_CONTROL 0x02 +#define AUDIO_TE_OVERLOAD_CONTROL 0x03 +#define AUDIO_TE_CLUSTER_CONTROL 0x04 +#define AUDIO_TE_UNDERFLOW_CONTROL 0x05 +#define AUDIO_TE_OVERFLOW_CONTROL 0x06 +#define AUDIO_TE_LATENCY_CONTROL 0x07 + +/********************************************************************** + * Mixer Control Selectors Codes in audio20 final.pdf A.17.5 + **********************************************************************/ +#define AUDIO_MU_CONTROL_UNDEFINED 0x00 +#define AUDIO_MU_MIXER_CONTROL 0x01 +#define AUDIO_MU_CLUSTER_CONTROL 0x02 +#define AUDIO_MU_UNDERFLOW_CONTROL 0x03 +#define AUDIO_MU_OVERFLOW_CONTROL 0x04 +#define AUDIO_MU_LATENCY_CONTROL 0x05 + + +/********************************************************************** + * Selector Control Selectors Codes in audio20 final.pdf A.17.6 + **********************************************************************/ +#define AUDIO_SU_CONTROL_UNDEFINED 0x00 +#define AUDIO_SU_SELECTOR_CONTROL 0x01 +#define AUDIO_SU_LATENCY_CONTROL 0x02 + +/********************************************************************** + * Feature Unit Control Selectors Codes in audio20 final.pdf A.17.7 + **********************************************************************/ +#define AUDIO_FU_CONTROL_UNDEFINED 0x00 +#define AUDIO_FU_MUTE_CONTROL 0x01 +#define AUDIO_FU_VOLUME_CONTROL 0x02 +#define AUDIO_FU_BASS_CONTROL 0x03 +#define AUDIO_FU_MID_CONTROL 0x04 +#define AUDIO_FU_TREBLE_CONTROL 0x05 +#define AUDIO_FU_GRAPHIC_EQUALIZER_CONTROL 0x06 +#define AUDIO_FU_AUTOMATIC_GAIN_CONTROL 0x07 +#define AUDIO_FU_DELAY_CONTROL 0x08 +#define AUDIO_FU_BASS_BOOST_CONTROL 0x09 +#define AUDIO_FU_LOUDNESS_CONTROL 0x0A +#define AUDIO_FU_INPUT_GAIN_CONTROL 0x0B +#define AUDIO_FU_INPUT_GAIN_PAD_CONTROL 0x0C +#define AUDIO_FU_PHASE_INVERTER_CONTROL 0x0D +#define AUDIO_FU_UNDERFLOW_CONTROL 0x0E +#define AUDIO_FU_OVERFLOW_CONTROL 0x0F +#define AUDIO_FU_LATENCY_CONTROL 0x10 + +/* Effect Unit Control Selectors Codes in audio20 final.pdf A.17.8*/ + +/********************************************************************** + * Parametric Equalizer Section Effect Unit Control Selectors Codes + * in audio20 final.pdf A.17.8.1 + **********************************************************************/ +#define AUDIO_PE_CONTROL_UNDEFINED 0x00 +#define AUDIO_PE_ENABLE_CONTROL 0x01 +#define AUDIO_PE_CENTERFREQ_CONTROL 0x02 +#define AUDIO_PE_QFACTOR_CONTROL 0x03 +#define AUDIO_PE_GAIN_CONTROL 0x04 +#define AUDIO_PE_UNDERFLOW_CONTROL 0x05 +#define AUDIO_PE_OVERFLOW_CONTROL 0x06 +#define AUDIO_PE_LATENCY_CONTROL 0x07 + +/********************************************************************** + * Reverberation Effect Unit Control Selectors Codes in + * audio20 final.pdf A.17.8.2 + **********************************************************************/ +#define AUDIO_RV_CONTROL_UNDEFINED 0x00 +#define AUDIO_RV_ENABLE_CONTROL 0x01 +#define AUDIO_RV_TYPE_CONTROL 0x02 +#define AUDIO_RV_LEVEL_CONTROL 0x03 +#define AUDIO_RV_TIME_CONTROL 0x04 +#define AUDIO_RV_FEEDBACK_CONTROL 0x05 +#define AUDIO_RV_PREDELAY_CONTROL 0x06 +#define AUDIO_RV_DENSITY_CONTROL 0x07 +#define AUDIO_RV_HIFREQ_ROLLOFF_CONTROL 0x08 +#define AUDIO_RV_UNDERFLOW_CONTROL 0x09 +#define AUDIO_RV_OVERFLOW_CONTROL 0x0A +#define AUDIO_RV_LATENCY_CONTROL 0x0B + + +/********************************************************************** + * Modulation Delay Effect Unit Control Selectors Codes in + * audio20 final.pdf A.17.8.3 + **********************************************************************/ +#define AUDIO_MD_CONTROL_UNDEFINED 0x00 +#define AUDIO_MD_ENABLE_CONTROL 0x01 +#define AUDIO_MD_BALANCE_CONTROL 0x02 +#define AUDIO_MD_RATE_CONTROL 0x03 +#define AUDIO_MD_DEPTH_CONTROL 0x04 +#define AUDIO_MD_TIME_CONTROL 0x05 +#define AUDIO_MD_FEEDBACK_CONTROL 0x06 +#define AUDIO_MD_UNDERFLOW_CONTROL 0x07 +#define AUDIO_MD_OVERFLOW_CONTROL 0x08 +#define AUDIO_MD_LATENCY_CONTROL 0x09 + + +/********************************************************************** + * Dynamic Range Compressor Effect Unit Control Selectors Codes in + * audio20 final.pdf A.17.8.4 + **********************************************************************/ +#define AUDIO_DR_CONTROL_UNDEFINED 0x00 +#define AUDIO_DR_ENABLE_CONTROL 0x01 +#define AUDIO_DR_COMPRESSION_RATE_CONTROL 0x02 +#define AUDIO_DR_MAXAMPL_CONTROL 0x03 +#define AUDIO_DR_THRESHOLD_CONTROL 0x04 +#define AUDIO_DR_ATTACK_TIME_CONTROL 0x05 +#define AUDIO_DR_RELEASE_TIME_CONTROL 0x06 +#define AUDIO_DR_UNDERFLOW_CONTROL 0x07 +#define AUDIO_DR_OVERFLOW_CONTROL 0x08 +#define AUDIO_DR_LATENCY_CONTROL 0x09 + + +/* Processing Unit Control Selectors Codes in audio20 final.pdf A.17.9 */ + +/********************************************************************** + * Up/Down-mix Processing Unit Control Selectors Codes in + * audio20 final.pdf A.17.9.1 + **********************************************************************/ +#define AUDIO_UD_CONTROL_UNDEFINED 0x00 +#define AUDIO_UD_ENABLE_CONTROL 0x01 +#define AUDIO_UD_MODE_SELECT_CONTROL 0x02 +#define AUDIO_UD_CLUSTER_CONTROL 0x03 +#define AUDIO_UD_UNDERFLOW_CONTROL 0x04 +#define AUDIO_UD_OVERFLOW_CONTROL 0x05 +#define AUDIO_UD_LATENCY_CONTROL 0x06 + + +/********************************************************************** + * Dolby Prologic Processing Unit Control Selectors Codes in + * audio20 final.pdf A.17.9.2 + **********************************************************************/ +#define AUDIO_DP_CONTROL_UNDEFINED 0x00 +#define AUDIO_DP_ENABLE_CONTROL 0x01 +#define AUDIO_DP_MODE_SELECT_CONTROL 0x02 +#define AUDIO_DP_CLUSTER_CONTROL 0x03 +#define AUDIO_DP_UNDERFLOW_CONTROL 0x04 +#define AUDIO_DP_OVERFLOW_CONTROL 0x05 +#define AUDIO_DP_LATENCY_CONTROL 0x06 + + +/********************************************************************** + * Stereo Extender Processing Unit Control Selectors Codes in + * audio20 final.pdf A.17.9.3 + **********************************************************************/ +#define AUDIO_ST_EXT_CONTROL_UNDEFINED 0x00 +#define AUDIO_ST_EXT_ENABLE_CONTROL 0x01 +#define AUDIO_ST_EXT_WIDTH_CONTROL 0x02 +#define AUDIO_ST_EXT_UNDERFLOW_CONTROL 0x03 +#define AUDIO_ST_EXT_OVERFLOW_CONTROL 0x04 +#define AUDIO_ST_EXT_LATENCY_CONTROL 0x05 + + +/********************************************************************** + * Extension Unit Control Selectors Codes in audio20 final.pdf A.17.10 + **********************************************************************/ +#define AUDIO_XU_CONTROL_UNDEFINED 0x00 +#define AUDIO_XU_ENABLE_CONTROL 0x01 +#define AUDIO_XU_CLUSTER_CONTROL 0x02 +#define AUDIO_XU_UNDERFLOW_CONTROL 0x03 +#define AUDIO_XU_OVERFLOW_CONTROL 0x04 +#define AUDIO_XU_LATENCY_CONTROL 0x05 + + +/********************************************************************** + * AudioStreaming Interface Control Selectors Codes in + * audio20 final.pdf A.17.11 + **********************************************************************/ +#define AUDIO_AS_CONTROL_UNDEFINED 0x00 +#define AUDIO_AS_ACT_ALT_SETTING_CONTROL 0x01 +#define AUDIO_AS_VAL_ALT_SETTINGS_CONTROL 0x02 +#define AUDIO_AS_AUDIO_DATA_FORMAT_CONTROL 0x03 + +/********************************************************************** + * Encoder Control Selectors Codes in audio20 final.pdf A.17.12 + **********************************************************************/ +#define AUDIO_EN_CONTROL_UNDEFINED 0x00 +#define AUDIO_EN_BIT_RATE_CONTROL 0x01 +#define AUDIO_EN_QUALITY_CONTROL 0x02 +#define AUDIO_EN_VBR_CONTROL 0x03 +#define AUDIO_EN_TYPE_CONTROL 0x04 +#define AUDIO_EN_UNDERFLOW_CONTROL 0x05 +#define AUDIO_EN_OVERFLOW_CONTROL 0x06 +#define AUDIO_EN_ENCODER_ERROR_CONTROL 0x07 +#define AUDIO_EN_PARAM1_CONTROL 0x08 +#define AUDIO_EN_PARAM2_CONTROL 0x09 +#define AUDIO_EN_PARAM3_CONTROL 0x0A +#define AUDIO_EN_PARAM4_CONTROL 0x0B +#define AUDIO_EN_PARAM5_CONTROL 0x0C +#define AUDIO_EN_PARAM6_CONTROL 0x0D +#define AUDIO_EN_PARAM7_CONTROL 0x0E +#define AUDIO_EN_PARAM8_CONTROL 0x0F + +/* Decoder Control Selectors Codes in audio20 final.pdf A.17.13 */ + +/********************************************************************** + * MPEG Decoder Control Selectors Codes in audio20 final.pdf A.17.13.1 + **********************************************************************/ +#define AUDIO_MD_CONTROL_UNDEFINED 0x00 +#define AUDIO_MD_DUAL_CHANNEL_CONTROL 0x01 +#define AUDIO_MD_SECOND_STEREO_CONTROL 0x02 +#define AUDIO_MD_MULTILINGUAL_CONTROL 0x03 +#define AUDIO_MD_DYN_RANGE_CONTROL 0x04 +#define AUDIO_MD_SCALING_CONTROL 0x05 +#define AUDIO_MD_HILO_SCALING_CONTROL 0x06 +#define AUDIO_MD_UNDERFLOW_CONTROL 0x07 +#define AUDIO_MD_OVERFLOW_CONTROL 0x08 +#define AUDIO_MD_DECODER_ERROR_CONTROL 0x09 + +/********************************************************************** + * AC-3 Decoder Control Selectors Codes in audio20 final.pdf A.17.13.2 + **********************************************************************/ +#define AUDIO_AD_CONTROL_UNDEFINED 0x00 +#define AUDIO_AD_MODE_CONTROL 0x01 +#define AUDIO_AD_DYN_RANGE_CONTROL 0x02 +#define AUDIO_AD_SCALING_CONTROL 0x03 +#define AUDIO_AD_HILO_SCALING_CONTROL 0x04 +#define AUDIO_AD_UNDERFLOW_CONTROL 0x05 +#define AUDIO_AD_OVERFLOW_CONTROL 0x06 +#define AUDIO_AD_DECODER_ERROR_CONTROL 0x07 + +/********************************************************************** + * WMA Decoder Control Selectors Codes in audio20 final.pdf A.17.13.3 + **********************************************************************/ +#define AUDIO_WD_CONTROL_UNDEFINED 0x00 +#define AUDIO_WD_UNDERFLOW_CONTROL 0x01 +#define AUDIO_WD_OVERFLOW_CONTROL 0x02 +#define AUDIO_WD_DECODER_ERROR_CONTROL 0x03 + +/********************************************************************** + * DTS Decoder Control Selectors Codes in audio20 final.pdf A.17.13.4 + **********************************************************************/ +#define AUDIO_DD_CONTROL_UNDEFINED 0x00 +#define AUDIO_DD_UNDERFLOW_CONTROL 0x01 +#define AUDIO_DD_OVERFLOW_CONTROL 0x02 +#define AUDIO_DD_DECODER_ERROR_CONTROL 0x03 + + +/********************************************************************** + * Endpoint Control Selectors Codes in audio20 final.pdf A.17.14 + **********************************************************************/ +#define AUDIO_EP_CONTROL_UNDEFINED 0x00 +#define AUDIO_EP_PITCH_CONTROL 0x01 +#define AUDIO_EP_DATA_OVERRUN_CONTROL 0x02 +#define AUDIO_EP_DATA_UNDERRUN_CONTROL 0x03 + + + +#define AUDIO_ENABLE_CONTROL 0x01 /* Common Selector */ +#define AUDIO_MODE_SELECT_CONTROL 0x02 /* Common Selector */ + +/* - Up/Down-mix Control Selectors */ +/* AUDIO_ENABLE_CONTROL 0x01 Common Selector */ +/* AUDIO_MODE_SELECT_CONTROL 0x02 Common Selector */ + +/* - Dolby Prologic Control Selectors */ +/* AUDIO_ENABLE_CONTROL 0x01 Common Selector */ +/* AUDIO_MODE_SELECT_CONTROL 0x02 Common Selector */ + +/* - 3D Stereo Extender Control Selectors */ +/* AUDIO_ENABLE_CONTROL 0x01 Common Selector */ +#define AUDIO_SPACIOUSNESS_CONTROL 0x02 + +/********************************************************************** + * Reverberation Control Selectors + **********************************************************************/ +/* AUDIO_ENABLE_CONTROL 0x01 Common Selector */ +#define AUDIO_REVERB_LEVEL_CONTROL 0x02 +#define AUDIO_REVERB_TIME_CONTROL 0x03 +#define AUDIO_REVERB_FEEDBACK_CONTROL 0x04 + +/********************************************************************** + * Chorus Control Selectors + **********************************************************************/ +/* AUDIO_ENABLE_CONTROL 0x01 Common Selector */ +#define AUDIO_CHORUS_LEVEL_CONTROL 0x02 +#define AUDIO_SHORUS_RATE_CONTROL 0x03 +#define AUDIO_CHORUS_DEPTH_CONTROL 0x04 + +/********************************************************************** + * Dynamic Range Compressor Control Selectors + **********************************************************************/ +/* AUDIO_ENABLE_CONTROL 0x01 Common Selector */ +#define AUDIO_COMPRESSION_RATE_CONTROL 0x02 +#define AUDIO_MAX_AMPL_CONTROL 0x03 +#define AUDIO_THRESHOLD_CONTROL 0x04 +#define AUDIO_ATTACK_TIME_CONTROL 0x05 +#define AUDIO_RELEASE_TIME_CONTROL 0x06 + +/********************************************************************** + * Extension Unit Control Selectors + **********************************************************************/ +/* AUDIO_ENABLE_CONTROL 0x01 Common Selector */ + + +/********************************************************************** + * Endpoint Control Selectors + **********************************************************************/ +#define AUDIO_SAMPLING_FREQ_CONTROL 0x01 +#define AUDIO_PITCH_CONTROL 0x02 + + +/* Audio Format Specific Control Selectors */ + +/********************************************************************** + * MPEG Control Selectors + **********************************************************************/ +#define AUDIO_MPEG_CONTROL_UNDEFINED 0x00 +#define AUDIO_MPEG_DUAL_CHANNEL_CONTROL 0x01 +#define AUDIO_MPEG_SECOND_STEREO_CONTROL 0x02 +#define AUDIO_MPEG_MULTILINGUAL_CONTROL 0x03 +#define AUDIO_MPEG_DYN_RANGE_CONTROL 0x04 +#define AUDIO_MPEG_SCALING_CONTROL 0x05 +#define AUDIO_MPEG_HILO_SCALING_CONTROL 0x06 + + +/********************************************************************** + * AC-3 Control Selectors + **********************************************************************/ +#define AUDIO_AC3_CONTROL_UNDEFINED 0x00 +#define AUDIO_AC3_MODE_CONTROL 0x01 +#define AUDIO_AC3_DYN_RANGE_CONTROL 0x02 +#define AUDIO_AC3_SCALING_CONTROL 0x03 +#define AUDIO_AC3_HILO_SCALING_CONTROL 0x04 + + +/********************************************************************** + * Audio Format Type Descriptor Sizes + **********************************************************************/ +#define AUDIO_FORMAT_TYPE_I_DESC_SZ(n) 0x08+(n*3) +#define AUDIO_FORMAT_TYPE_II_DESC_SZ(n) 0x09+(n*3) +#define AUDIO_FORMAT_TYPE_III_DESC_SZ(n) 0x08+(n*3) +#define AUDIO_FORMAT_MPEG_DESC_SIZE 0x09 +#define AUDIO_FORMAT_AC3_DESC_SIZE 0x0A + + +/* Audio Data Format Codes */ + +/********************************************************************** + * Audio Format Types in Frmts20 final.pdf Appendix A A.1: + **********************************************************************/ +#define AUDIO_FORMAT_TYPE_UNDEFINED 0x00 +#define AUDIO_FORMAT_TYPE_I 0x01 +#define AUDIO_FORMAT_TYPE_II 0x02 +#define AUDIO_FORMAT_TYPE_III 0x03 +#define AUDIO_EXT_FORMAT_TYPE_I 0x81 +#define AUDIO_EXT_FORMAT_TYPE_II 0x82 +#define AUDIO_EXT_FORMAT_TYPE_III 0x83 + + +/********************************************************************** + * Audio Data Format Type I Bit Allocations in + * Frmts20 final.pdf Appendix A A.2.1: + **********************************************************************/ +#define AUDIO_FORMAT_TYPE_I_UNDEFINED 0x00000000 +#define AUDIO_FORMAT_PCM 0x00000001 +#define AUDIO_FORMAT_PCM8 0x00000002 +#define AUDIO_FORMAT_IEEE_FLOAT 0x00000004 +#define AUDIO_FORMAT_ALAW 0x00000008 +#define AUDIO_FORMAT_MULAW 0x00000010 +#define AUDIO_FORMAT_TYPE_I_RAW_DATA 0x80000000 + + +/********************************************************************** + * Audio Data Format Type II Bit Allocations in + * Frmts20 final.pdf Appendix A A.2.2: + **********************************************************************/ +//THERE IS SOME DEFFIRENT WITH THE KEIL RL +#define AUDIO_FORMAT_TYPE_II_UNDEFINED 0x00000000 +#define AUDIO_FORMAT_MPEG 0x00000001 +#define AUDIO_FORMAT_AC3 0x00000002 +#define AUDIO_FORMAT_WMA 0x00000004 +#define AUDIO_FORMAT_DTS 0x00000008 +#define AUDIO_FORMAT_TYPE_I_RAW_DATA 0x80000000 + + +/********************************************************************** + * Audio Data Format Type III Bit Allocations in + * Frmts20 final.pdf Appendix A A.2.3: + **********************************************************************/ +#define AUDIO_FORMAT_TYPE_III_UNDEFINED 0x00000000 +#define AUDIO_FORMAT_IEC1937_AC3 0x00000001 +#define AUDIO_FORMAT_IEC1937_MPEG1_L1 0x00000002 +#define AUDIO_FORMAT_IEC1937_MPEG1_L2_3_NOEXT 0x00000004 +#define AUDIO_FORMAT_IEC1937_MPEG2_EXT 0x00000008 +#define AUDIO_FORMAT_IEC1937_MPEG2_AAC_ADTS 0x00000010 +#define AUDIO_FORMAT_IEC1937_MPEG2_L1_LS 0x00000020 +#define AUDIO_FORMAT_IEC1937_MPEG2_L2_3 0x00000080 +#define AUDIO_FORMAT_IEC1937_DTS_I 0x00000100 +#define AUDIO_FORMAT_IEC1937_DTS_II 0x00000200 +#define AUDIO_FORMAT_IEC1937_DTS_III 0x00000400 +#define AUDIO_FORMAT_IEC1937_ATRAC 0x00000800 +#define AUDIO_FORMAT_IEC1937_ATRAC2_3 0x00001000 +#define AUDIO_FORMAT_TYPE_III_WMA 0x00002000 + +/********************************************************************** + * Audio Data Format Type IV Bit Allocations in + * Frmts20 final.pdf Appendix A A.2.4: + **********************************************************************/ +#define AUDIO_FORMAT_TYPE_III_UNDEFINED 0x00000000 +#define AUDIO_FORMAT_PCM 0x00000001 +#define AUDIO_FORMAT_PCM8 0x00000002 +#define AUDIO_FORMAT_IEEE_FLOAT 0x00000004 +#define AUDIO_FORMAT_ALAW 0x00000008 +#define AUDIO_FORMAT_MULAW 0x00000010 +#define AUDIO_FORMAT_MPEG_IV 0x00000020 +#define AUDIO_FORMAT_AC_3 0x00000080 +#define AUDIO_FORMAT_WMA_IV 0x00000100 +#define AUDIO_FORMAT_IEC61937_AC_3 0x00000200 +#define AUDIO_FORMAT_IEC61937_MPEG1_L1 0x00000400 +#define AUDIO_FORMAT_IEC61937_MPEG1_L23_NOEX 0x00000800 +#define AUDIO_FORMAT_IEC61937_MPEG2_EXT 0x00001000 +#define AUDIO_FORMAT_IEC61937_MPEG_2_AAC_ADTS 0x00002000 +#define AUDIO_FORMAT_IEC61937_MPEG_2_L1_LS 0x00004000 +#define AUDIO_FORMAT_IEC61937_MPEG_2_L23_LS 0x00008000 +#define AUDIO_FORMAT_IEC61937_DTS_I 0x00010000 +#define AUDIO_FORMAT_IEC61937_DTS_II 0x00020000 +#define AUDIO_FORMAT_IEC61937_DTS_III 0x00040000 +#define AUDIO_FORMAT_IEC61937_ATRAC 0x00080000 +#define AUDIO_FORMAT_IEC61937_ATRAC23 0x00100000 +#define AUDIO_FORMAT_TYPE_III_WMA_IV 0x00200000 +#define AUDIO_FORMAT_IEC60958_PCM 0x00400000 + +/********************************************************************** + * Predefined Audio Channel Configuration Bits In Audio2.0 final.pdf 4.1 + **********************************************************************/ +#define AUDIO_CHANNEL_M 0x00000000 /* Mono */ +#define AUDIO_CHANNEL_L 0x00000001 /* Left Front */ +#define AUDIO_CHANNEL_R 0x00000002 /* Right Front */ +#define AUDIO_CHANNEL_C 0x00000004 /* Center Front */ +#define AUDIO_CHANNEL_LFE 0x00000008 /* Low Freq. Enhance. */ +#define AUDIO_CHANNEL_LS 0x00000010 /* Left Surround */ +#define AUDIO_CHANNEL_RS 0x00000020 /* Right Surround */ +#define AUDIO_CHANNEL_LC 0x00000040 /* Left of Center */ +#define AUDIO_CHANNEL_RC 0x00000080 /* Right of Center */ +#define AUDIO_CHANNEL_S 0x00000100 /* Surround */ +#define AUDIO_CHANNEL_SL 0x00000200 /* Side Left */ +#define AUDIO_CHANNEL_SR 0x00000400 /* Side Right */ +#define AUDIO_CHANNEL_TC 0x00000800 /* Top */ +#define AUDIO_CHANNEL_TFL 0x00001000 +#define AUDIO_CHANNEL_TFC 0x00002000 +#define AUDIO_CHANNEL_TFR 0x00004000 +#define AUDIO_CHANNEL_TBL 0x00008000 +#define AUDIO_CHANNEL_TBC 0x00010000 +#define AUDIO_CHANNEL_TBR 0x00020000 +#define AUDIO_CHANNEL_TFLC 0x00040000 +#define AUDIO_CHANNEL_TFRC 0x00080000 +#define AUDIO_CHANNEL_LLFE 0x00100000 +#define AUDIO_CHANNEL_RLFE 0x00200000 +#define AUDIO_CHANNEL_TSL 0x00400000 +#define AUDIO_CHANNEL_TSR 0x00800000 +#define AUDIO_CHANNEL_BC 0x01000000 +#define AUDIO_CHANNEL_BLC 0x02000000 +#define AUDIO_CHANNEL_BRC 0x04000000 + + +/********************************************************************** + * Feature Unit Control Bits + **********************************************************************/ +#define AUDIO_CONTROL_MUTE 0x0001 +#define AUDIO_CONTROL_VOLUME 0x0002 +#define AUDIO_CONTROL_BASS 0x0004 +#define AUDIO_CONTROL_MID 0x0008 +#define AUDIO_CONTROL_TREBLE 0x0010 +#define AUDIO_CONTROL_GRAPHIC_EQUALIZER 0x0020 +#define AUDIO_CONTROL_AUTOMATIC_GAIN 0x0040 +#define AUDIO_CONTROL_DEALY 0x0080 +#define AUDIO_CONTROL_BASS_BOOST 0x0100 +#define AUDIO_CONTROL_LOUDNESS 0x0200 + + +/********************************************************************** + * Processing Unit Control Bits: + **********************************************************************/ +#define AUDIO_CONTROL_ENABLE 0x0001 /* Common Bit */ +#define AUDIO_CONTROL_MODE_SELECT 0x0002 /* Common Bit */ + + +/********************************************************************** + * Up/Down-mix Control Bits + **********************************************************************/ +/* AUDIO_CONTROL_ENABLE 0x0001 Common Bit */ +/* AUDIO_CONTROL_MODE_SELECT 0x0002 Common Bit */ + + +/********************************************************************** + * Dolby Prologic Control Bits + **********************************************************************/ +/* AUDIO_CONTROL_ENABLE 0x0001 Common Bit */ +/* AUDIO_CONTROL_MODE_SELECT 0x0002 Common Bit */ + +/********************************************************************** + * 3D Stereo Extender Control Bits + **********************************************************************/ +/* AUDIO_CONTROL_ENABLE 0x0001 Common Bit */ +#define AUDIO_CONTROL_SPACIOUSNESS 0x0002 + + +/********************************************************************** + * Reverberation Control Bits + **********************************************************************/ +/* AUDIO_CONTROL_ENABLE 0x0001 Common Bit */ +#define AUDIO_CONTROL_REVERB_TYPE 0x0002 +#define AUDIO_CONTROL_REVERB_LEVEL 0x0004 +#define AUDIO_CONTROL_REVERB_TIME 0x0008 +#define AUDIO_CONTROL_REVERB_FEEDBACK 0x0010 + + +/********************************************************************** + * Chorus Control Bits + **********************************************************************/ +/* AUDIO_CONTROL_ENABLE 0x0001 Common Bit */ +#define AUDIO_CONTROL_CHORUS_LEVEL 0x0002 +#define AUDIO_CONTROL_SHORUS_RATE 0x0004 +#define AUDIO_CONTROL_CHORUS_DEPTH 0x0008 + +/********************************************************************** + * Dynamic Range Compressor Control Bits + **********************************************************************/ +/* AUDIO_CONTROL_ENABLE 0x0001 Common Bit */ +#define AUDIO_CONTROL_COMPRESSION_RATE 0x0002 +#define AUDIO_CONTROL_MAX_AMPL 0x0004 +#define AUDIO_CONTROL_THRESHOLD 0x0008 +#define AUDIO_CONTROL_ATTACK_TIME 0x0010 +#define AUDIO_CONTROL_RELEASE_TIME 0x0020 + + +/********************************************************************** + * Extension Unit Control Bits + **********************************************************************/ +/* AUDIO_CONTROL_ENABLE 0x0001 Common Bit */ + +/********************************************************************** + * Endpoint Control Bits + **********************************************************************/ +#define AUDIO_CONTROL_SAMPLING_FREQ 0x01 +#define AUDIO_CONTROL_PITCH 0x02 +#define AUDIO_MAX_PACKETS_ONLY 0x80 + + +/* Audio Terminal Types *///////////////////////////////////////////////////////////////////////// + +/********************************************************************** + * USB Terminal Types in Termt20 final.pdf 2.1 Table 2-1: + **********************************************************************/ +#define AUDIO_TERMINAL_USB_UNDEFINED 0x0100 +#define AUDIO_TERMINAL_USB_STREAMING 0x0101 +#define AUDIO_TERMINAL_USB_VENDOR_SPECIFIC 0x01FF + +/********************************************************************** + * Input Terminal Types in Termt20 final.pdf 2.2 Table 2-2: + **********************************************************************/ +#define AUDIO_TERMINAL_INPUT_UNDEFINED 0x0200 +#define AUDIO_TERMINAL_MICROPHONE 0x0201 +#define AUDIO_TERMINAL_DESKTOP_MICROPHONE 0x0202 +#define AUDIO_TERMINAL_PERSONAL_MICROPHONE 0x0203 +#define AUDIO_TERMINAL_OMNI_DIR_MICROPHONE 0x0204 +#define AUDIO_TERMINAL_MICROPHONE_ARRAY 0x0205 +#define AUDIO_TERMINAL_PROCESSING_MIC_ARRAY 0x0206 + +/********************************************************************** + * Output Terminal Types in Termt20 final.pdf 2.3 Table 2-3: + **********************************************************************/ +#define AUDIO_TERMINAL_OUTPUT_UNDEFINED 0x0300 +#define AUDIO_TERMINAL_SPEAKER 0x0301 +#define AUDIO_TERMINAL_HEADPHONES 0x0302 +#define AUDIO_TERMINAL_HEAD_MOUNTED_AUDIO 0x0303 +#define AUDIO_TERMINAL_DESKTOP_SPEAKER 0x0304 +#define AUDIO_TERMINAL_ROOM_SPEAKER 0x0305 +#define AUDIO_TERMINAL_COMMUNICATION_SPEAKER 0x0306 +#define AUDIO_TERMINAL_LOW_FREQ_SPEAKER 0x0307 + + +/********************************************************************** + * Bi-directional Terminal Types in Termt20 final.pdf 2.4 Table 2-4: + **********************************************************************/ +#define AUDIO_TERMINAL_BIDIRECTIONAL_UNDEFINED 0x0400 +#define AUDIO_TERMINAL_HANDSET 0x0401 +#define AUDIO_TERMINAL_HEAD_MOUNTED_HANDSET 0x0402 +#define AUDIO_TERMINAL_SPEAKERPHONE 0x0403 +#define AUDIO_TERMINAL_SPEAKERPHONE_ECHOSUPRESS 0x0404 +#define AUDIO_TERMINAL_SPEAKERPHONE_ECHOCANCEL 0x0405 + +/********************************************************************** + * Telephony Terminal Types in Termt20 final.pdf 2.5 Table 2-5: + **********************************************************************/ +#define AUDIO_TERMINAL_TELEPHONY_UNDEFINED 0x0500 +#define AUDIO_TERMINAL_PHONE_LINE 0x0501 +#define AUDIO_TERMINAL_TELEPHONE 0x0502 +#define AUDIO_TERMINAL_DOWN_LINE_PHONE 0x0503 + +/********************************************************************** + * External Terminal Types in Termt20 final.pdf 2.6 Table 2-6: + **********************************************************************/ +#define AUDIO_TERMINAL_EXTERNAL_UNDEFINED 0x0600 +#define AUDIO_TERMINAL_ANALOG_CONNECTOR 0x0601 +#define AUDIO_TERMINAL_DIGITAL_AUDIO_INTERFACE 0x0602 +#define AUDIO_TERMINAL_LINE_CONNECTOR 0x0603 +#define AUDIO_TERMINAL_LEGACY_AUDIO_CONNECTOR 0x0604 +#define AUDIO_TERMINAL_SPDIF_INTERFACE 0x0605 +#define AUDIO_TERMINAL_1394_DA_STREAM 0x0606 +#define AUDIO_TERMINAL_1394_DA_STREAM_TRACK 0x0607 +#define AUDIO_TERMINAL_ADAT_LIGHTPIPE 0x0608 +#define AUDIO_TERMINAL_TDIF 0x0609 +#define AUDIO_TERMINAL_MADI 0x060A + +/********************************************************************** + * Embedded Function Terminal Types in + * Termt20 final.pdf 2.7 Table 2-7: + **********************************************************************/ +#define AUDIO_TERMINAL_EMBEDDED_UNDEFINED 0x0700 +#define AUDIO_TERMINAL_CALIBRATION_NOISE 0x0701 +#define AUDIO_TERMINAL_EQUALIZATION_NOISE 0x0702 +#define AUDIO_TERMINAL_CD_PLAYER 0x0703 +#define AUDIO_TERMINAL_DAT 0x0704 +#define AUDIO_TERMINAL_DCC 0x0705 +#define AUDIO_TERMINAL_MINI_DISK 0x0706 +#define AUDIO_TERMINAL_ANALOG_TAPE 0x0707 +#define AUDIO_TERMINAL_PHONOGRAPH 0x0708 +#define AUDIO_TERMINAL_VCR_AUDIO 0x0709 +#define AUDIO_TERMINAL_VIDEO_DISC_AUDIO 0x070A +#define AUDIO_TERMINAL_DVD_AUDIO 0x070B +#define AUDIO_TERMINAL_TV_TUNER_AUDIO 0x070C +#define AUDIO_TERMINAL_SATELLITE_RECEIVER_AUDIO 0x070D +#define AUDIO_TERMINAL_CABLE_TUNER_AUDIO 0x070E +#define AUDIO_TERMINAL_DSS_AUDIO 0x070F +#define AUDIO_TERMINAL_RADIO_RECEIVER 0x0710 +#define AUDIO_TERMINAL_RADIO_TRANSMITTER 0x0711 +#define AUDIO_TERMINAL_MULTI_TRACK_RECORDER 0x0712 +#define AUDIO_TERMINAL_SYNTHESIZER 0x0713 +#define AUDIO_TERMINAL_PIANO 0x0714 +#define AUDIO_TERMINAL_GUITAR 0x0715 +#define AUDIO_TERMINAL_DRUMS_RHYTHM 0x0716 +#define AUDIO_TERMINAL_OTHER 0x0717 + + +#endif /* __USB_AUDIO_H__ */ diff --git a/CoX/middleware/USB_CLASS/USB_CDC/cdc_callback.c b/CoX/middleware/USB_CLASS/USB_CDC/cdc_callback.c new file mode 100644 index 00000000..bf652082 --- /dev/null +++ b/CoX/middleware/USB_CLASS/USB_CDC/cdc_callback.c @@ -0,0 +1,909 @@ +/***************************************************************************** + * U S B - C D C - C O M P O N E N T + ****************************************************************************/ +/** + * @file : CDC_CALLBACK.c + * @brief : USB Communication Device Class Call Back module + * @version : 1.1 + * @date : 10. MAR. 2011 + * @author : CooCox + ************************************************************************** + * Software that is described herein is for illustrative purposes only + * which provides customers with programming information regarding the + * products. This software is supplied "AS IS" without any warranties. + * NXP Semiconductors assumes no responsibility or liability for the + * use of the software, conveys no license or title under any patent, + * copyright, or mask work right to the product. NXP Semiconductors + * reserves the right to make changes in the software without + * notification. NXP Semiconductors also make no representation or + * warranty that such application will be suitable for the specified + * use without further testing or modification. + **********************************************************************/ +#include "usb_Enumerate.h" +#include "cdc_callback.h" + +void CDC_Event(USBCDC_Dev *dev); + +/********************************************************************** + * Buffer masks + **********************************************************************/ +#define CDC_BUF_SIZE (64) /*Output buffer in bytes (power 2)*/ + /*large enough for file transfer */ +#define CDC_BUF_MASK (CDC_BUF_SIZE-1ul) + +/********************************************************************** + * Buffer read / write macros + **********************************************************************/ +#define CDC_BUF_RESET(cdcBuf) (cdcBuf->rdIdx = cdcBuf->wrIdx = 0) +#define CDC_BUF_WR(cdcBuf, dataIn) (cdcBuf->data[CDC_BUF_MASK & cdcBuf->wrIdx++] = (dataIn)) +#define CDC_BUF_RD(cdcBuf) (cdcBuf->data[CDC_BUF_MASK & cdcBuf->rdIdx++]) +#define CDC_BUF_EMPTY(cdcBuf) (cdcBuf->rdIdx == cdcBuf->wrIdx) +#define CDC_BUF_FULL(cdcBuf) (cdcBuf->rdIdx == cdcBuf->wrIdx+1) +#define CDC_BUF_COUNT(cdcBuf) (CDC_BUF_MASK & (cdcBuf->wrIdx - cdcBuf->rdIdx)) + +/********************************************************************** + * Function declaration + **********************************************************************/ +unsigned short CDC_GetSerialState (USBCDC_Dev *dev); + +/********************************************************************************************************//** + * @brief read data from CDC_OutBuf + * @param[out] buffer : buffer for CDC Out data + * @param[in] length : buffer length of CDC Out data + * buf : buffer for CDC Out data + * @return The length of the read byte +************************************************************************************************************/ +int CDC_RdOutBuf (CDC_BUF_T *buf,char *buffer, const int *length) +{ + int bytesToRead, bytesRead; + + /* Read *length bytes, block if *bytes are not avaialable */ + bytesToRead = *length; + bytesToRead = (bytesToRead < (*length)) ? bytesToRead : (*length); + bytesRead = bytesToRead; + + + // ... add code to check for underrun + + while (bytesToRead--) + { + *buffer++ = CDC_BUF_RD(buf); + } + return (bytesRead); +} + +/********************************************************************************************************//** + * @brief Write data to CDC_OutBuf + * @param[out] buffer : buffer for CDC Out data + * @param[in] length : buffer length of CDC Out data + * buf : buffer for CDC Out data + * @return The length of the write byte +************************************************************************************************************/ +int CDC_WrOutBuf (CDC_BUF_T *buf,const char *buffer, int *length) +{ + int bytesToWrite, bytesWritten; + + // Write *length bytes + bytesToWrite = *length; + bytesWritten = bytesToWrite; + + + // ... add code to check for overwrite + + while (bytesToWrite) + { + CDC_BUF_WR(buf, *buffer++); // Copy Data to buffer + bytesToWrite--; + } + + return (bytesWritten); +} + + +/********************************************************************************************************//** + * @brief Check if character(s) are available at CDC_OutBuf + * @param[out] availChar : The length of the available byte at CDC_OutBuf + * @param[in] buf : buffer for CDC Out data + * @return 0 +************************************************************************************************************/ +int CDC_OutBufAvailChar (CDC_BUF_T *buf,int *availChar) +{ + + *availChar = CDC_BUF_COUNT(buf); + + return (0); +} +/* end Buffer handling */ + + +/********************************************************************************************************//** + * @brief CDC init + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +void CDC_Init (USBCDC_Dev *dev) +{ + dev->cdc_device_init (dev->cdc_device,(void *)&dev->CDC_LineCoding); + dev->CDC_DepInEmpty = 1; + dev->CDC_SerialState = CDC_GetSerialState(dev); + +// CDC_BUF_RESET((CDC_BUF_T *)(&dev->CDC_OutBuf)); +} + + +/********************************************************************************************************//** + * @brief CDC SendEncapsulatedCommand Request Callback,Called automatically on CDC SEND_ENCAPSULATED_COMMAND Request + * @param[in] dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t CDC_SendEncapsulatedCommand (USBCDC_Dev *dev) +{ + + return (TRUE); +} + + +/********************************************************************************************************//** + * @brief CDC GetEncapsulatedResponse Request Callback,Called automatically on CDC Get_ENCAPSULATED_RESPONSE Request + * @param[in] dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t CDC_GetEncapsulatedResponse (USBCDC_Dev *dev) +{ + + /* ... add code to handle request */ + return (TRUE); +} + + +/********************************************************************************************************//** + * @brief CDC SetCommFeature Request Callback,Called automatically on CDC Set_COMM_FATURE Request + * @param[in] wFeatureSelector: FeatureSelector + * dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t CDC_SetCommFeature (USBCDC_Dev *dev, unsigned short wFeatureSelector) +{ + + /* ... add code to handle request */ + return (TRUE); +} + + +/********************************************************************************************************//** + * @brief CDC GetCommFeature Request Callback,Called automatically on CDC Get_COMM_FATURE Request + * @param[in] wFeatureSelector : FeatureSelector + * dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t CDC_GetCommFeature (USBCDC_Dev *dev, unsigned short wFeatureSelector) +{ + + /* ... add code to handle request */ + return (TRUE); +} + + +/********************************************************************************************************//** + * @brief CDC ClearCommFeature Request Callback,Called automatically on CDC CLEAR_COMM_FATURE Request + * @param[in] wFeatureSelector: FeatureSelector + * dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t CDC_ClearCommFeature (USBCDC_Dev *dev, unsigned short wFeatureSelector) +{ + + /* ... add code to handle request */ + return (TRUE); +} + +/********************************************************************************************************//** + * @brief CDC SetAuxLineState Request Callback,Called automatically on CDC SET_AUX_LINE_STATE Request + * @param[in] wIsConnect: + * - 1 Connect + * - 0 Disconnect + * dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t CDC_SetAuxLineState (USBCDC_Dev *dev, unsigned short wIsConnect) +{ + + /* ... add code to handle request */ + return (TRUE); +} + +/********************************************************************************************************//** + * @brief CDC SetHookState Request Callback,Called automatically on CDC SET_HOOK_STATE Request + * @param[in] wRelayConfig: + * C 0 On hook + * C 1 Off hook + * - 2 SNOOPING + * dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t CDC_SetHookState (USBCDC_Dev *dev, unsigned short wRelayConfig) +{ + + /* ... add code to handle request */ + return (TRUE); +} + +/********************************************************************************************************//** + * @brief CDC PulseSetup Request Callback,Called automatically on CDC PULSE_SETUP Request + * @param[in] wIsEnable: + * 0 C Disable + * 1 C Enable + * dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t CDC_PulseSetup (USBCDC_Dev *dev, unsigned short wIsEnable) +{ + + /* ... add code to handle request */ + return (TRUE); +} + +/********************************************************************************************************//** + * @brief CDC SendPulse Request Callback,Called automatically on CDC SEND_PULSE Request + * @param[in] wCycles: contains the number of make/break pulse cycles to generate + * dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t CDC_SendPulse (USBCDC_Dev *dev, unsigned short wCycles) +{ + + /* ... add code to handle request */ + return (TRUE); +} + +/********************************************************************************************************//** + * @brief CDC SetPulseTime Request Callback,Called automatically on CDC SET_PULSE_TIME Request + * @param[in] wTiming: specifies the break time period in the high byte and + * the make time period in the low byte + * dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t CDC_SetPulseTime (USBCDC_Dev *dev, unsigned short wTiming) +{ + + /* ... add code to handle request */ + return (TRUE); +} + +/********************************************************************************************************//** + * @brief CDC RingAuxJack Request Callback,Called automatically on CDC RING_AUX_JACK Request + * @param[in] wFeatureSelector: wNumberOfRings: contains the number of ring signals to generate on + * a secondary phone jack of the device. + * dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t CDC_RingAuxJack (USBCDC_Dev *dev, unsigned short wNumberOfRings) +{ + + /* ... add code to handle request */ + return (TRUE); +} + +/********************************************************************************************************//** + * @brief CDC SetLineCoding Request Callback, Called automatically on CDC SET_LINE_CODING Request + * @param[in] dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t CDC_SetLineCoding (USBCDC_Dev *dev) +{ + + dev->CDC_LineCoding.dwDTERate = (dev->usb_enu.EP0Buf[0] << 0) + | (dev->usb_enu.EP0Buf[1] << 8) + | (dev->usb_enu.EP0Buf[2] << 16) + | (dev->usb_enu.EP0Buf[3] << 24); + dev->CDC_LineCoding.bCharFormat = dev->usb_enu.EP0Buf[4]; + dev->CDC_LineCoding.bParityType = dev->usb_enu.EP0Buf[5]; + dev->CDC_LineCoding.bDataBits = dev->usb_enu.EP0Buf[6]; + + dev->cdc_device_deinit(dev->cdc_device); + dev->cdc_device_init (dev->cdc_device,(void *)&dev->CDC_LineCoding); +// ser_InitPort (dev->CDC_LineCoding.dwDTERate, +// dev->CDC_LineCoding.bDataBits, +// dev->CDC_LineCoding.bParityType, +// dev->CDC_LineCoding.bCharFormat); + return (TRUE); +} + + +/********************************************************************************************************//** + * @brief CDC GetLineCoding Request Callback,Called automatically on CDC GET_LINE_CODING Request + * @param[in] dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t CDC_GetLineCoding (USBCDC_Dev *dev,uint32_t para) +{ + + dev->usb_enu.EP0Buf[0] = (dev->CDC_LineCoding.dwDTERate >> 0) & 0xFF; + dev->usb_enu.EP0Buf[1] = (dev->CDC_LineCoding.dwDTERate >> 8) & 0xFF; + dev->usb_enu.EP0Buf[2] = (dev->CDC_LineCoding.dwDTERate >> 16) & 0xFF; + dev->usb_enu.EP0Buf[3] = (dev->CDC_LineCoding.dwDTERate >> 24) & 0xFF; + dev->usb_enu.EP0Buf[4] = dev->CDC_LineCoding.bCharFormat; + dev->usb_enu.EP0Buf[5] = dev->CDC_LineCoding.bParityType; + dev->usb_enu.EP0Buf[6] = dev->CDC_LineCoding.bDataBits; + + return (TRUE); +} + +/********************************************************************************************************//** + * @brief CDC SetControlLineState Request Callback,Called automatically on CDC SET_CONTROL_LINE_STATE Request + * @param[in] wControlSignalBitmap: + * dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t CDC_SetControlLineState (USBCDC_Dev *dev,unsigned short wControlSignalBitmap) +{ + + CDC_Event(dev); + /* ... add code to handle request */ + return (TRUE); +} + +/********************************************************************************************************//** + * @brief CDC SendBreak Request Callback,Called automatically on CDC Set_COMM_FATURE Request + * @param[in] wDurationOfBreak: + * - 0xFFFF start of Break + * - 0x0000 stop of Break + * - 0x#### Duration of Break + * dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t CDC_SendBreak (USBCDC_Dev *dev, unsigned short wDurationOfBreak) +{ + + /* ... add code to handle request */ + return (TRUE); +} + +/********************************************************************************************************//** + * @brief CDC SetRingerParms Request Callback,Called automatically on CDC SET_RINGER_PARMS Request + * @param[in] dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t CDC_SetRingerParms (USBCDC_Dev *dev) +{ + + /* ... add code to handle request */ + return (TRUE); +} + +/********************************************************************************************************//** + * @brief CDC GetRingerParms Request Callback,Called automatically on CDC GET_RINGER_PARMS Request + * @param[in] dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t CDC_GetRingerParms (USBCDC_Dev *dev) +{ + + /* ... add code to handle request */ + return (TRUE); +} + +/********************************************************************************************************//** + * @brief CDC SetOperationParms Request Callback,Called automatically on CDC SET_OPERATION_PARMS Request + * @param[in] wOperationMode: + * - 0x2 Host Centric Mode + * - 0x1 Standalone Mode + * - 0x0 Simple Mode + * dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t CDC_SetOperationParms (USBCDC_Dev *dev, unsigned short wOperationMode) +{ + + /* ... add code to handle request */ + return (TRUE); +} + +/********************************************************************************************************//** + * @brief CDC GetOperationParms Request Callback,Called automatically on CDC GET_OPERATION_PARMS Request + * @param[in] dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t CDC_GetOperationParms (USBCDC_Dev *dev) +{ + + /* ... add code to handle request */ + return (TRUE); +} + +/********************************************************************************************************//** + * @brief CDC SetLineParms Request Callback,Called automatically on CDC SET_LINE_PARMS Request + * @param[in] wLineStateChange: + * - 0x0000 Drop the active call on the line. + * - 0x0001 Start a new call on the line. + * - 0x0002 Apply ringing to the line. + * - 0x0003 Remove ringing from the line. + * - 0x0004 Switch to a specific call on the line. Data is used to + * pass a 1-byte call index that identifies the call. + * dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t CDC_SetLineParms (USBCDC_Dev *dev, unsigned short wLineStateChange) +{ + + /* ... add code to handle request */ + return (TRUE); +} + +/********************************************************************************************************//** + * @brief CDC GetLineParms Request Callback,Called automatically on CDC GET_LINE_PARMS Request + * @param[in] dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t CDC_GetLineParms (USBCDC_Dev *dev) +{ + + /* ... add code to handle request */ + return (TRUE); +} + +/********************************************************************************************************//** + * @brief CDC DialDigits Request Callback,Called automatically on CDC DIAL_DIGITS Request + * @param[in] dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t CDC_DialDigits (USBCDC_Dev *dev) +{ + + /* ... add code to handle request */ + return (TRUE); +} + +/********************************************************************************************************//** + * @brief CDC SetLineParms Request Callback,Called automatically on CDC SET_LINE_PARMS Request + * @param[in] wUnitParameter: + * - bEntityId Unit Id + * - bParameterIndex A zero based value indicating Unit parameter index. + * dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t CDC_SetUnitParameter (USBCDC_Dev *dev, unsigned short wUnitParameter) +{ + + /* ... add code to handle request */ + return (TRUE); +} + +/********************************************************************************************************//** + * @brief CDC GetLineParms Request Callback,Called automatically on CDC GET_LINE_PARMS Request + * @param[in] wUnitParameter: + * - bEntityId Unit Id + * - bParameterIndex A zero based value indicating Unit parameter index. + * dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t CDC_GetUnitParameter (USBCDC_Dev *dev, unsigned short wUnitParameter) +{ + + /* ... add code to handle request */ + return (TRUE); +} + +/********************************************************************************************************//** + * @brief CDC ClearUnitParameter Request Callback,Called automatically on CDC CLEAR_UNIT_PARAMETER Request + * @param[in] wUnitParameter: + * - bEntityId Unit Id + * - bParameterIndex A zero based value indicating Unit parameter index. + * dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t CDC_ClearUnitParameter (USBCDC_Dev *dev, unsigned short wUnitParameter) +{ + + /* ... add code to handle request */ + return (TRUE); +} + +/********************************************************************************************************//** + * @brief CDC GetProfile Request Callback,Called automatically on CDC GET_PROFILE Request + * @param[in] dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t CDC_GetProfile (USBCDC_Dev *dev) +{ + + /* ... add code to handle request */ + return (TRUE); +} + +/********************************************************************************************************//** + * @brief CDC SetEthernetMulticastFilters Request Callback,Called automatically on + * CDC SET_ETHERNET_MULTICAST_FILTERS Request + * @param[in] wNumberOfFilters: Number of filters (N) + * dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t CDC_SetEthernetMulticastFilters (USBCDC_Dev *dev, unsigned short wNumberOfFilters) +{ + + /* ... add code to handle request */ + return (TRUE); +} + +/********************************************************************************************************//** + * @brief CDC SetEthernetPowerManagementPatternFilter Request Callback,Called automatically on + * CDC SET_ETHERNET_PMP_FILTER Request + * @param[in] wNumberOfFilters: Number of filters (N) + * dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t CDC_SetEthernetPowerManagementPatternFilter (USBCDC_Dev *dev, unsigned short wNumberOfFilters) +{ + + /* ... add code to handle request */ + return (TRUE); +} + +/********************************************************************************************************//** + * @brief CDC GetEthernetPowerManagementPatternFilter Request Callback,Called automatically on + * CDC GET_ETHERNET_PMP_FILTER Request + * @param[in] wNumberOfFilters: Number of filters (N) + * dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t CDC_GetEthernetPowerManagementPatternFilter (USBCDC_Dev *dev, unsigned short wNumberOfFilters) +{ + + /* ... add code to handle request */ + return (TRUE); +} + +/********************************************************************************************************//** + * @brief CDC SetEthernetPacketFilter Request Callback,Called automatically on + * CDC SET_ETHERNET_PACKET_FILTER Request + * @param[in] wPacketFilterBitmap: + * - D0 PACKET_TYPE_PROMISCUOUS + * - D1 PACKET_TYPE_ALL_MULTICAST + * - D2 PACKET_TYPE_DIRECTED + * - D3 PACKET_TYPE_BROADCAST + * - D4 PACKET_TYPE_MULTICAST + * dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t CDC_SetEthernetPacketFilter (USBCDC_Dev *dev, unsigned short wPacketFilterBitmap) +{ + + /* ... add code to handle request */ + return (TRUE); +} + +/********************************************************************************************************//** + * @brief CDC GetEthernetStatistic Request Callback,Called automatically on + * CDC GET_ETHERNET_STATISTIC Request + * @param[in] wFeatureSelector: + * dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t CDC_GetEthernetStatistic (USBCDC_Dev *dev, unsigned short wFeatureSelector) +{ + + /* ... add code to handle request */ + return (TRUE); +} + +/********************************************************************************************************//** + * @brief CDC SetATMDataFormat Request Callback,Called automatically on + * CDC SET_ATM_DATA_FORMAT Request + * @param[in] wDataFormat: + * - 1 Type 1 format: concatenated ATM cells + * - 2 Type 2 format: ATM header template + concatenated ATM cell payloads + * - 3 Type 3 format: AAL 5 SDU + * dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t CDC_SetATMDataFormat (USBCDC_Dev *dev, unsigned short wDataFormat) +{ + + /* ... add code to handle request */ + return (TRUE); +} + +/********************************************************************************************************//** + * @brief CDC GetATMDeviceStatistics Request Callback,Called automatically on + * CDC GET_ATM_DEVICE_STATISTICS Request + * @param[in] wFeatureSelector: + * - 0 Reserved for future use + * - 1 The number of cells that have been sent upstream to the WAN link by the ATM layer. + * - 2 The number of cells that have been received downstream from the WAN link by the ATM layer. + * - 3 The number of cells that have been received downstream from the WAN link by the ATM layer + * and discarded due to congestion on the USB link. + * - 4 The number of cells that have been received downstream from the WAN link by the ATM layer + * and discarded due to AAL5 CRC errors. + * - 5 The number of cells that have been received downstream from the WAN link and discarded + * due to HEC errors in the cell header. + * - 6 The number of cells that have been received downstream from the WAN link and have been + * detected with HEC errors in the cell header and successfully corrected. + * dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t CDC_GetATMDeviceStatistics (USBCDC_Dev *dev, unsigned short wFeatureSelector) +{ + + /* ... add code to handle request */ + return (TRUE); +} + +/********************************************************************************************************//** + * @brief CDC SetATMDefaultVC Request Callback,Called automatically on + * CDC SET_ATM_DEFAULT_VC Request + * @param[in] dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t CDC_SetATMDefaultVC (USBCDC_Dev *dev) +{ + + /* ... add code to handle request */ + return (TRUE); +} + +/********************************************************************************************************//** + * @brief CDC GetATMVCStatistics Request Callback,Called automatically on + * CDC GET_ATM_VC_STATISTICS Request + * @param[in] wFeatureSelector : + * - 00 Reserved for future use + * - 01 The number of cells that have been sent upstream to the WAN link for the specified + * VPI/VCI since the device has been powered on or reset. + * - 02 The number of cells that have been received downstream from the WAN link for the + * specified VPI/VCI since the device has been powered on or reset. + * dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t CDC_GetATMVCStatistics (USBCDC_Dev *dev, unsigned short wFeatureSelector) +{ + + /* ... add code to handle request */ + return (TRUE); +} + + + + +/********************************************************************************************************//** + * @brief CDC_BulkIn call on DataIn Request + * @param[in] dev : a point which contains all the global variables which using in this function + * event : usb endpoint event type + * @return None +************************************************************************************************************/ +void bulk_in_handle(USBCDC_Dev *dev,uint32_t Event) +{ +// int numBytesRead, numBytesAvail; +// +// //ser_AvailChar (&numBytesAvail); +// +// // ... add code to check for overwrite +// +// //numBytesRead = ser_Read ((char *)&dev->BulkBufIn[0], &numBytesAvail); +// +// // send over USB +// if (numBytesRead > 0) +// { +// dev->usb_enu.usb->USB_WriteEP (CDC_DEP_IN, &dev->BulkBufIn[0], numBytesRead); +// } +// else +// { +// dev->CDC_DepInEmpty = 1; +// } +} + + +/********************************************************************************************************//** + * @brief CDC_BulkOut call on DataOut Request + * @param[in] dev : a point which contains all the global variables which using in this function + * event : usb endpoint event type + * @return None +************************************************************************************************************/ +void bulk_out_handle(USBCDC_Dev *dev,uint32_t Event) +{ + int numBytesRead; + + // get data from USB into intermediate buffer + numBytesRead = dev->usb_enu.usb->USB_ReadEP(CDC_DEP_OUT, &dev->BulkBufOut[0]); + + // ... add code to check for overwrite + + // store data in a buffer to transmit it over serial interface + CDC_WrOutBuf (&dev->CDC_OutBuf,(char *)&dev->BulkBufOut[0], &numBytesRead); + +} + +/********************************************************************************************************//** + * @brief Send the NETWORK_CONNECTION notification as defined in CDC120.pdf, 6.3.1. + * @param[in] dev : a point which contains all the global variables which using in this function + * wIsConnected : + * @return None +************************************************************************************************************/ +void CDC_NetworkConnection (USBCDC_Dev *dev, unsigned short wIsConnected) +{ + /* ... add code to handle Notifications */ +} + +/********************************************************************************************************//** + * @brief Send the RESPONSE_AVAILABLE notification as defined in CDC120.pdf, 6.3.2. + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +void CDC_ResponseAvailable (USBCDC_Dev *dev) +{ + /* ... add code to handle Notifications */ +} + +/********************************************************************************************************//** + * @brief Send the CONNECTION_SPEED_CHANGE notification as defined in CDC120.pdf, 6.3.3. + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +void CDC_ConnectionSpeedChange (USBCDC_Dev *dev) +{ + /* ... add code to handle Notifications */ +} + +/********************************************************************************************************//** + * @brief Send the AUX_JACK_ HOOK_STATE notification as defined in PSTN120.pdf, 6.5.2. + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +void CDC_AuxJackHookState (USBCDC_Dev *dev) +{ + /* ... add code to handle Notifications */ +} + +/********************************************************************************************************//** + * @brief Send the RING_DETECT notification as defined in PSTN120.pdf, 6.5.3. + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +void CDC_RingDetect (USBCDC_Dev *dev) +{ + /* ... add code to handle Notifications */ +} + +/********************************************************************************************************//** + * @brief Send the CALL_STATE_CHANGE notification as defined in PSTN120.pdf, 6.5.5. + * @param[in] dev : a point which contains all the global variables which using in this function + * wCallIndex : + * @return None +************************************************************************************************************/ +void CDC_CallStateChange (USBCDC_Dev *dev, unsigned short wCallIndex) +{ + /* ... add code to handle Notifications */ +} + +/********************************************************************************************************//** + * @brief Send the LINE_STATE_CHANGE notification as defined in PSTN120.pdf, 6.5.6. + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +void CDC_LineStateChange (USBCDC_Dev *dev, unsigned short wLineState) +{ + /* ... add code to handle Notifications */ +} + + + +/********************************************************************************************************//** + * @brief Get the SERIAL_STATE as defined in PSTN120.pdf, 6.5.4, Table 31. + * @param[in] dev : a point which contains all the global variables which using in this function + * @return SerialState as defined in PSTN120.pdf +************************************************************************************************************/ +unsigned short CDC_GetSerialState (USBCDC_Dev *dev) +{ + unsigned short temp; + + dev->CDC_SerialState = 0; + //ser_LineState (&temp); + + if (temp & 0x8000) dev->CDC_SerialState |= CDC_SERIAL_STATE_RX_CARRIER; + if (temp & 0x2000) dev->CDC_SerialState |= CDC_SERIAL_STATE_TX_CARRIER; + if (temp & 0x0010) dev->CDC_SerialState |= CDC_SERIAL_STATE_BREAK; + if (temp & 0x4000) dev->CDC_SerialState |= CDC_SERIAL_STATE_RING; + if (temp & 0x0008) dev->CDC_SerialState |= CDC_SERIAL_STATE_FRAMING; + if (temp & 0x0004) dev->CDC_SerialState |= CDC_SERIAL_STATE_PARITY; + if (temp & 0x0002) dev->CDC_SerialState |= CDC_SERIAL_STATE_OVERRUN; + + return (dev->CDC_SerialState); +} + + +/********************************************************************************************************//** + * @brief Send the SERIAL_STATE notification as defined in PSTN120.pdf, 6.5.4. + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +void CDC_SerialStateFun (USBCDC_Dev *dev) +{ + + dev->NotificationBuf[0] = 0xA1; // bmRequestType + dev->NotificationBuf[1] = CDC_NOTIFICATION_SERIAL_STATE; // bNotification (SERIAL_STATE) + dev->NotificationBuf[2] = 0x00; // wValue + dev->NotificationBuf[3] = 0x00; + dev->NotificationBuf[4] = 0x00; // wIndex (Interface #, LSB first) + dev->NotificationBuf[5] = 0x00; + dev->NotificationBuf[6] = 0x02; // wLength (Data length = 2 bytes, LSB first) + dev->NotificationBuf[7] = 0x00; + dev->NotificationBuf[8] = (dev->CDC_SerialState >> 0) & 0xFF; // UART State Bitmap (16bits, LSB first) + dev->NotificationBuf[9] = (dev->CDC_SerialState >> 8) & 0xFF; + + dev->usb_enu.usb->USB_WriteEP (CDC_CEP_IN, &dev->NotificationBuf[0], 10); // send notification +} + +/********************************************************************************************************//** + * @brief CDC VCOM open + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +void CDC_Open(USBCDC_Dev *dev, USBCDC_Dev *user_config) +{ + dev->usb_enu.cdc_data = dev; + dev->usb_enu.g_pfn_cdc_GetLineCoding = (PFN_CDC_CALLBACK *)CDC_GetLineCoding; + dev->usb_enu.g_pfn_cdc_SetLineCoding = (PFN_CDC_CALLBACK *)CDC_SetLineCoding; + dev->usb_enu.g_pfn_cdc_SetCommFeature = (PFN_CDC_CALLBACK *)CDC_SetCommFeature; + dev->usb_enu.g_pfn_cdc_SendEncapsulatedCommand = (PFN_CDC_CALLBACK *)CDC_SendEncapsulatedCommand; + dev->usb_enu.g_pfn_cdc_SendBreak = (PFN_CDC_CALLBACK *)CDC_SendBreak; + dev->usb_enu.g_pfn_cdc_SetControlLineState = (PFN_CDC_CALLBACK *)CDC_SetControlLineState; + + + CDC_Init(dev); + USB_Init(&dev->usb_enu); +} + +/********************************************************************************************************//** + * @brief connect CDC to usb host + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +void CDC_Connect(USBCDC_Dev *dev,uint32_t con) +{ + dev->usb_enu.usb->USB_Connect(con); +} + +/********************************************************************************************************//** + * @brief Get ADC Configuration statue + * @param[in] dev : a point which contains all the global variables which using in this function + * @return Configuration statue +************************************************************************************************************/ +uint8_t CDC_Configurated(USBCDC_Dev *dev) +{ + return dev->usb_enu.USB_Configuration; +} + +/********************************************************************************************************//** + * @brief ADC event callback setup + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +void CDC_Event(USBCDC_Dev *dev) +{ + dev->usb_enu.usb->USB_Event((CDC_DEP_OUT&0xf),(USB_Event_Handler)bulk_out_handle,(void *)dev); + dev->usb_enu.usb->USB_Event((CDC_DEP_IN &0xf),(USB_Event_Handler)bulk_in_handle, (void *)dev); +} + +/********************************************************************************************************//** + * @brief ADC read,data transfer from host to device + * @param[in] dev : a point which contains all the global variables which using in this function + * rbuf : buffer of read + * length : byte length of read + * @return None +************************************************************************************************************/ +uint32_t CDC_Read(USBCDC_Dev *dev, uint8_t *rbuf, uint32_t length) +{ + dev->cdc_device_read(dev->cdc_device, dev->CDC_InBuf.data, length); + return length; +} + +/********************************************************************************************************//** + * @brief CDC write,data transfer from device to host + * @param[in] dev : a point which contains all the global variables which using in this function + * wbuf : buffer of write + * length : byte length of write + * @return None +************************************************************************************************************/ +uint32_t CDC_Write(USBCDC_Dev *dev, uint8_t *wbuf, uint32_t length) +{ + dev->cdc_device_write(dev->cdc_device, wbuf, length); + return length; +} diff --git a/CoX/middleware/USB_CLASS/USB_CDC/cdc_callback.h b/CoX/middleware/USB_CLASS/USB_CDC/cdc_callback.h new file mode 100644 index 00000000..c5351d80 --- /dev/null +++ b/CoX/middleware/USB_CLASS/USB_CDC/cdc_callback.h @@ -0,0 +1,79 @@ +/***************************************************************************** + * U S B - C D C - C O M P O N E N T + ****************************************************************************/ +/** + * @file : CDC_CALLBACK.h + * @brief : USB Communication Device Class Call Back module Definitions + * @version : 1.1 + * @date : 10. MAR. 2010 + * @author : CooCox + ****************************************************************************/ + +#ifndef __CDC_CALLBACK_H__ +#define __CDC_CALLBACK_H__ + +#include "usb_enumerate.h" + +/*********************************************************************** + * USB CDC call back function definition + **********************************************************************/ +typedef uint32_t (PFN_CDCD_Init_CALLBACK) (void *dev,void *para); +typedef uint32_t (PFN_CDCD_READ_CALLBACK) (void *dev, uint8_t *rbuf, uint32_t rlen); +typedef uint32_t (PFN_CDCD_WRITE_CALLBACK) (void *dev, uint8_t *wbuf, uint32_t wlen); +typedef uint32_t (PFN_CDCD_DeInit_CALLBACK)(void *dev); + +/** + * @brief CDC output buffer + */ +typedef struct __CDC_BUF_T +{ + uint8_t data[CDC_BUF_SIZE]; + unsigned int wrIdx; + unsigned int rdIdx; +} CDC_BUF_T; + +/** + * @brief USB CDC Structure + */ +typedef struct +{ + USB_ENU_Dev usb_enu; + CDC_LINE_CODING CDC_LineCoding; + CDC_BUF_T CDC_OutBuf; + CDC_BUF_T CDC_InBuf; + unsigned short CDC_DepInEmpty; + unsigned char BulkBufIn[USB_CDC_BUFSIZE]; + unsigned char BulkBufOut[USB_CDC_BUFSIZE]; + unsigned short CDC_SerialState; + unsigned char NotificationBuf [10]; + + PFN_CDCD_Init_CALLBACK *cdc_device_init; + PFN_CDCD_READ_CALLBACK *cdc_device_read; + PFN_CDCD_WRITE_CALLBACK *cdc_device_write; + PFN_CDCD_DeInit_CALLBACK *cdc_device_deinit; + void *cdc_device; + void *cdc_para; +} USBCDC_Dev; + +/********************************************************************** + * CDC buffer handling + **********************************************************************/ +extern int CDC_RdOutBuf (CDC_BUF_T *buf,char *buffer, const int *length); +extern int CDC_WrOutBuf (CDC_BUF_T *buf,const char *buffer, int *length); +extern int CDC_OutBufAvailChar (CDC_BUF_T *buf,int *availChar); + + +/*********************************************************************** + * extern API of this component + **********************************************************************/ +extern void CDC_Open(USBCDC_Dev *dev, USBCDC_Dev *user_config); +extern void CDC_Connect(USBCDC_Dev *dev,uint32_t con); +extern uint8_t CDC_Configurated(USBCDC_Dev *dev); +extern void CDC_Event(USBCDC_Dev *dev); +extern uint32_t CDC_Read(USBCDC_Dev *dev, uint8_t *rbuf, uint32_t length); +extern uint32_t CDC_Write(USBCDC_Dev *dev, uint8_t *wbuf, uint32_t length); + + + +#endif /* __CDC_CALLBACK_H__ */ + diff --git a/CoX/middleware/USB_CLASS/USB_CDC/usb_cdc.h b/CoX/middleware/USB_CLASS/USB_CDC/usb_cdc.h new file mode 100644 index 00000000..65c52f46 --- /dev/null +++ b/CoX/middleware/USB_CLASS/USB_CDC/usb_cdc.h @@ -0,0 +1,846 @@ +/***************************************************************************** + * U S B - C D C - C O M P O N E N T + ****************************************************************************/ +/** + * @file : USB_CDC.h + * @brief : USB Communication Device Class Definitions + * @version : 1.0 + * @date : 10. MAR. 2011 + * @author : CooCox + ****************************************************************************/ + +#ifndef __USB_CDC_H +#define __USB_CDC_H + +/********************************************************************** + * Definitions based on CDC120.pdf (www.usb.org) + **********************************************************************/ + +/********************************************************************** + * Communication device class specification version 1.20 + **********************************************************************/ +#define CDC_V1_20 0x0120 /*!usb_enu.SetupPacket.wValue.WB.H) + { + case HID_REPORT_INPUT: + if(dev->GetInReport !=NULL) + { + dev->GetInReport(dev->hid_device,dev->InReport,3); + } + dev->usb_enu.EP0Buf[0] = dev->InReport[0]; + dev->usb_enu.EP0Buf[1] = dev->InReport[1]; + dev->usb_enu.EP0Buf[2] = dev->InReport[2]; + break; + case HID_REPORT_OUTPUT: + return (FALSE); /* Not Supported */ + case HID_REPORT_FEATURE: + /* EP0Buf[] = ...; */ + /* break; */ + return (FALSE); /* Not Supported */ + } + return (TRUE); +} + + +/********************************************************************************************************//** + * @brief HID Set Report Request Callback,Called automatically on HID Set Report Request + * @param[in] dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t HID_SetReport (USBHID_Dev *dev) +{ + + /* ReportID = SetupPacket.wValue.WB.L; */ + switch (dev->usb_enu.SetupPacket.wValue.WB.H) + { + case HID_REPORT_INPUT: + return (FALSE); /* Not Supported */ + case HID_REPORT_OUTPUT: + *dev->OutReport = dev->usb_enu.EP0Buf[0]; + if(dev->SetOutReport != NULL) + { + dev->SetOutReport(dev->hid_device,dev->OutReport,1); + } + break; + case HID_REPORT_FEATURE: + return (FALSE); /* Not Supported */ + } + return (TRUE); +} + + +/********************************************************************************************************//** + * @brief HID Get Idle Request Callback,Called automatically on HID Get Idle Request + * @param[in] dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t HID_GetIdle (USBHID_Dev *dev) +{ + + dev->usb_enu.EP0Buf[0] = dev->HID_IdleTime[dev->usb_enu.SetupPacket.wValue.WB.L]; + return (TRUE); +} + + +/********************************************************************************************************//** + * @brief HID Set Idle Request Callback,Called automatically on HID Set Idle Request + * @param[in] dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t HID_SetIdle (USBHID_Dev *dev) +{ + + dev->HID_IdleTime[dev->usb_enu.SetupPacket.wValue.WB.L] = dev->usb_enu.SetupPacket.wValue.WB.H; + + /* Idle Handling if needed */ + /* ... */ + + return (TRUE); +} + + +/********************************************************************************************************//** + * @brief HID Get Protocol Request Callback,Called automatically on HID Get Protocol Request + * @param[in] dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t HID_GetProtocol (USBHID_Dev *dev) +{ + + dev->usb_enu.EP0Buf[0] = dev->HID_Protocol; + return (TRUE); +} + + +/********************************************************************************************************//** + * @brief HID Set Protocol Request Callback,Called automatically on HID Set Protocol Request + * @param[in] dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +uint32_t HID_SetProtocol (USBHID_Dev *dev) +{ + + dev->HID_Protocol = dev->usb_enu.SetupPacket.wValue.WB.L; + + /* Protocol Handling if needed */ + /* ... */ + + return (TRUE); +} +/********************************************************************************************************//** + * @brief HID interrupt input + * @param[in] dev : a point which contains all the global variables which using in this function + * Event : event type of endpoint + * @return None +************************************************************************************************************/ +void HID_IntIn (USBHID_Dev *dev,uint32_t Event) +{ + if(dev->GetInReport !=NULL) + { + dev->GetInReport(dev->hid_device,dev->InReport, 3); + } + dev->usb_enu.usb->USB_WriteEP(HID_INPUT, dev->InReport, 3); +} + +/********************************************************************************************************//** + * @brief HID interrupt output + * @param[in] dev : a point which contains all the global variables which using in this function + * Event : event type of endpoint + * @return None +************************************************************************************************************/ +void HID_IntOut(USBHID_Dev *dev,uint32_t Event) +{ + uint32_t len; + len = dev->usb_enu.usb->USB_ReadEP(HID_OUTPUT,dev->OutReport); + if(dev->SetOutReport !=NULL) + { + dev->SetOutReport(dev->hid_device,dev->OutReport, len); + } +} + +/********************************************************************************************************//** + * @brief Initialization of the USB HID + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +void HID_Init (USBHID_Dev *dev) +{ + dev->usb_enu.hid_data = dev; + dev->usb_enu.g_pfn_hid_get_idle = (PFN_HID_CALLBACK *)HID_GetIdle; + dev->usb_enu.g_pfn_hid_get_procotol = (PFN_HID_CALLBACK *)HID_GetProtocol; + dev->usb_enu.g_pfn_hid_get_report = (PFN_HID_CALLBACK *)HID_GetReport; + dev->usb_enu.g_pfn_hid_set_idle = (PFN_HID_CALLBACK *)HID_SetIdle; + dev->usb_enu.g_pfn_hid_set_procotol = (PFN_HID_CALLBACK *)HID_SetProtocol; + dev->usb_enu.g_pfn_hid_set_report = (PFN_HID_CALLBACK *)HID_SetReport; + + USB_Init(&dev->usb_enu); +} + +/********************************************************************************************************//** + * @brief Connect HID to the host + * @param[in] dev : a point which contains all the global variables which using in this function + * con : TRUE \FALSE + * @return None +************************************************************************************************************/ +void HID_Connect(USBHID_Dev *dev,uint32_t con) +{ + dev->usb_enu.usb->USB_Connect(con); +} + +/********************************************************************************************************//** + * @brief Get ADC Configuration statue + * @param[in] dev : a point which contains all the global variables which using in this function + * @return Configuration statue +************************************************************************************************************/ +uint8_t HID_Configurated(USBHID_Dev *dev) +{ + return dev->usb_enu.USB_Configuration; +} + +/********************************************************************************************************//** + * @brief HID read,data transfer from host to device + * @param[in] dev : a point which contains all the global variables which using in this function + * rbuf : buffer of read + * len : byte length of read + * @return None +************************************************************************************************************/ +uint32_t HID_Read (USBHID_Dev *dev, uint8_t *rbuf, uint32_t len) +{ + len=dev->usb_enu.usb->USB_ReadEP(HID_OUTPUT,dev->OutReport); + if(dev->SetOutReport !=NULL) + { + dev->SetOutReport(dev->hid_device,dev->OutReport,len); + } + return len; +} + +/********************************************************************************************************//** + * @brief HID write,data transfer from device to host + * @param[in] dev : a point which contains all the global variables which using in this function + * wbuf : buffer of write + * len : byte length of write + * @return None +************************************************************************************************************/ +uint32_t HID_Write (USBHID_Dev *dev, uint8_t *wbuf, uint32_t len) +{ + if(dev->GetInReport != NULL) + { + dev->GetInReport(dev->hid_device,dev->InReport,len); + } + dev->usb_enu.usb->USB_WriteEP(HID_INPUT, dev->InReport, len); + return len; +} + + +/********************************************************************************************************//** + * @brief HID event callback setup + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +void HID_Event(USBHID_Dev *dev) +{ + dev->usb_enu.usb->USB_Event((HID_OUTPUT&0xf),(USB_Event_Handler)HID_IntOut,(void *)dev); + dev->usb_enu.usb->USB_Event((HID_INPUT &0xf),(USB_Event_Handler)HID_IntIn, (void *)dev); +} diff --git a/CoX/middleware/USB_CLASS/USB_HID/hid_callback.h b/CoX/middleware/USB_CLASS/USB_HID/hid_callback.h new file mode 100644 index 00000000..24a4f10e --- /dev/null +++ b/CoX/middleware/USB_CLASS/USB_HID/hid_callback.h @@ -0,0 +1,53 @@ +/***************************************************************************** + * U S B - H I D - C O M P O N E N T + ****************************************************************************/ +/** + * @file : hid_callback.h + * @brief : HID HID call back Definitions + * @version : 1.1 + * @date : 11. Mar. 2011 + * @author : CooCox + ****************************************************************************/ + +#ifndef __HID_CALLBACK_H__ +#define __HID_CALLBACK_H__ +#include "usb_enumerate.h" + +/********************************************************************************************************//** + * HID Number of Reports +************************************************************************************************************/ +#define HID_REPORT_NUM 1 + +/********************************************************************************************************//** + * HID call back function definition +************************************************************************************************************/ +typedef uint32_t (PFN_HID_REPORT_CALLBACK)(void *dev,uint8_t *report, uint32_t len); + +/** + * @brief USB HID Structure + */ +typedef struct +{ + USB_ENU_Dev usb_enu; + PFN_HID_REPORT_CALLBACK *GetInReport; + PFN_HID_REPORT_CALLBACK *SetOutReport; + void *hid_device; +// void *hid_para; + + uint8_t *InReport; + uint8_t *OutReport; + uint8_t HID_Protocol; + uint8_t HID_IdleTime[HID_REPORT_NUM]; +} USBHID_Dev; + +/********************************************************************************************************//** + * HID extern Functions +************************************************************************************************************/ +extern uint32_t HID_Read (USBHID_Dev *dev, uint8_t *rbuf, uint32_t len); +extern uint32_t HID_Write (USBHID_Dev *dev, uint8_t *wbuf, uint32_t len); +extern void HID_Init (USBHID_Dev *dev); +extern void HID_Connect(USBHID_Dev *dev,uint32_t con); +extern uint8_t HID_Configurated(USBHID_Dev *dev); +extern void HID_Event(USBHID_Dev *dev); + +#endif /* __HID_CALLBACK_H__ */ diff --git a/CoX/middleware/USB_CLASS/USB_HID/usb_hid.h b/CoX/middleware/USB_CLASS/USB_HID/usb_hid.h new file mode 100644 index 00000000..d1597c7f --- /dev/null +++ b/CoX/middleware/USB_CLASS/USB_HID/usb_hid.h @@ -0,0 +1,383 @@ +/***************************************************************************** + * U S B - H I D - C O M P O N E N T + ****************************************************************************/ +/** + * @file : usb_hid.h + * @brief : USB HID (Human Interface Device) Definitions + * @version : 1.1 + * @date : 11. Mar. 2011 + * @author : CooCox + ****************************************************************************/ + +#ifndef __USB_HID_H__ +#define __USB_HID_H__ + + +/********************************************************************************************************//** + * HID Subclass Codes +************************************************************************************************************/ +#define HID_SUBCLASS_NONE 0x00 /*!< NO HID SUBCLASS */ +#define HID_SUBCLASS_BOOT 0x01 + + +/********************************************************************************************************//** + * HID Protocol Codes +************************************************************************************************************/ +#define HID_PROTOCOL_NONE 0x00 +#define HID_PROTOCOL_KEYBOARD 0x01 +#define HID_PROTOCOL_MOUSE 0x02 + + +/********************************************************************************************************//** + * HID Descriptor Types +************************************************************************************************************/ +#define HID_HID_DESCRIPTOR_TYPE 0x21 /*!< Hid Description */ +#define HID_REPORT_DESCRIPTOR_TYPE 0x22 /*!< Report Description */ +#define HID_PHYSICAL_DESCRIPTOR_TYPE 0x23 /*!< Physical Description */ + + +/********************************************************************************************************//** + * HID Descriptor +************************************************************************************************************/ +typedef struct _HID_DESCRIPTOR { + uint8_t bLength; /*!< Length of Description */ + uint8_t bDescriptorType; /*!< Type of Description HID = 21H */ + uint16_t bcdHID; /*!< Version of HID */ + uint8_t bCountryCode; /*!< Country Code */ + uint8_t bNumDescriptors; /*!< Number of support's other Description */ + /* Array of one or more descriptors */ + struct _HID_DESCRIPTOR_LIST { + uint8_t bDescriptorType; /*!< Type of attached's Description */ + uint16_t wDescriptorLength; /*!< Length of all of Description */ + } __attribute__ ((packed)) DescriptorList[1]; +} __attribute__ ((packed)) HID_DESCRIPTOR; + + +/********************************************************************************************************//** + * HID Request Codes +************************************************************************************************************/ +#define HID_REQUEST_GET_REPORT 0x01 /*!< Request of Get Report */ +#define HID_REQUEST_GET_IDLE 0x02 /*!< Request of Get Idle speed */ +#define HID_REQUEST_GET_PROTOCOL 0x03 /*!< Request of Get Hid Protocol */ +#define HID_REQUEST_SET_REPORT 0x09 /*!< Request of Set Report */ +#define HID_REQUEST_SET_IDLE 0x0A /*!< Request of Set Idle speed */ +#define HID_REQUEST_SET_PROTOCOL 0x0B /*!< Request of Set Hid Protocol */ + + +/********************************************************************************************************//** + * HID Report Types +************************************************************************************************************/ +#define HID_REPORT_INPUT 0x01 /*!< Report of Hid Input */ +#define HID_REPORT_OUTPUT 0x02 /*!< Report of Hid Output */ +#define HID_REPORT_FEATURE 0x03 /*!< Report of Hid Feature */ + + +/********************************************************************************************************//** + * Usage Pages +************************************************************************************************************/ +#define HID_USAGE_PAGE_UNDEFINED 0x00 +#define HID_USAGE_PAGE_GENERIC 0x01 +#define HID_USAGE_PAGE_SIMULATION 0x02 +#define HID_USAGE_PAGE_VR 0x03 +#define HID_USAGE_PAGE_SPORT 0x04 +#define HID_USAGE_PAGE_GAME 0x05 +#define HID_USAGE_PAGE_DEV_CONTROLS 0x06 +#define HID_USAGE_PAGE_KEYBOARD 0x07 +#define HID_USAGE_PAGE_LED 0x08 +#define HID_USAGE_PAGE_BUTTON 0x09 +#define HID_USAGE_PAGE_ORDINAL 0x0A +#define HID_USAGE_PAGE_TELEPHONY 0x0B +#define HID_USAGE_PAGE_CONSUMER 0x0C +#define HID_USAGE_PAGE_DIGITIZER 0x0D +#define HID_USAGE_PAGE_UNICODE 0x10 +#define HID_USAGE_PAGE_ALPHANUMERIC 0x14 + + + + +/********************************************************************************************************//** + * Generic Desktop Page (0x01) +************************************************************************************************************/ +#define HID_USAGE_GENERIC_POINTER 0x01 +#define HID_USAGE_GENERIC_MOUSE 0x02 +#define HID_USAGE_GENERIC_JOYSTICK 0x04 +#define HID_USAGE_GENERIC_GAMEPAD 0x05 +#define HID_USAGE_GENERIC_KEYBOARD 0x06 +#define HID_USAGE_GENERIC_KEYPAD 0x07 +#define HID_USAGE_GENERIC_X 0x30 +#define HID_USAGE_GENERIC_Y 0x31 +#define HID_USAGE_GENERIC_Z 0x32 +#define HID_USAGE_GENERIC_RX 0x33 +#define HID_USAGE_GENERIC_RY 0x34 +#define HID_USAGE_GENERIC_RZ 0x35 +#define HID_USAGE_GENERIC_SLIDER 0x36 +#define HID_USAGE_GENERIC_DIAL 0x37 +#define HID_USAGE_GENERIC_WHEEL 0x38 +#define HID_USAGE_GENERIC_HATSWITCH 0x39 +#define HID_USAGE_GENERIC_COUNTED_BUFFER 0x3A +#define HID_USAGE_GENERIC_BYTE_COUNT 0x3B +#define HID_USAGE_GENERIC_MOTION_WAKEUP 0x3C +#define HID_USAGE_GENERIC_VX 0x40 +#define HID_USAGE_GENERIC_VY 0x41 +#define HID_USAGE_GENERIC_VZ 0x42 +#define HID_USAGE_GENERIC_VBRX 0x43 +#define HID_USAGE_GENERIC_VBRY 0x44 +#define HID_USAGE_GENERIC_VBRZ 0x45 +#define HID_USAGE_GENERIC_VNO 0x46 +#define HID_USAGE_GENERIC_SYSTEM_CTL 0x80 +#define HID_USAGE_GENERIC_SYSCTL_POWER 0x81 +#define HID_USAGE_GENERIC_SYSCTL_SLEEP 0x82 +#define HID_USAGE_GENERIC_SYSCTL_WAKE 0x83 +#define HID_USAGE_GENERIC_SYSCTL_CONTEXT_MENU 0x84 +#define HID_USAGE_GENERIC_SYSCTL_MAIN_MENU 0x85 +#define HID_USAGE_GENERIC_SYSCTL_APP_MENU 0x86 +#define HID_USAGE_GENERIC_SYSCTL_HELP_MENU 0x87 +#define HID_USAGE_GENERIC_SYSCTL_MENU_EXIT 0x88 +#define HID_USAGE_GENERIC_SYSCTL_MENU_SELECT 0x89 +#define HID_USAGE_GENERIC_SYSCTL_MENU_RIGHT 0x8A +#define HID_USAGE_GENERIC_SYSCTL_MENU_LEFT 0x8B +#define HID_USAGE_GENERIC_SYSCTL_MENU_UP 0x8C +#define HID_USAGE_GENERIC_SYSCTL_MENU_DOWN 0x8D + + + +/********************************************************************************************************//** + * Simulation Controls Page (0x02) +************************************************************************************************************/ +#define HID_USAGE_SIMULATION_RUDDER 0xBA +#define HID_USAGE_SIMULATION_THROTTLE 0xBB + + +/********************************************************************************************************//** + * Error "keys +************************************************************************************************************/ +#define HID_USAGE_KEYBOARD_NOEVENT 0x00 +#define HID_USAGE_KEYBOARD_ROLLOVER 0x01 +#define HID_USAGE_KEYBOARD_POSTFAIL 0x02 +#define HID_USAGE_KEYBOARD_UNDEFINED 0x03 + + +/********************************************************************************************************//** + * Letters +************************************************************************************************************/ +#define HID_USAGE_KEYBOARD_aA 0x04 +#define HID_USAGE_KEYBOARD_zZ 0x1D + + +/********************************************************************************************************//** + * Numbers +************************************************************************************************************/ +#define HID_USAGE_KEYBOARD_ONE 0x1E +#define HID_USAGE_KEYBOARD_ZERO 0x27 + +#define HID_USAGE_KEYBOARD_RETURN 0x28 +#define HID_USAGE_KEYBOARD_ESCAPE 0x29 +#define HID_USAGE_KEYBOARD_DELETE 0x2A + + +/********************************************************************************************************//** + * Funtion keys +************************************************************************************************************/ +#define HID_USAGE_KEYBOARD_F1 0x3A +#define HID_USAGE_KEYBOARD_F12 0x45 + +#define HID_USAGE_KEYBOARD_PRINT_SCREEN 0x46 + + +/********************************************************************************************************//** + * Modifier Keys +************************************************************************************************************/ +#define HID_USAGE_KEYBOARD_LCTRL 0xE0 +#define HID_USAGE_KEYBOARD_LSHFT 0xE1 +#define HID_USAGE_KEYBOARD_LALT 0xE2 +#define HID_USAGE_KEYBOARD_LGUI 0xE3 +#define HID_USAGE_KEYBOARD_RCTRL 0xE4 +#define HID_USAGE_KEYBOARD_RSHFT 0xE5 +#define HID_USAGE_KEYBOARD_RALT 0xE6 +#define HID_USAGE_KEYBOARD_RGUI 0xE7 +#define HID_USAGE_KEYBOARD_SCROLL_LOCK 0x47 +#define HID_USAGE_KEYBOARD_NUM_LOCK 0x53 +#define HID_USAGE_KEYBOARD_CAPS_LOCK 0x39 + + + +/********************************************************************************************************//** + * LED Page (0x08) +************************************************************************************************************/ +#define HID_USAGE_LED_NUM_LOCK 0x01 +#define HID_USAGE_LED_CAPS_LOCK 0x02 +#define HID_USAGE_LED_SCROLL_LOCK 0x03 +#define HID_USAGE_LED_COMPOSE 0x04 +#define HID_USAGE_LED_KANA 0x05 +#define HID_USAGE_LED_POWER 0x06 +#define HID_USAGE_LED_SHIFT 0x07 +#define HID_USAGE_LED_DO_NOT_DISTURB 0x08 +#define HID_USAGE_LED_MUTE 0x09 +#define HID_USAGE_LED_TONE_ENABLE 0x0A +#define HID_USAGE_LED_HIGH_CUT_FILTER 0x0B +#define HID_USAGE_LED_LOW_CUT_FILTER 0x0C +#define HID_USAGE_LED_EQUALIZER_ENABLE 0x0D +#define HID_USAGE_LED_SOUND_FIELD_ON 0x0E +#define HID_USAGE_LED_SURROUND_FIELD_ON 0x0F +#define HID_USAGE_LED_REPEAT 0x10 +#define HID_USAGE_LED_STEREO 0x11 +#define HID_USAGE_LED_SAMPLING_RATE_DETECT 0x12 +#define HID_USAGE_LED_SPINNING 0x13 +#define HID_USAGE_LED_CAV 0x14 +#define HID_USAGE_LED_CLV 0x15 +#define HID_USAGE_LED_RECORDING_FORMAT_DET 0x16 +#define HID_USAGE_LED_OFF_HOOK 0x17 +#define HID_USAGE_LED_RING 0x18 +#define HID_USAGE_LED_MESSAGE_WAITING 0x19 +#define HID_USAGE_LED_DATA_MODE 0x1A +#define HID_USAGE_LED_BATTERY_OPERATION 0x1B +#define HID_USAGE_LED_BATTERY_OK 0x1C +#define HID_USAGE_LED_BATTERY_LOW 0x1D +#define HID_USAGE_LED_SPEAKER 0x1E +#define HID_USAGE_LED_HEAD_SET 0x1F +#define HID_USAGE_LED_HOLD 0x20 +#define HID_USAGE_LED_MICROPHONE 0x21 +#define HID_USAGE_LED_COVERAGE 0x22 +#define HID_USAGE_LED_NIGHT_MODE 0x23 +#define HID_USAGE_LED_SEND_CALLS 0x24 +#define HID_USAGE_LED_CALL_PICKUP 0x25 +#define HID_USAGE_LED_CONFERENCE 0x26 +#define HID_USAGE_LED_STAND_BY 0x27 +#define HID_USAGE_LED_CAMERA_ON 0x28 +#define HID_USAGE_LED_CAMERA_OFF 0x29 +#define HID_USAGE_LED_ON_LINE 0x2A +#define HID_USAGE_LED_OFF_LINE 0x2B +#define HID_USAGE_LED_BUSY 0x2C +#define HID_USAGE_LED_READY 0x2D +#define HID_USAGE_LED_PAPER_OUT 0x2E +#define HID_USAGE_LED_PAPER_JAM 0x2F +#define HID_USAGE_LED_REMOTE 0x30 +#define HID_USAGE_LED_FORWARD 0x31 +#define HID_USAGE_LED_REVERSE 0x32 +#define HID_USAGE_LED_STOP 0x33 +#define HID_USAGE_LED_REWIND 0x34 +#define HID_USAGE_LED_FAST_FORWARD 0x35 +#define HID_USAGE_LED_PLAY 0x36 +#define HID_USAGE_LED_PAUSE 0x37 +#define HID_USAGE_LED_RECORD 0x38 +#define HID_USAGE_LED_ERROR 0x39 +#define HID_USAGE_LED_SELECTED_INDICATOR 0x3A +#define HID_USAGE_LED_IN_USE_INDICATOR 0x3B +#define HID_USAGE_LED_MULTI_MODE_INDICATOR 0x3C +#define HID_USAGE_LED_INDICATOR_ON 0x3D +#define HID_USAGE_LED_INDICATOR_FLASH 0x3E +#define HID_USAGE_LED_INDICATOR_SLOW_BLINK 0x3F +#define HID_USAGE_LED_INDICATOR_FAST_BLINK 0x40 +#define HID_USAGE_LED_INDICATOR_OFF 0x41 +#define HID_USAGE_LED_FLASH_ON_TIME 0x42 +#define HID_USAGE_LED_SLOW_BLINK_ON_TIME 0x43 +#define HID_USAGE_LED_SLOW_BLINK_OFF_TIME 0x44 +#define HID_USAGE_LED_FAST_BLINK_ON_TIME 0x45 +#define HID_USAGE_LED_FAST_BLINK_OFF_TIME 0x46 +#define HID_USAGE_LED_INDICATOR_COLOR 0x47 +#define HID_USAGE_LED_RED 0x48 +#define HID_USAGE_LED_GREEN 0x49 +#define HID_USAGE_LED_AMBER 0x4A +#define HID_USAGE_LED_GENERIC_INDICATOR 0x4B + + +/********************************************************************************************************//** + * Telephony Device Page (0x0B) +************************************************************************************************************/ +#define HID_USAGE_TELEPHONY_PHONE 0x01 +#define HID_USAGE_TELEPHONY_ANSWERING_MACHINE 0x02 +#define HID_USAGE_TELEPHONY_MESSAGE_CONTROLS 0x03 +#define HID_USAGE_TELEPHONY_HANDSET 0x04 +#define HID_USAGE_TELEPHONY_HEADSET 0x05 +#define HID_USAGE_TELEPHONY_KEYPAD 0x06 +#define HID_USAGE_TELEPHONY_PROGRAMMABLE_BUTTON 0x07 + + + +/********************************************************************************************************//** + * Consumer Page (0x0C) +************************************************************************************************************/ +#define HID_USAGE_CONSUMER_CONTROL 0x01 + + +/********************************************************************************************************//** + * Main Items +************************************************************************************************************/ +#define HID_Input(x) 0x81,x +#define HID_Output(x) 0x91,x +#define HID_Feature(x) 0xB1,x +#define HID_Collection(x) 0xA1,x +#define HID_EndCollection 0xC0 + + +/********************************************************************************************************//** + * Data (Input, Output, Feature) +************************************************************************************************************/ +#define HID_Data 0<<0 +#define HID_Constant 1<<0 +#define HID_Array 0<<1 +#define HID_Variable 1<<1 +#define HID_Absolute 0<<2 +#define HID_Relative 1<<2 +#define HID_NoWrap 0<<3 +#define HID_Wrap 1<<3 +#define HID_Linear 0<<4 +#define HID_NonLinear 1<<4 +#define HID_PreferredState 0<<5 +#define HID_NoPreferred 1<<5 +#define HID_NoNullPosition 0<<6 +#define HID_NullState 1<<6 +#define HID_NonVolatile 0<<7 +#define HID_Volatile 1<<7 + + +/********************************************************************************************************//** + * Collection Data +************************************************************************************************************/ +#define HID_Physical 0x00 +#define HID_Application 0x01 +#define HID_Logical 0x02 +#define HID_Report 0x03 +#define HID_NamedArray 0x04 +#define HID_UsageSwitch 0x05 +#define HID_UsageModifier 0x06 + + +/********************************************************************************************************//** + * Global Items +************************************************************************************************************/ +#define HID_UsagePage(x) 0x05,x +#define HID_UsagePageVendor(x) 0x06,x,0xFF +#define HID_LogicalMin(x) 0x15,x +#define HID_LogicalMinS(x) 0x16,(x&0xFF),((x>>8)&0xFF) +#define HID_LogicalMinL(x) 0x17,(x&0xFF),((x>>8)&0xFF),((x>>16)&0xFF),((x>>24)&0xFF) +#define HID_LogicalMax(x) 0x25,x +#define HID_LogicalMaxS(x) 0x26,(x&0xFF),((x>>8)&0xFF) +#define HID_LogicalMaxL(x) 0x27,(x&0xFF),((x>>8)&0xFF),((x>>16)&0xFF),((x>>24)&0xFF) +#define HID_PhysicalMin(x) 0x35,x +#define HID_PhysicalMinS(x) 0x36,(x&0xFF),((x>>8)&0xFF) +#define HID_PhysicalMinL(x) 0x37,(x&0xFF),((x>>8)&0xFF),((x>>16)&0xFF),((x>>24)&0xFF) +#define HID_PhysicalMax(x) 0x45,x +#define HID_PhysicalMaxS(x) 0x46,(x&0xFF),((x>>8)&0xFF) +#define HID_PhysicalMaxL(x) 0x47,(x&0xFF),((x>>8)&0xFF),((x>>16)&0xFF),((x>>24)&0xFF) +#define HID_UnitExponent(x) 0x55,x +#define HID_Unit(x) 0x65,x +#define HID_UnitS(x) 0x66,(x&0xFF),((x>>8)&0xFF) +#define HID_UnitL(x) 0x67,(x&0xFF),((x>>8)&0xFF),((x>>16)&0xFF),((x>>24)&0xFF) +#define HID_ReportSize(x) 0x75,x +#define HID_ReportID(x) 0x85,x +#define HID_ReportCount(x) 0x95,x +#define HID_Push 0xA0 +#define HID_Pop 0xB0 + + + +/********************************************************************************************************//** + * Local Items +************************************************************************************************************/ +#define HID_Usage(x) 0x09,x +#define HID_UsageMin(x) 0x19,x +#define HID_UsageMax(x) 0x29,x + + +#endif diff --git a/CoX/middleware/USB_CLASS/USB_HID/usb_hid_config.h b/CoX/middleware/USB_CLASS/USB_HID/usb_hid_config.h new file mode 100644 index 00000000..b7920d49 --- /dev/null +++ b/CoX/middleware/USB_CLASS/USB_HID/usb_hid_config.h @@ -0,0 +1,31 @@ +/***************************************************************************** + * U S B - H I D - C O M P O N E N T + ****************************************************************************/ +/** + * @file : usb_hid_config.h + * @brief : USB hid Configuration + * @version : 1.1 + * @date : 11. Mar. 2011 + * @author : CooCox + ****************************************************************************/ + + +#ifndef __USB_HID_CONFIG_H__ +#define __USB_HID_CONFIG_H__ + +/********************************************************************** + * CDC vendor ID and product ID + **********************************************************************/ +#define USB_VENDOR_ID 0x1234 // Vendor ID +#define USB_PROD_ID 0x0003 // Product ID +#define USB_DEVICE 0x0100 // Device ID +#define HID_FUNCTION HID_PROTOCOL_MOUSE /*!< hid function <0-2> */ + + +/********************************************************************** + * CDC Communication In\Out Endpoint Address + **********************************************************************/ +#define HID_INPUT 0x81 +#define HID_OUTPUT 0x02 + +#endif /* __USB_MSC_CONFIG_H__ */ diff --git a/CoX/middleware/USB_CLASS/USB_MSC/msc_callback.c b/CoX/middleware/USB_CLASS/USB_MSC/msc_callback.c new file mode 100644 index 00000000..22508292 --- /dev/null +++ b/CoX/middleware/USB_CLASS/USB_MSC/msc_callback.c @@ -0,0 +1,776 @@ + +#include "msc_callback.h" +#include + + +void MSC_SetCSW(USBMSC_Dev *dev); +void MSC_SetStallEP(USBMSC_Dev *dev,uint32_t EPNum); +void MSC_Event(USBMSC_Dev *dev); + +/********************************************************************************************************//** + * @brief USB MSC data in format + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +uint32_t DataInFormat (USBMSC_Dev *dev) +{ + + if (dev->CBW.dDataLength == 0) + { + dev->CSW.bStatus = CSW_PHASE_ERROR; + MSC_SetCSW(dev); + return (FALSE); + } + if ((dev->CBW.bmFlags & 0x80) == 0) + { + MSC_SetStallEP(dev,MSC_EP_OUT); + dev->CSW.bStatus = CSW_PHASE_ERROR; + MSC_SetCSW(dev); + return (FALSE); + } + return (TRUE); +} + +/********************************************************************************************************//** + * @brief USB MSC data in transfer + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +void DataInTransfer (USBMSC_Dev *dev) +{ + + if (dev->BulkLen >= dev->CBW.dDataLength) + { + dev->BulkLen = dev->CBW.dDataLength; + dev->BulkStage = MSC_BS_DATA_IN_LAST; + } + else + { + dev->BulkStage = MSC_BS_DATA_IN_LAST_STALL; /* short or zero packet */ + } + + xUSBEndpointWrite(MSC_EP_IN, dev->BulkBuf, dev->BulkLen); + + dev->CSW.dDataResidue -= dev->BulkLen; + dev->CSW.bStatus = CSW_CMD_PASSED; +} + +/********************************************************************************************************//** + * @brief USB MSC read write setup + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +uint32_t MSC_RWSetup (USBMSC_Dev *dev) +{ + uint32_t n; + + /* Logical Block Address of First Block */ + n = (dev->CBW.CB[2] << 24) | + (dev->CBW.CB[3] << 16) | + (dev->CBW.CB[4] << 8) | + (dev->CBW.CB[5] << 0); + + dev->Offset = n * MSC_BlockSize; + + /* Number of Blocks to transfer */ + switch (dev->CBW.CB[0]) + { + case SCSI_READ10: + case SCSI_WRITE10: + case SCSI_VERIFY10: + n = (dev->CBW.CB[7] << 8) | + (dev->CBW.CB[8] << 0); + break; + + case SCSI_READ12: + case SCSI_WRITE12: + n = (dev->CBW.CB[6] << 24) | + (dev->CBW.CB[7] << 16) | + (dev->CBW.CB[8] << 8) | + (dev->CBW.CB[9] << 0); + break; + } + + dev->Length = n * MSC_BlockSize; + + if (dev->CBW.dDataLength == 0) + { + /* host requests no data */ + dev->CSW.bStatus = CSW_CMD_FAILED; + MSC_SetCSW(dev); + return (FALSE); + } + + if (dev->CBW.dDataLength != dev->Length) + { + if ((dev->CBW.bmFlags & 0x80) != 0) + { + /* stall appropriate EP */ + MSC_SetStallEP(dev,MSC_EP_IN); + } + else + { + MSC_SetStallEP(dev,MSC_EP_IN); + } + + dev->CSW.bStatus = CSW_CMD_FAILED; + MSC_SetCSW(dev); + + return (FALSE); + } + + return (TRUE); +} + +/********************************************************************************************************//** + * @brief USB MSC get CSW + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +void MSC_SetCSW(USBMSC_Dev *dev) +{ + dev->CSW.dSignature = MSC_CSW_Signature; + xUSBEndpointWrite(MSC_EP_IN, (uint8_t *)&dev->CSW, sizeof(dev->CSW)); + dev->BulkStage = MSC_BS_CSW; +} + +/********************************************************************************************************//** + * @brief Initialization of USB MSC memory + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +void MSC_InitFlash(USBMSC_Dev *dev) +{ + dev->flash_init(dev->flash_data); +} + +/********************************************************************************************************//** + * @brief USB MSC read memory + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +void MSC_MemoryRead(USBMSC_Dev *dev) +{ + uint32_t n; + + if (dev->Length > MSC_MAX_PACKET) + { + n = MSC_MAX_PACKET; + } + else + { + n = dev->Length; + } + + if ((dev->Offset + n) > MSC_MemorySize) + { + n = MSC_MemorySize - dev->Offset; + dev->BulkStage = MSC_BS_DATA_IN_LAST_STALL; + } + if(dev->flash_read != NULL) + { + dev->flash_read(dev->flash_data, dev->Offset, dev->BulkBuf, n); + } + xUSBEndpointWrite(MSC_EP_IN, dev->BulkBuf, n); + dev->Offset += n; + dev->Length -= n; + + dev->CSW.dDataResidue -= n; + + if (dev->Length == 0) + { + dev->BulkStage = MSC_BS_DATA_IN_LAST; + } + + if (dev->BulkStage != MSC_BS_DATA_IN) + { + dev->CSW.bStatus = CSW_CMD_PASSED; + } +} + +/********************************************************************************************************//** + * @brief USB MSC write memory + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +void MSC_MemoryWrite(USBMSC_Dev *dev) +{ + if ((dev->Offset + dev->BulkLen) > MSC_MemorySize) + { + dev->BulkLen = MSC_MemorySize - dev->Offset; + dev->BulkStage = MSC_BS_CSW; + MSC_SetStallEP(dev,MSC_EP_OUT); + } + if(dev->flash_write != NULL) + { + dev->flash_write(dev->flash_data, dev->Offset, dev->BulkBuf, dev->BulkLen); + } + dev->Offset += dev->BulkLen; + dev->Length -= dev->BulkLen; + dev->CSW.dDataResidue -= dev->BulkLen; + if ((dev->Length == 0) || (dev->BulkStage == MSC_BS_CSW)) + { + dev->CSW.bStatus = CSW_CMD_PASSED; + MSC_SetCSW(dev); + + } + +} +/********************************************************************************************************//** + * @brief USB MSC verify memory + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +void MSC_MemoryVerify(USBMSC_Dev *dev) +{ + uint32_t n,MemOK; + + if ((dev->Offset + dev->BulkLen) > MSC_MemorySize) + { + dev->BulkLen = MSC_MemorySize - dev->Offset; + dev->BulkStage = MSC_BS_CSW; + MSC_SetStallEP(dev, MSC_EP_OUT); + } + if(dev->flash_read != NULL) + { + dev->flash_read(dev->flash_data, dev->Offset, dev->BulkBuf, dev->BulkLen); + } + for (n = 0; n < dev->BulkLen; n++) + { + if (dev->Memory[n] != dev->BulkBuf[n]) + { + MemOK = FALSE; + break; + } + } + + dev->Offset += dev->BulkLen; + dev->Length -= dev->BulkLen; + + dev->CSW.dDataResidue -= dev->BulkLen; + + if ((dev->Length == 0) || (dev->BulkStage == MSC_BS_CSW)) + { + dev->CSW.bStatus = (MemOK) ? CSW_CMD_PASSED : CSW_CMD_FAILED; + MSC_SetCSW(dev); + } +} + +/********************************************************************************************************//** + * @brief USB MSC set stall end point + * @param[in] dev : a point which contains all the global variables which using in this function + * EPNum : logic number of end point + * @return None +************************************************************************************************************/ +void MSC_SetStallEP(USBMSC_Dev *dev,uint32_t EPNum) +{ + + dev->usb_enu.USB_EndPointHalt |= (EPNum & 0x80) ? ((1 << 16) << (EPNum & 0x0F)) : (1 << EPNum); +} + +/********************************************************************************************************//** + * @brief USB MSC test unit ready + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +void MSC_TestUnitReady(USBMSC_Dev *dev) +{ + if (dev->CBW.dDataLength != 0) + { + if ((dev->CBW.bmFlags & 0x80) != 0) + { + MSC_SetStallEP(dev,MSC_EP_IN); + } + else + { + MSC_SetStallEP(dev,MSC_EP_OUT); + } + } + + dev->CSW.bStatus = CSW_CMD_PASSED; + MSC_SetCSW(dev); +} + +/********************************************************************************************************//** + * @brief USB MSC request sense + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +void MSC_RequestSense(USBMSC_Dev *dev) +{ + if (!DataInFormat(dev)) return; + + dev->BulkBuf[ 0] = 0x70; /* Response Code */ + dev->BulkBuf[ 1] = 0x00; + dev->BulkBuf[ 2] = 0x00;//0x02; /* Sense Key *///DIFF + dev->BulkBuf[ 3] = 0x00; + dev->BulkBuf[ 4] = 0x00; + dev->BulkBuf[ 5] = 0x00; + dev->BulkBuf[ 6] = 0x00; + dev->BulkBuf[ 7] = 0x0A; /* Additional Length */ + dev->BulkBuf[ 8] = 0x00; + dev->BulkBuf[ 9] = 0x00; + dev->BulkBuf[10] = 0x00; + dev->BulkBuf[11] = 0x00; + dev->BulkBuf[12] = 0x00;//0x30; /* ASC *///diff + dev->BulkBuf[13] = 0x00;//0x01; /* ASCQ *///diff + dev->BulkBuf[14] = 0x00; + dev->BulkBuf[15] = 0x00; + dev->BulkBuf[16] = 0x00; + dev->BulkBuf[17] = 0x00; + + dev->BulkLen = 18; + DataInTransfer(dev); +} + +/********************************************************************************************************//** + * @brief USB MSC inquiry + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +void MSC_Inquiry(USBMSC_Dev *dev) +{ + if (!DataInFormat(dev)) return; + + dev->BulkBuf[ 0] = 0x00; /* Direct Access Device */ + dev->BulkBuf[ 1] = 0x80; /* RMB = 1: Removable Medium */ + dev->BulkBuf[ 2] = 0x00; /* Version: No conformance claim to standard */ + dev->BulkBuf[ 3] = 0x01; + + dev->BulkBuf[ 4] = 36-4; /* Additional Length */ + dev->BulkBuf[ 5] = 0x80; /* SCCS = 1: Storage Controller Component */ + dev->BulkBuf[ 6] = 0x00; + dev->BulkBuf[ 7] = 0x00; + + dev->BulkBuf[ 8] = 'N'; /* Vendor Identification */ + dev->BulkBuf[ 9] = 'O'; + dev->BulkBuf[10] = 'V'; + dev->BulkBuf[11] = 'O'; + dev->BulkBuf[12] = 'T'; + dev->BulkBuf[13] = 'O'; + dev->BulkBuf[14] = 'N'; + dev->BulkBuf[15] = ' '; + + dev->BulkBuf[16] = 'N'; /* Product Identification */ + dev->BulkBuf[17] = 'U'; + dev->BulkBuf[18] = 'C'; + dev->BulkBuf[19] = '1'; + dev->BulkBuf[20] = '4'; + dev->BulkBuf[21] = 'X'; + dev->BulkBuf[22] = 'x'; + dev->BulkBuf[23] = ' '; + dev->BulkBuf[24] = 'D'; + dev->BulkBuf[25] = 'i'; + dev->BulkBuf[26] = 's'; + dev->BulkBuf[27] = 'k'; + dev->BulkBuf[28] = ' '; + dev->BulkBuf[29] = ' '; + dev->BulkBuf[30] = ' '; + dev->BulkBuf[31] = ' '; + + dev->BulkBuf[32] = '1'; /* Product Revision Level */ + dev->BulkBuf[33] = '.'; + dev->BulkBuf[34] = '0'; + dev->BulkBuf[35] = ' '; + + dev->BulkLen = 36; + DataInTransfer(dev); +} + +/********************************************************************************************************//** + * @brief USB MSC mode sense 6 + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +void MSC_ModeSense6(USBMSC_Dev *dev) +{ + if (!DataInFormat(dev)) return; + + dev->BulkBuf[ 0] = 0x03; + dev->BulkBuf[ 1] = 0x00; + dev->BulkBuf[ 2] = 0x00; + dev->BulkBuf[ 3] = 0x00; + + dev->BulkLen = 4; + DataInTransfer(dev); +} + +/********************************************************************************************************//** + * @brief USB MSC mode sense 10 + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +void MSC_ModeSense10(USBMSC_Dev *dev) +{ + + if (!DataInFormat(dev)) return; + + dev->BulkBuf[ 0] = 0x00; + dev->BulkBuf[ 1] = 0x06; + dev->BulkBuf[ 2] = 0x00; + dev->BulkBuf[ 3] = 0x00; + dev->BulkBuf[ 4] = 0x00; + dev->BulkBuf[ 5] = 0x00; + dev->BulkBuf[ 6] = 0x00; + dev->BulkBuf[ 7] = 0x00; + + dev->BulkLen = 8; + DataInTransfer(dev); +} + +/********************************************************************************************************//** + * @brief USB MSC read format capacity + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +void MSC_ReadFormatCapacity(USBMSC_Dev *dev) +{ + if (!DataInFormat(dev)) return; + + dev->BulkBuf[ 0] = 0x00; + dev->BulkBuf[ 1] = 0x00; + dev->BulkBuf[ 2] = 0x00; + dev->BulkBuf[ 3] = 0x08; /* Capacity List Length */ + + /* Block Count */ + dev->BulkBuf[ 4] = (MSC_BlockCount >> 24) & 0xFF; + dev->BulkBuf[ 5] = (MSC_BlockCount >> 16) & 0xFF; + dev->BulkBuf[ 6] = (MSC_BlockCount >> 8) & 0xFF; + dev->BulkBuf[ 7] = (MSC_BlockCount >> 0) & 0xFF; + + /* Block Length */ + dev->BulkBuf[ 8] = 0x02; /* Descriptor Code: Formatted Media */ + dev->BulkBuf[ 9] = (MSC_BlockSize >> 16) & 0xFF; + dev->BulkBuf[10] = (MSC_BlockSize >> 8) & 0xFF; + dev->BulkBuf[11] = (MSC_BlockSize >> 0) & 0xFF; + + dev->BulkLen = 12; + DataInTransfer(dev); +} + +/********************************************************************************************************//** + * @brief USB MSC read capacity + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +void MSC_ReadCapacity(USBMSC_Dev *dev) +{ + if (!DataInFormat(dev)) return; + + /* Last Logical Block */ + dev->BulkBuf[ 0] = ((MSC_BlockCount - 1) >> 24) & 0xFF; + dev->BulkBuf[ 1] = ((MSC_BlockCount - 1) >> 16) & 0xFF; + dev->BulkBuf[ 2] = ((MSC_BlockCount - 1) >> 8) & 0xFF; + dev->BulkBuf[ 3] = ((MSC_BlockCount - 1) >> 0) & 0xFF; + + /* Block Length */ + dev->BulkBuf[ 4] = (MSC_BlockSize >> 24) & 0xFF; + dev->BulkBuf[ 5] = (MSC_BlockSize >> 16) & 0xFF; + dev->BulkBuf[ 6] = (MSC_BlockSize >> 8) & 0xFF; + dev->BulkBuf[ 7] = (MSC_BlockSize >> 0) & 0xFF; + + dev->BulkLen = 8; + DataInTransfer(dev); +} + +/********************************************************************************************************//** + * @brief USB MSC get CBW + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +void MSC_GetCBW(USBMSC_Dev *dev) +{ + + uint32_t n; + + for (n = 0; n < dev->BulkLen; n++) + { + *((uint8_t *)&dev->CBW + n) = dev->BulkBuf[n]; + } + if ((dev->BulkLen == sizeof(dev->CBW)) && (dev->CBW.dSignature == MSC_CBW_Signature)) + { + /* Valid CBW */ + dev->CSW.dTag = dev->CBW.dTag; + dev->CSW.dDataResidue = dev->CBW.dDataLength; + if ((dev->CBW.bLUN != 0) || + (dev->CBW.bCBLength < 1) || + (dev->CBW.bCBLength > 16) ) + { + fail: + dev->CSW.bStatus = CSW_CMD_FAILED; + MSC_SetCSW(dev); + } + else + { + switch (dev->CBW.CB[0]) + { + case SCSI_TEST_UNIT_READY://SCSI_TEST_UNIT_READY! + MSC_TestUnitReady(dev); + break; + case SCSI_REQUEST_SENSE://SCSI_REQUEST_SENSE! + MSC_RequestSense(dev); +// printf(" SCSI_REQUEST_SENSE!\n\r"); + break; + case SCSI_FORMAT_UNIT: + goto fail; + case SCSI_INQUIRY://SCSI_INQUIRY + MSC_Inquiry(dev); + break; + case SCSI_START_STOP_UNIT: + goto fail; + case SCSI_MEDIA_REMOVAL://SCSI_MEDIA_REMOVAL! +// printf(" SCSI_MEDIA_REMOVAL!\n\r"); + dev->CSW.bStatus = CSW_CMD_PASSED; + MSC_SetCSW(dev); + break;//goto fail; + case SCSI_MODE_SELECT6: + goto fail; + case SCSI_MODE_SENSE6://SCSI_MODE_SENSE6! + MSC_ModeSense6(dev); + break; + case SCSI_MODE_SELECT10: + goto fail; + case SCSI_MODE_SENSE10: + MSC_ModeSense10(dev); + break; + case SCSI_READ_FORMAT_CAPACITIES://READ_FORMAT_CAPACITIES! + MSC_ReadFormatCapacity(dev); + break; + case SCSI_READ_CAPACITY://SCSI_READ_CAPACITY! + MSC_ReadCapacity(dev); + break; + case SCSI_READ10://SCSI_READ10! + case SCSI_READ12: +// printf(" SCSI_READ10!\n\r"); + if(MSC_RWSetup(dev)) + { + if ((dev->CBW.bmFlags & 0x80) != 0) + { + dev->BulkStage = MSC_BS_DATA_IN; + MSC_MemoryRead(dev); + } + else + { + /* direction mismatch */ + MSC_SetStallEP(dev,MSC_EP_IN); + dev->CSW.bStatus = CSW_PHASE_ERROR; + MSC_SetCSW(dev); + } + } + break; + case SCSI_WRITE10://SCSI_WRITE10! + case SCSI_WRITE12: +// printf(" SCSI_WRITE10!\n\r"); + if (MSC_RWSetup(dev)) + { + if ((dev->CBW.bmFlags & 0x80) == 0) + { + dev->BulkStage = MSC_BS_DATA_OUT; + if(dev->InitOffset!=NULL) + { + *dev->InitOffset = dev->Offset; + } + if(dev->TotalLength!=NULL) + { + *dev->TotalLength = dev->Length; + } + + } + else + { + /* direction mismatch */ + MSC_SetStallEP(dev,MSC_EP_IN); + dev->CSW.bStatus = CSW_PHASE_ERROR; + MSC_SetCSW(dev); + } + } + break; + case SCSI_VERIFY10: + if ((dev->CBW.CB[1] & 0x02) == 0) + { + dev->CSW.bStatus = CSW_CMD_PASSED; + MSC_SetCSW(dev); + break; + } + if (MSC_RWSetup(dev)) + { + if ((dev->CBW.bmFlags & 0x80) == 0) + { + dev->BulkStage = MSC_BS_DATA_OUT; + } + else + { + MSC_SetStallEP(dev,MSC_EP_IN); + dev->CSW.bStatus = CSW_PHASE_ERROR; + MSC_SetCSW(dev); + } + } + break; + default: + goto fail; + } + } + } + else + { + /* Invalid CBW */ + MSC_SetStallEP(dev,MSC_EP_IN); + /* set EP to stay stalled */ + dev->usb_enu.USB_EndPointStall |= (MSC_EP_IN & 0x80) ? ((1 << 16) << (MSC_EP_IN & 0x0F)) : (1 << MSC_EP_IN); + MSC_SetStallEP(dev,MSC_EP_IN); + /* set EP to stay stalled */ + dev->usb_enu.USB_EndPointStall |= (MSC_EP_OUT & 0x80) ? ((1 << 16) << (MSC_EP_OUT & 0x0F)) : (1 << MSC_EP_OUT); + dev->BulkStage = MSC_BS_ERROR; + } +} + +/********************************************************************************************************//** + * @brief USB MSC reset + * @param[in] dev : a point which contains all the global variables which using in this function + * Event: NULL + * @return None +************************************************************************************************************/ +uint32_t MSC_Reset(USBMSC_Dev *dev, uint32_t Event) +{ + dev->usb_enu.USB_EndPointHalt = 0x00000000; + dev->CSW.dSignature = 0; + dev->BulkStage = MSC_BS_CBW; + + return (TRUE); +} + +/********************************************************************************************************//** + * @brief USB MSC get max LUN + * @param[in] dev : a point which contains all the global variables which using in this function + * Event: NULL + * @return None +************************************************************************************************************/ +uint32_t MSC_GetMaxLUN(USBMSC_Dev *dev, uint32_t Event) +{ + dev->usb_enu.EP0Buf[0] = 0; /* No LUN associated with this device */ + MSC_Event(dev); + return (TRUE); +} + +/********************************************************************************************************//** + * @brief Initialization of the USB MSC + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +void MSC_Open(USBMSC_Dev *dev) +{ + //dev->di_usb_e = &di_usb_enumerate; + dev->usb_enu.msc_data = dev; + dev->usb_enu.g_pfn_msc_request_reset = (PFN_MSC_CALLBACK *)MSC_Reset; + dev->usb_enu.g_pfn_msc_request_get_max_lun = (PFN_MSC_CALLBACK *)MSC_GetMaxLUN; + + if(dev->flash_init != NULL) + { + dev->flash_init(dev->flash_data); + } + USB_Init(&dev->usb_enu); +} + +/********************************************************************************************************//** + * @brief Connect MSC to the host + * @param[in] dev : a point which contains all the global variables which using in this function + * con : TRUE \FALSE + * @return None +************************************************************************************************************/ +void MSC_Connect(USBMSC_Dev *dev,uint32_t con) +{ + xUSBConnect(con); +} + +/********************************************************************************************************//** + * @brief Get MSC Configuration statue + * @param[in] dev : a point which contains all the global variables which using in this function + * @return Configuration statue +************************************************************************************************************/ +uint8_t MSC_Configurated(USBMSC_Dev *dev) +{ + return dev->usb_enu.USB_Configuration; +} + + +/********************************************************************************************************//** + * @brief MSC bulk in handle + * @param[in] dev : a point which contains all the global variables which using in this function + * event : event type of endpoint + * @return None +************************************************************************************************************/ +void bulk_in_handle(USBMSC_Dev *dev,uint32_t Event, + unsigned long ulMsgParam, + void *pvMsgData) +{ + switch (dev->BulkStage) + { + case MSC_BS_DATA_IN: + switch (dev->CBW.CB[0]) + { + case SCSI_READ10: + case SCSI_READ12: + MSC_MemoryRead(dev); + break; + } + break; + case MSC_BS_DATA_IN_LAST: + MSC_SetCSW(dev); + break; + case MSC_BS_DATA_IN_LAST_STALL: + MSC_SetStallEP(dev,MSC_EP_OUT); + MSC_SetCSW(dev); + break; + case MSC_BS_CSW: + dev->BulkStage = MSC_BS_CBW; + break; + } +} +/********************************************************************************************************//** + * @brief MSC bulk out handle + * @param[in] dev : a point which contains all the global variables which using in this function + * event : event type of endpoint + * @return None +************************************************************************************************************/ +void bulk_out_handle(USBMSC_Dev *dev,uint32_t Event, + unsigned long ulMsgParam, + void *pvMsgData) +{ + dev->BulkLen = xUSBEndpointRead(MSC_EP_OUT, dev->BulkBuf); + switch (dev->BulkStage) + { + case MSC_BS_CBW: + MSC_GetCBW(dev); + break; + case MSC_BS_DATA_OUT: + switch (dev->CBW.CB[0]) + { + case SCSI_WRITE10: + case SCSI_WRITE12: + MSC_MemoryWrite(dev); + break; + case SCSI_VERIFY10: + MSC_MemoryVerify(dev); + break; + } + break; + default: + MSC_SetStallEP(dev,MSC_EP_OUT); + dev->CSW.bStatus = CSW_PHASE_ERROR; + MSC_SetCSW(dev); + break; + } +} + +/********************************************************************************************************//** + * @brief MSC event callback setup + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +void MSC_Event(USBMSC_Dev *dev) +{ + xUSBEventHandler((MSC_EP_OUT&0xf),(xtEventCallback)bulk_out_handle,(void *)dev); + xUSBEventHandler((MSC_EP_IN &0xf),(xtEventCallback)bulk_in_handle, (void *)dev); +} + + diff --git a/CoX/middleware/USB_CLASS/USB_MSC/msc_callback.h b/CoX/middleware/USB_CLASS/USB_MSC/msc_callback.h new file mode 100644 index 00000000..3601cfb5 --- /dev/null +++ b/CoX/middleware/USB_CLASS/USB_MSC/msc_callback.h @@ -0,0 +1,58 @@ +/***************************************************************************** + * U S B - M S C - C O M P O N E N T + ****************************************************************************/ +/** + * @file : msc_callback.h + * @brief : Mass Storage Class call back Definitions + * @version : 1.0 + * @date : 28. Dec. 2010 + * @author : CooCox + ****************************************************************************/ + +#ifndef __MSC_CALLBACK_H__ +#define __MSC_CALLBACK_H__ +#include "usb_enumerate.h" + +/*********************************************************************** + * USB MSC call back function definition + **********************************************************************/ +typedef uint32_t (PFN_FLASH_Init_CALLBACK) (void *dev); +typedef uint32_t (PFN_FLASH_READ_CALLBACK) (void *dev, uint32_t addr, uint8_t *rbuf, uint32_t rlen); +typedef uint32_t (PFN_FLASH_WRITE_CALLBACK)(void *dev, uint32_t addr, uint8_t *wbuf, uint32_t wlen); +typedef uint32_t (PFN_FLASH_ERASE_CALLBACK)(void *dev, uint32_t addr); + + +/** + * @brief USB MSC Structure + */ +typedef struct +{ + USB_ENU_Dev usb_enu; + + PFN_FLASH_Init_CALLBACK *flash_init; + PFN_FLASH_READ_CALLBACK *flash_read; + PFN_FLASH_WRITE_CALLBACK *flash_write; + uint32_t *TotalLength; /* R/W Length */ + uint32_t *InitOffset; /* R/W Offset */ + void *flash_data; + + MSC_CBW CBW; /* Command Block Wrapper */ + MSC_CSW CSW; /* Command Status Wrapper */ + uint8_t BulkStage; /* Bulk Stage */ + uint8_t BulkBuf[MSC_MAX_PACKET]; /* Bulk In/Out Buffer */ + uint8_t BulkLen; /* Bulk In/Out Length */ + uint32_t Length; /* R/W Length */ + + uint32_t Offset; /* R/W Offset */ + uint8_t Memory[65]; +} USBMSC_Dev; + +/*********************************************************************** + * extern API of this component + **********************************************************************/ +extern void MSC_Open(USBMSC_Dev *dev); +extern void MSC_Connect(USBMSC_Dev *dev,uint32_t con); +extern uint8_t MSC_Configurated(USBMSC_Dev *dev); +extern void MSC_Event(USBMSC_Dev *dev); + +#endif /* __MSC_CALLBACK_H__ */ diff --git a/CoX/middleware/USB_CLASS/USB_MSC/usb_msc.h b/CoX/middleware/USB_CLASS/USB_MSC/usb_msc.h new file mode 100644 index 00000000..0deb2f44 --- /dev/null +++ b/CoX/middleware/USB_CLASS/USB_MSC/usb_msc.h @@ -0,0 +1,149 @@ +/***************************************************************************** + * U S B - M S C - C O M P O N E N T + ****************************************************************************/ +/** + * @file : usb_msc.h + * @brief : USB Mass Storage Class Definitions + * @version : 1.0 + * @date : 28. Dec. 2010 + * @author : CooCox + ****************************************************************************/ + +#ifndef __USB_MSC_H__ +#define __USB_MSC_H__ + + +/*********************************************************************** + * MSC Subclass Codes + **********************************************************************/ +#define MSC_SUBCLASS_RBC 0x01 +#define MSC_SUBCLASS_SFF8020I_MMC2 0x02 +#define MSC_SUBCLASS_QIC157 0x03 +#define MSC_SUBCLASS_UFI 0x04 +#define MSC_SUBCLASS_SFF8070I 0x05 +#define MSC_SUBCLASS_SCSI 0x06 +#define MSC_SUBCLASS_LSD_FS 0x07 +#define MSC_SUBCLASS_IEEE_1667 0x08 + +/*********************************************************************** + * MSC Protocol Codes + **********************************************************************/ +#define MSC_PROTOCOL_CBI_INT 0x00 +#define MSC_PROTOCOL_CBI_NOINT 0x01 +#define MSC_PROTOCOL_OBSKLETE 0x02 +#define MSC_PROTOCOL_BULK_ONLY 0x50 +#define MSC_PROTOCOL_UAS 0x62 + +/*********************************************************************** + * MSC Request Codes + **********************************************************************/ +#define MSC_REQUEST_ADSC 0x00 +#define MSC_REQUEST_GET_REQ 0xFC +#define MSC_REQUEST_PUT_REQ 0xFD +#define MSC_REQUEST_RESET 0xFF +#define MSC_REQUEST_GET_MAX_LUN 0xFE + +/*********************************************************************** + * MSC Bulk-only Stage + **********************************************************************/ +#define MSC_BS_CBW 0 /* Command Block Wrapper */ +#define MSC_BS_DATA_OUT 1 /* Data Out Phase */ +#define MSC_BS_DATA_IN 2 /* Data In Phase */ +#define MSC_BS_DATA_IN_LAST 3 /* Data In Last Phase */ +#define MSC_BS_DATA_IN_LAST_STALL 4 /* Data In Last Phase with Stall */ +#define MSC_BS_CSW 5 /* Command Status Wrapper */ +#define MSC_BS_ERROR 6 /* Error */ + + +/** + * @brief Bulk-only Command Block Wrapper + */ +typedef struct _MSC_CBW { + uint32_t dSignature; + uint32_t dTag; + uint32_t dDataLength; + uint8_t bmFlags; + uint8_t bLUN; + uint8_t bCBLength; + uint8_t CB[16]; +} __attribute__((packed)) MSC_CBW; + + +/** + * @brief Bulk-only Command Status Wrapper + */ +typedef struct _MSC_CSW { + uint32_t dSignature; + uint32_t dTag; + uint32_t dDataResidue; + uint8_t bStatus; +} __attribute__((packed)) MSC_CSW; + +#define MSC_CBW_Signature 0x43425355 +#define MSC_CSW_Signature 0x53425355 + +/*********************************************************************** + * CSW Status Definitions + **********************************************************************/ +#define CSW_CMD_PASSED 0x00 +#define CSW_CMD_FAILED 0x01 +#define CSW_PHASE_ERROR 0x02 + +/*********************************************************************** + * SCSI Commands + **********************************************************************/ +#define SCSI_TEST_UNIT_READY 0x00 +#define SCSI_REQUEST_SENSE 0x03 +#define SCSI_FORMAT_UNIT 0x04 +#define SCSI_INQUIRY 0x12 +#define SCSI_MODE_SELECT6 0x15 +#define SCSI_MODE_SENSE6 0x1A +#define SCSI_START_STOP_UNIT 0x1B +#define SCSI_MEDIA_REMOVAL 0x1E +#define SCSI_READ_FORMAT_CAPACITIES 0x23 +#define SCSI_READ_CAPACITY 0x25 +#define SCSI_READ10 0x28 +#define SCSI_WRITE10 0x2A +#define SCSI_VERIFY10 0x2F +#define SCSI_READ12 0xA8 +#define SCSI_WRITE12 0xAA +#define SCSI_MODE_SELECT10 0x55 +#define SCSI_MODE_SENSE10 0x5A + +/*********************************************************************** + * UFI Commands + **********************************************************************/ +#define UFI_TEST_UNIT_READY 0x00 +#define UFI_REZORE_UNIT 0x01 +#define UFI_REQUEST_SENSE 0x03 +#define UFI_FORMAT_UNIT 0x04 +#define UFI_INQUIRY 0x12 +#define UFI_START_STOP_UNIT 0x1B +#define UFI_SEND_DIAGNOSTIC 0x1D +#define UFI_MEDIA_REMOVAL 0x1E +#define UFI_READ_FORMAT_CAPACITIES 0x23 +#define UFI_READ_CAPACITY 0x25 +#define UFI_READ10 0x28 +#define UFI_WRITE10 0x2A +#define UFI_SEEK10 0x2B +#define UFI_WRITE1_VERIFY 0x2E +#define UFI_VERIFY 0x2F +#define UFI_READ12 0xA8 +#define UFI_WRITE12 0xAA +#define UFI_MODE_SELECT 0x55 +#define UFI_MODE_SENSE 0x5A + +/*********************************************************************** + * Assigned wValue Codes + **********************************************************************/ +#define MSC_REQ_GLI 0x00 +#define MSC_REQ_SPO 0x01 +#define MSC_REQ_MPO 0x02 +#define MSC_REQ_CPO 0x03 +#define MSC_REQ_EPO 0x04 +#define MSC_REQ_EFP 0x05 +#define MSC_REQ_LA 0x06 +#define MSC_REQ_CIAO 0x07 + + +#endif /* __USB_MSC_H__ */ diff --git a/CoX/middleware/USB_CLASS/USB_MSC/usb_msc_config.h b/CoX/middleware/USB_CLASS/USB_MSC/usb_msc_config.h new file mode 100644 index 00000000..e34e2338 --- /dev/null +++ b/CoX/middleware/USB_CLASS/USB_MSC/usb_msc_config.h @@ -0,0 +1,38 @@ +/***************************************************************************** + * U S B - M S C - C O M P O N E N T + ****************************************************************************/ +/** + * @file : usb_msc_config.h + * @brief : USB Custom Configuration + * @version : 1.0 + * @date : 28. Dec. 2010 + * @author : CooCox + ****************************************************************************/ + + +#ifndef __USB_MSC_CONFIG_H__ +#define __USB_MSC_CONFIG_H__ + +/*********************************************************************** + * Mass Storage Memory Layout + **********************************************************************/ +#define MSC_MemorySize 2048*1024 +#define MSC_BlockSize 512 +#define MSC_BlockCount (MSC_MemorySize / MSC_BlockSize) + +/*********************************************************************** + * MSC In/Out Endpoint Logic Address + **********************************************************************/ +#define MSC_EP_IN 0x81 +#define MSC_EP_OUT 0x02 + +/*********************************************************************** + * Max In/Out Packet Size + **********************************************************************/ +#define MSC_MAX_PACKET 64 +#define USB_VENDOR_ID 0x1FC9 // Vendor ID +#define USB_PROD_ID 0x0003 // Product ID +#define USB_DEVICE 0x0100 // Device ID + + +#endif /* __USB_MSC_CONFIG_H__ */ diff --git a/CoX/middleware/USB_ENUMERATE/type.h b/CoX/middleware/USB_ENUMERATE/type.h new file mode 100644 index 00000000..52847a83 --- /dev/null +++ b/CoX/middleware/USB_ENUMERATE/type.h @@ -0,0 +1,54 @@ +/***************************************************************************** + * U S B - C O M M O M - C O M P O N E N T + ****************************************************************************/ +/** + * @file : type.h + * @brief : Type definition Header file for NOVOTON Family + * Microprocessors + * @version : 1.0 + * @date : 28. Dec. 2010 + * @author : CooCox + ****************************************************************************/ +#ifndef __TYPE_H__ +#define __TYPE_H__ + +/********************************************************************** + * CodeRed - ifdef for GNU added to avoid potential clash with stdint.h + **********************************************************************/ +#if defined ( __GNUC__ ) +#include +#else + +/********************************************************************** + * exact-width signed integer types + **********************************************************************/ + +typedef signed char int8_t; +typedef signed short int int16_t; +typedef signed int int32_t; +typedef signed __int64 int64_t; + +/********************************************************************** + * exact-width unsigned integer types + **********************************************************************/ + +typedef unsigned char uint8_t; +typedef unsigned short int uint16_t; +typedef unsigned int uint32_t; +typedef unsigned __int64 uint64_t; + +#endif /* __GNUC__ */ + +#ifndef NULL +#define NULL ((void *)0) +#endif + +#ifndef FALSE +#define FALSE (0) +#endif + +#ifndef TRUE +#define TRUE (1) +#endif + +#endif /* __TYPE_H__ */ diff --git a/CoX/middleware/USB_ENUMERATE/usb.h b/CoX/middleware/USB_ENUMERATE/usb.h new file mode 100644 index 00000000..fc96d901 --- /dev/null +++ b/CoX/middleware/USB_ENUMERATE/usb.h @@ -0,0 +1,265 @@ +/***************************************************************************** + * U S B - C O M M O M - C O M P O N E N T + ****************************************************************************/ +/** + * @file : usb.h + * @brief : USB Definitions + * @version : 1.0 + * @date : 28. Dec. 2010 + * @author : CooCox + ****************************************************************************/ + +#ifndef __USB_H__ +#define __USB_H__ +#include "type.h" +/** + * @brief word to byte union + */ +typedef union +{ + uint16_t W; + struct + { + uint8_t L; + uint8_t H; + } __attribute__((packed)) WB; +} __attribute__((packed)) WORD_BYTE; + + +/*********************************************************************** + * bmRequestType.Dir + **********************************************************************/ +#define REQUEST_HOST_TO_DEVICE 0 +#define REQUEST_DEVICE_TO_HOST 1 + +/*********************************************************************** + * bmRequestType.Type + **********************************************************************/ +#define REQUEST_STANDARD 0 +#define REQUEST_CLASS 1 +#define REQUEST_VENDOR 2 +#define REQUEST_RESERVED 3 + +/*********************************************************************** + * bmRequestType.Recipient + **********************************************************************/ +#define REQUEST_TO_DEVICE 0 +#define REQUEST_TO_INTERFACE 1 +#define REQUEST_TO_ENDPOINT 2 +#define REQUEST_TO_OTHER 3 + + +/** + * @brief bmRequestType union Definition + */ +typedef union _REQUEST_TYPE +{ + struct _BM + { + uint8_t Recipient : 5; + uint8_t Type : 2; + uint8_t Dir : 1; + } __attribute__((packed)) BM; + uint8_t B; +} __attribute__((packed)) REQUEST_TYPE; + +/*********************************************************************** + * USB Standard Request Codes + **********************************************************************/ +#define USB_REQUEST_GET_STATUS 0 +#define USB_REQUEST_CLEAR_FEATURE 1 +#define USB_REQUEST_SET_FEATURE 3 +#define USB_REQUEST_SET_ADDRESS 5 +#define USB_REQUEST_GET_DESCRIPTOR 6 +#define USB_REQUEST_SET_DESCRIPTOR 7 +#define USB_REQUEST_GET_CONFIGURATION 8 +#define USB_REQUEST_SET_CONFIGURATION 9 +#define USB_REQUEST_GET_INTERFACE 10 +#define USB_REQUEST_SET_INTERFACE 11 +#define USB_REQUEST_SYNC_FRAME 12 + + +/*********************************************************************** + * USB GET_STATUS Bit Values + **********************************************************************/ +#define USB_GETSTATUS_SELF_POWERED 0x01 +#define USB_GETSTATUS_REMOTE_WAKEUP 0x02 +#define USB_GETSTATUS_ENDPOINT_STALL 0x01 + +/*********************************************************************** + * USB Standard Feature selectors + **********************************************************************/ +#define USB_FEATURE_ENDPOINT_STALL 0 +#define USB_FEATURE_REMOTE_WAKEUP 1 + +/** + * @brief USB Default Control Pipe Setup Packet + */ +typedef struct _USB_SETUP_PACKET { + REQUEST_TYPE bmRequestType; + uint8_t bRequest; + WORD_BYTE wValue; + WORD_BYTE wIndex; + uint16_t wLength; +} __attribute__((packed)) USB_SETUP_PACKET; + + +/*********************************************************************** + * USB Descriptor Types + **********************************************************************/ +#define USB_DEVICE_DESCRIPTOR_TYPE 1 +#define USB_CONFIGURATION_DESCRIPTOR_TYPE 2 +#define USB_STRING_DESCRIPTOR_TYPE 3 +#define USB_INTERFACE_DESCRIPTOR_TYPE 4 +#define USB_ENDPOINT_DESCRIPTOR_TYPE 5 +#define USB_DEVICE_QUALIFIER_DESCRIPTOR_TYPE 6 +#define USB_OTHER_SPEED_CONFIG_DESCRIPTOR_TYPE 7 +#define USB_INTERFACE_POWER_DESCRIPTOR_TYPE 8 +#define USB_OTG_DESCRIPTOR_TYPE 9 +#define USB_DEBUG_DESCRIPTOR_TYPE 10 +#define USB_INTERFACE_ASSOCIATION_DESCRIPTOR_TYPE 11 + + +/*********************************************************************** + * USB Device Classes + **********************************************************************/ +#define USB_DEVICE_CLASS_RESERVED 0x00 +#define USB_DEVICE_CLASS_AUDIO 0x01 +#define USB_DEVICE_CLASS_COMMUNICATIONS 0x02 +#define USB_DEVICE_CLASS_HUMAN_INTERFACE 0x03 +#define USB_DEVICE_CLASS_MONITOR 0x04 +#define USB_DEVICE_CLASS_PHYSICAL_INTERFACE 0x05 +#define USB_DEVICE_CLASS_POWER 0x06 +#define USB_DEVICE_CLASS_PRINTER 0x07 +#define USB_DEVICE_CLASS_STORAGE 0x08 +#define USB_DEVICE_CLASS_HUB 0x09 +#define USB_DEVICE_CLASS_MISCELLANEOUS 0xEF +#define USB_DEVICE_CLASS_VENDOR_SPECIFIC 0xFF + + +/*********************************************************************** + * bmAttributes in Configuration Descriptor + **********************************************************************/ +#define USB_CONFIG_POWERED_MASK 0x40 +#define USB_CONFIG_BUS_POWERED 0x80 +#define USB_CONFIG_SELF_POWERED 0xC0 +#define USB_CONFIG_REMOTE_WAKEUP 0x20 + +/*********************************************************************** + * bMaxPower in Configuration Descriptor + **********************************************************************/ +#define USB_CONFIG_POWER_MA(mA) ((mA)/2) + +/*********************************************************************** + * bEndpointAddress in Endpoint Descriptor + **********************************************************************/ +#define USB_ENDPOINT_DIRECTION_MASK 0x80 +#define USB_ENDPOINT_OUT(addr) ((addr) | 0x00) +#define USB_ENDPOINT_IN(addr) ((addr) | 0x80) + +/*********************************************************************** + * bmAttributes in Endpoint Descriptor + **********************************************************************/ +#define USB_ENDPOINT_TYPE_MASK 0x03 +#define USB_ENDPOINT_TYPE_CONTROL 0x00 +#define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01 +#define USB_ENDPOINT_TYPE_BULK 0x02 +#define USB_ENDPOINT_TYPE_INTERRUPT 0x03 +#define USB_ENDPOINT_SYNC_MASK 0x0C +#define USB_ENDPOINT_SYNC_NO_SYNCHRONIZATION 0x00 +#define USB_ENDPOINT_SYNC_ASYNCHRONOUS 0x04 +#define USB_ENDPOINT_SYNC_ADAPTIVE 0x08 +#define USB_ENDPOINT_SYNC_SYNCHRONOUS 0x0C +#define USB_ENDPOINT_USAGE_MASK 0x30 +#define USB_ENDPOINT_USAGE_DATA 0x00 +#define USB_ENDPOINT_USAGE_FEEDBACK 0x10 +#define USB_ENDPOINT_USAGE_IMPLICIT_FEEDBACK 0x20 +#define USB_ENDPOINT_USAGE_RESERVED 0x30 + + +/** + * @brief USB Standard Device Descriptor + */ +typedef struct _USB_DEVICE_DESCRIPTOR { + uint8_t bLength; + uint8_t bDescriptorType; + uint16_t bcdUSB; + uint8_t bDeviceClass; + uint8_t bDeviceSubClass; + uint8_t bDeviceProtocol; + uint8_t bMaxPacketSize0; + uint16_t idVendor; + uint16_t idProduct; + uint16_t bcdDevice; + uint8_t iManufacturer; + uint8_t iProduct; + uint8_t iSerialNumber; + uint8_t bNumConfigurations; +} __attribute__((packed)) USB_DEVICE_DESCRIPTOR; + + +/** + * @brief USB 2.0 Device Qualifier Descriptor + */ +typedef struct _USB_DEVICE_QUALIFIER_DESCRIPTOR { + uint8_t bLength; + uint8_t bDescriptorType; + uint16_t bcdUSB; + uint8_t bDeviceClass; + uint8_t bDeviceSubClass; + uint8_t bDeviceProtocol; + uint8_t bMaxPacketSize0; + uint8_t bNumConfigurations; + uint8_t bReserved; +} __attribute__((packed)) USB_DEVICE_QUALIFIER_DESCRIPTOR; + +/** + * @brief USB Standard Configuration Descriptor + */ +typedef struct _USB_CONFIGURATION_DESCRIPTOR { + uint8_t bLength; + uint8_t bDescriptorType; + uint16_t wTotalLength; + uint8_t bNumInterfaces; + uint8_t bConfigurationValue; + uint8_t iConfiguration; + uint8_t bmAttributes; + uint8_t bMaxPower; +} __attribute__((packed)) USB_CONFIGURATION_DESCRIPTOR; + + +/** + * @brief USB Standard Interface Descriptor + */ +typedef struct _USB_INTERFACE_DESCRIPTOR { + uint8_t bLength; + uint8_t bDescriptorType; + uint8_t bInterfaceNumber; + uint8_t bAlternateSetting; + uint8_t bNumEndpoints; + uint8_t bInterfaceClass; + uint8_t bInterfaceSubClass; + uint8_t bInterfaceProtocol; + uint8_t iInterface; +} __attribute__((packed)) USB_INTERFACE_DESCRIPTOR; + + +/** + * @brief USB String Descriptor + */ +typedef struct _USB_STRING_DESCRIPTOR { + uint8_t bLength; + uint8_t bDescriptorType; + uint16_t bString/*[]*/; +} __attribute__((packed)) USB_STRING_DESCRIPTOR; + +/** + * @brief USB Common Descriptor + */ +typedef struct _USB_COMMON_DESCRIPTOR { + uint8_t bLength; + uint8_t bDescriptorType; +} __attribute__((packed)) USB_COMMON_DESCRIPTOR; + + +#endif /* __USB_H__ */ diff --git a/CoX/middleware/USB_ENUMERATE/usb_Enumerate.c b/CoX/middleware/USB_ENUMERATE/usb_Enumerate.c new file mode 100644 index 00000000..b06d753c --- /dev/null +++ b/CoX/middleware/USB_ENUMERATE/usb_Enumerate.c @@ -0,0 +1,1852 @@ +/***************************************************************************** + * U S B - C O M M O M - C O M P O N E N T + ****************************************************************************/ +/** + * @file : usb_Enumerate.c + * @brief : USB Enumerate Module + * @version : 1.1 + * @date : 3. Mar. 2011 + * @author : CooCox + ****************************************************************************/ +#include "usb_enumerate.h" + +/********************************************************************************************************//** + * @brief Reset USB Core + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +void USB_ResetCore (USB_ENU_Dev *dev) +{ + + dev->USB_DeviceStatus = 0; + dev->USB_DeviceAddress = 0; + dev->USB_Configuration = 0; + dev->USB_EndPointMask = 0x00010001; + dev->USB_EndPointHalt = 0x00000000; + dev->USB_EndPointStall = 0x00000000; +} +/********************************************************************************************************//** + * @brief USB Request - Setup Stage + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +void USB_SetupStage (USB_ENU_Dev *dev) +{ + xUSBEndpointRead(0x00, (uint8_t *)&(dev->SetupPacket)); +} + +/********************************************************************************************************//** + * @brief USB Request - Data In Stage + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +void USB_DataInStage (USB_ENU_Dev *dev) +{ + uint32_t cnt; + + if (dev->EP0Data.Count > USB_MAX_PACKET0) + { + cnt = USB_MAX_PACKET0; + } else + { + cnt = dev->EP0Data.Count; + } + cnt = xUSBEndpointWrite(0x80, dev->EP0Data.pData, cnt); + dev->EP0Data.pData += cnt; + dev->EP0Data.Count -= cnt; +} + +/********************************************************************************************************//** + * @brief USB Request - Data Out Stage + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +void USB_DataOutStage (USB_ENU_Dev *dev) +{ + uint32_t cnt; + + cnt = xUSBEndpointRead(0x00, dev->EP0Data.pData); + dev->EP0Data.pData += cnt; + dev->EP0Data.Count -= cnt; +} + +/********************************************************************************************************//** + * @brief USB Request - Status In Stage + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +void USB_StatusInStage (USB_ENU_Dev *dev) +{ + xUSBEndpointWrite(0x80, NULL, 0); +} + +/********************************************************************************************************//** + * @brief USB Request - Status Out Stage + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +void USB_StatusOutStage (USB_ENU_Dev *dev) +{ + xUSBEndpointRead(0x00, dev->EP0Buf); +} + +/********************************************************************************************************//** + * @brief Get Status USB Request + * @param[in] dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +__inline uint32_t USB_ReqGetStatus (USB_ENU_Dev *dev) +{ + uint32_t n, m; + + switch (dev->SetupPacket.bmRequestType.BM.Recipient) + { + case REQUEST_TO_DEVICE: + dev->EP0Data.pData = (uint8_t *)&(dev->USB_DeviceStatus); + break; + case REQUEST_TO_INTERFACE: + if ((dev->USB_Configuration != 0) && (dev->SetupPacket.wIndex.WB.L < dev->USB_NumInterfaces)) + { + *((uint16_t __attribute__((packed)) *)dev->EP0Buf) = 0; + dev->EP0Data.pData = dev->EP0Buf; + } + else + { + return (FALSE); + } + break; + case REQUEST_TO_ENDPOINT: + n = dev->SetupPacket.wIndex.WB.L & 0x8F; + m = (n & 0x80) ? ((1 << 16) << (n & 0x0F)) : (1 << n); + if (((dev->USB_Configuration != 0) || ((n & 0x0F) == 0)) && (dev->USB_EndPointMask & m)) + { + *((uint16_t __attribute__((packed)) *)dev->EP0Buf) = (dev->USB_EndPointHalt & m) ? 1 : 0; + dev->EP0Data.pData = dev->EP0Buf; + } + else + { + return (FALSE); + } + break; + default: + return (FALSE); + } + return (TRUE); +} + +/********************************************************************************************************//** + * @brief Set/Clear Feature USB Request + * @param[in] dev : a point which contains all the global variables which using in this function + * @param[in] sc: 0 - Clear, + * 1 - Set + * (global SetupPacket) + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +__inline uint32_t USB_ReqSetClrFeature (USB_ENU_Dev *dev, uint32_t sc) +{ + uint32_t n, m; + + switch (dev->SetupPacket.bmRequestType.BM.Recipient) + { + case REQUEST_TO_DEVICE: + if (dev->SetupPacket.wValue.W == USB_FEATURE_REMOTE_WAKEUP) + { + if (sc) + { + xUSBWakeUpEnable(); + dev->USB_DeviceStatus |= USB_GETSTATUS_REMOTE_WAKEUP; + } + else + { + xUSBWakeUpDisable(); + dev->USB_DeviceStatus &= ~USB_GETSTATUS_REMOTE_WAKEUP; + } + } + else + { + return (FALSE); + } + break; + case REQUEST_TO_INTERFACE: + return (FALSE); + case REQUEST_TO_ENDPOINT: + n = dev->SetupPacket.wIndex.WB.L & 0x8F; + m = (n & 0x80) ? ((1 << 16) << (n & 0x0F)) : (1 << n); + if ((dev->USB_Configuration != 0) && ((n & 0x0F) != 0) && (dev->USB_EndPointMask & m)) + { + if (dev->SetupPacket.wValue.W == USB_FEATURE_ENDPOINT_STALL) + { + if (sc) + { + xUSBEndpointStallSet(n); + dev->USB_EndPointHalt |= m; + } + else + { + if ((dev->USB_EndPointStall & m) != 0) + { + return (TRUE); + } + xUSBEndpointStallClear(n); +#if (USB_MSC) + if ((n == MSC_EP_IN) && ((dev->USB_EndPointHalt & m) != 0)) + { + /* Compliance Test: rewrite CSW after unstall */ +// if (CSW.dSignature == MSC_CSW_Signature) +// { +// xUSBEndpointWrite(MSC_EP_IN, (uint8_t *)&CSW, sizeof(CSW)); +// } + } +#endif + dev->USB_EndPointHalt &= ~m; + } + } + else + { + return (FALSE); + } + } + else + { + return (FALSE); + } + break; + default: + return (FALSE); + } + return (TRUE); +} + +/********************************************************************************************************//** + * @brief Set Address USB Request + * @param[in] dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +__inline uint32_t USB_ReqSetAddress (USB_ENU_Dev *dev) +{ + + switch (dev->SetupPacket.bmRequestType.BM.Recipient) + { + case REQUEST_TO_DEVICE: + dev->USB_DeviceAddress = 0x80 | dev->SetupPacket.wValue.WB.L; + break; + default: + return (FALSE); + } + return (TRUE); +} + +/********************************************************************************************************//** + * @brief Get Descriptor USB Request + * @param[in] dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +__inline uint32_t USB_ReqGetDescriptor (USB_ENU_Dev *dev) +{ + uint8_t *pD; + uint32_t len, n; + + switch (dev->SetupPacket.bmRequestType.BM.Recipient) + { + case REQUEST_TO_DEVICE: + switch (dev->SetupPacket.wValue.WB.H) + { + case USB_DEVICE_DESCRIPTOR_TYPE: + dev->EP0Data.pData = (uint8_t *)dev->USB_DeviceDescriptor; + len = USB_DEVICE_DESC_SIZE; + break; + case USB_CONFIGURATION_DESCRIPTOR_TYPE: + pD = (uint8_t *)dev->USB_ConfigDescriptor; + for (n = 0; n != dev->SetupPacket.wValue.WB.L; n++) + { + if (((USB_CONFIGURATION_DESCRIPTOR *)pD)->bLength != 0) + { + pD += ((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength; + } + } + if (((USB_CONFIGURATION_DESCRIPTOR *)pD)->bLength == 0) + { + return (FALSE); + } + dev->EP0Data.pData = pD; + len = ((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength; + break; + case USB_STRING_DESCRIPTOR_TYPE: + pD = (uint8_t *)dev->USB_StringDescriptor; + for (n = 0; n != dev->SetupPacket.wValue.WB.L; n++) + { + if (((USB_STRING_DESCRIPTOR *)pD)->bLength != 0) + { + pD += ((USB_STRING_DESCRIPTOR *)pD)->bLength; + } + } + if (((USB_STRING_DESCRIPTOR *)pD)->bLength == 0) + { + return (FALSE); + } + dev->EP0Data.pData = pD; + len = ((USB_STRING_DESCRIPTOR *)dev->EP0Data.pData)->bLength; + break; + default: + return (FALSE); + } + break; + case REQUEST_TO_INTERFACE: + switch (dev->SetupPacket.wValue.WB.H) + { +#if USB_HID + case HID_HID_DESCRIPTOR_TYPE: + if (dev->SetupPacket.wIndex.WB.L != USB_HID_IF_NUM) + { + return (FALSE); /* Only Single HID Interface is supported */ + } + dev->EP0Data.pData = (uint8_t *)dev->USB_ConfigDescriptor + HID_DESC_OFFSET; + len = HID_DESC_SIZE; + break; + case HID_REPORT_DESCRIPTOR_TYPE: + if (dev->SetupPacket.wIndex.WB.L != USB_HID_IF_NUM) + { + return (FALSE); /* Only Single HID Interface is supported */ + } + dev->EP0Data.pData = (uint8_t *)dev->HID_ReportDescriptor; + len = HID_ReportDescSize; + break; + case HID_PHYSICAL_DESCRIPTOR_TYPE: + return (FALSE); /* HID Physical Descriptor is not supported */ +#endif + default: + return (FALSE); + } + break; + default: + return (FALSE); + } + + if (dev->EP0Data.Count > len) + { + dev->EP0Data.Count = len; + } + + return (TRUE); +} + +/********************************************************************************************************//** + * @brief Get Configuration USB Request + * @param[in] dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +__inline uint32_t USB_ReqGetConfiguration (USB_ENU_Dev *dev) +{ + + switch (dev->SetupPacket.bmRequestType.BM.Recipient) + { + case REQUEST_TO_DEVICE: + dev->EP0Data.pData = &dev->USB_Configuration; + break; + default: + return (FALSE); + } + return (TRUE); +} + +/********************************************************************************************************//** + * @brief Add a number of bytes to a pointer's address,Call looks like: AddPtr((void **)&myPointer, 8); + * @param[in] vpptr: void pointer to pointer + * @param[in] n : number of bytes to add to pointer + * @return None +************************************************************************************************************/ +__inline void UsbAddPtr(void **vpptr, uint32_t n) +{ + /* Declare a pointer to a pointer to a byte. Only a byte pointer + * can be incremented by a number of bytes. Other pointers will + * increment by a multiple of what they point to. + */ + uint8_t **bpptr; + + /* Convert our void pointer to a pointer to a byte pointer to a pointer */ + bpptr = (uint8_t **)vpptr; + + /* Add 'n' bytes to our pointer value */ + (*bpptr) += n; +} + +/********************************************************************************************************//** + * @brief Set Configuration USB Request + * @param[in] dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +__inline uint32_t USB_ReqSetConfiguration (USB_ENU_Dev *dev) +{ + USB_COMMON_DESCRIPTOR *pD; + uint32_t alt = 0; + uint32_t n, m; + + switch (dev->SetupPacket.bmRequestType.BM.Recipient) + { + case REQUEST_TO_DEVICE: + + if (dev->SetupPacket.wValue.WB.L) + { + pD = (USB_COMMON_DESCRIPTOR *)dev->USB_ConfigDescriptor; + while (pD->bLength) + { + switch (pD->bDescriptorType) + { + case USB_CONFIGURATION_DESCRIPTOR_TYPE: + if (((USB_CONFIGURATION_DESCRIPTOR *)pD)->bConfigurationValue == dev->SetupPacket.wValue.WB.L) + { + dev->USB_Configuration = dev->SetupPacket.wValue.WB.L; + dev->USB_NumInterfaces = ((USB_CONFIGURATION_DESCRIPTOR *)pD)->bNumInterfaces; + for (n = 0; n < USB_IF_NUM; n++) + { + dev->USB_AltSetting[n] = 0; + } + for (n = 1; n < 16; n++) + { + if (dev->USB_EndPointMask & (1 << n)) + { + xUSBEndpointDisable(n); + } + if (dev->USB_EndPointMask & ((1 << 16) << n)) + { + xUSBEndpointDisable(n | 0x80); + } + } + dev->USB_EndPointMask = 0x00010001; + dev->USB_EndPointHalt = 0x00000000; + dev->USB_EndPointStall= 0x00000000; + xUSBConfigure(TRUE); + if (((USB_CONFIGURATION_DESCRIPTOR *)pD)->bmAttributes & USB_CONFIG_POWERED_MASK) + { + dev->USB_DeviceStatus |= USB_GETSTATUS_SELF_POWERED; + } + else + { + dev->USB_DeviceStatus &= ~USB_GETSTATUS_SELF_POWERED; + } + } + else + { + UsbAddPtr((void **)&pD, ((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength); + continue; + } + break; + case USB_INTERFACE_DESCRIPTOR_TYPE: + alt = ((USB_INTERFACE_DESCRIPTOR *)pD)->bAlternateSetting; + break; + case USB_ENDPOINT_DESCRIPTOR_TYPE: + if (alt == 0) + { + n = ((USB_ENDPOINT_DESCRIPTOR *)pD)->bEndpointAddress & 0x8F; + m = (n & 0x80) ? ((1 << 16) << (n & 0x0F)) : (1 << n); + dev->USB_EndPointMask |= m; + xUSBEndpointConfig((USB_ENDPOINT_DESCRIPTOR *)pD,0); + xUSBEndpointEnable(n); + xUSBEndpointReset(n); + } + break; + } + UsbAddPtr((void **)&pD, pD->bLength); + } + } + else + { + dev->USB_Configuration = 0; + for (n = 1; n < 16; n++) + { + if (dev->USB_EndPointMask & (1 << n)) + { + xUSBEndpointDisable(n); + } + if (dev->USB_EndPointMask & ((1 << 16) << n)) + { + xUSBEndpointDisable(n | 0x80); + } + } + dev->USB_EndPointMask = 0x00010001; + dev->USB_EndPointHalt = 0x00000000; + dev->USB_EndPointStall = 0x00000000; + xUSBConfigure(FALSE); + } + + if (dev->USB_Configuration != dev->SetupPacket.wValue.WB.L) + { + return (FALSE); + } + break; + default: + return (FALSE); + } + return (TRUE); +} + + +/********************************************************************************************************//** + * @brief Get Interface USB Request + * @param[in] dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +__inline uint32_t USB_ReqGetInterface (USB_ENU_Dev *dev) +{ + + switch (dev->SetupPacket.bmRequestType.BM.Recipient) + { + case REQUEST_TO_INTERFACE: + if ((dev->USB_Configuration != 0) && (dev->SetupPacket.wIndex.WB.L < dev->USB_NumInterfaces)) + { + dev->EP0Data.pData = dev->USB_AltSetting + dev->SetupPacket.wIndex.WB.L; + } + else + { + return (FALSE); + } + break; + default: + return (FALSE); + } + return (TRUE); +} + +/********************************************************************************************************//** + * @brief Set Interface USB Request + * @param[in] dev : a point which contains all the global variables which using in this function + * @return TRUE - Success, FALSE - Error +************************************************************************************************************/ +__inline uint32_t USB_ReqSetInterface (USB_ENU_Dev *dev) +{ + USB_COMMON_DESCRIPTOR *pD; + uint32_t ifn = 0, alt = 0, old = 0, msk = 0; + uint32_t n, m; + uint32_t set; + + switch (dev->SetupPacket.bmRequestType.BM.Recipient) + { + case REQUEST_TO_INTERFACE: + if (dev->USB_Configuration == 0) return (FALSE); + set = FALSE; + pD = (USB_COMMON_DESCRIPTOR *)dev->USB_ConfigDescriptor; + while (pD->bLength) + { + switch (pD->bDescriptorType) + { + case USB_CONFIGURATION_DESCRIPTOR_TYPE: + if (((USB_CONFIGURATION_DESCRIPTOR *)pD)->bConfigurationValue != dev->USB_Configuration) + { + UsbAddPtr((void **)&pD, ((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength); + continue; + } + break; + case USB_INTERFACE_DESCRIPTOR_TYPE: + ifn = ((USB_INTERFACE_DESCRIPTOR *)pD)->bInterfaceNumber; + alt = ((USB_INTERFACE_DESCRIPTOR *)pD)->bAlternateSetting; + msk = 0; + if ((ifn == dev->SetupPacket.wIndex.WB.L) && (alt == dev->SetupPacket.wValue.WB.L)) + { + set = TRUE; + old = dev->USB_AltSetting[ifn]; + dev->USB_AltSetting[ifn] = (uint8_t)alt; + } + break; + case USB_ENDPOINT_DESCRIPTOR_TYPE: + if (ifn == dev->SetupPacket.wIndex.WB.L) + { + n = ((USB_ENDPOINT_DESCRIPTOR *)pD)->bEndpointAddress & 0x8F; + m = (n & 0x80) ? ((1 << 16) << (n & 0x0F)) : (1 << n); + if (alt == dev->SetupPacket.wValue.WB.L) + { + dev->USB_EndPointMask |= m; + dev->USB_EndPointHalt &= ~m; + xUSBEndpointConfig((USB_ENDPOINT_DESCRIPTOR *)pD,0); + xUSBEndpointEnable(n); + xUSBEndpointReset(n); + msk |= m; + } + else if ((alt == old) && ((msk & m) == 0)) + { + dev->USB_EndPointMask &= ~m; + dev->USB_EndPointHalt &= ~m; + xUSBEndpointDisable(n); + } + } + break; + } + UsbAddPtr((void **)&pD, pD->bLength); + } + break; + default: + return (FALSE); + } + + return (set); +} + +/********************************************************************************************************//** + * @brief USB Endpoint 0 Event Callback + * @param[in] dev : a point which contains all the global variables which using in this function + * @param[in] event: USB_EVT_SETUP\USB_EVT_OUT\USB_EVT_IN\USB_EVT_OUT_NAK\USB_EVT_IN_NAK + * @return None +************************************************************************************************************/ +void USB_EndPoint0 (USB_ENU_Dev *dev, uint32_t event, + unsigned long ulMsgParam, + void *pvMsgData) +{ + + switch (event) + { + case USB_EVT_SETUP: + USB_SetupStage(dev); + xUSBEndpointDirCtr(dev->SetupPacket.bmRequestType.BM.Dir); + dev->EP0Data.Count = dev->SetupPacket.wLength; /* Number of bytes to transfer */ + switch (dev->SetupPacket.bmRequestType.BM.Type) + { + + case REQUEST_STANDARD: + switch (dev->SetupPacket.bRequest) + { + case USB_REQUEST_GET_STATUS: + if (!USB_ReqGetStatus(dev)) + { + goto stall_i; + } + USB_DataInStage(dev); + break; + + case USB_REQUEST_CLEAR_FEATURE: + if (!USB_ReqSetClrFeature(dev,0)) + { + goto stall_i; + } + USB_StatusInStage(dev); +#if USB_FEATURE_EVENT + if(dev->g_pfn_feature_callback !=NULL) + { + dev->g_pfn_feature_callback(0); + } +#endif + break; + + case USB_REQUEST_SET_FEATURE: + if (!USB_ReqSetClrFeature(dev,1)) + { + goto stall_i; + } + USB_StatusInStage(dev); +#if USB_FEATURE_EVENT + if(dev->g_pfn_feature_callback !=NULL) + { + dev->g_pfn_feature_callback(0); + } +#endif + break; + + case USB_REQUEST_SET_ADDRESS: + if (!USB_ReqSetAddress(dev)) + { + goto stall_i; + } + USB_StatusInStage(dev); + break; + + case USB_REQUEST_GET_DESCRIPTOR: + if (!USB_ReqGetDescriptor(dev)) + { + goto stall_i; + } + USB_DataInStage(dev); + break; + + case USB_REQUEST_SET_DESCRIPTOR: + /*stall_o:*/ + xUSBEndpointStallSet(0x00); /* not supported */ + dev->EP0Data.Count = 0; + break; + + case USB_REQUEST_GET_CONFIGURATION: + if (!USB_ReqGetConfiguration(dev)) + { + goto stall_i; + } + USB_DataInStage(dev); + break; + + case USB_REQUEST_SET_CONFIGURATION: + if (!USB_ReqSetConfiguration(dev)) + { + goto stall_i; + } + USB_StatusInStage(dev); +#if USB_CONFIGURE_EVENT + if(dev->g_pfn_config_callback != NULL) + { + dev->g_pfn_config_callback(0); + } +#endif + break; + + case USB_REQUEST_GET_INTERFACE: + if (!USB_ReqGetInterface(dev)) + { + goto stall_i; + } + USB_DataInStage(dev); + break; + + case USB_REQUEST_SET_INTERFACE: + if (!USB_ReqSetInterface(dev)) + { + goto stall_i; + } + USB_StatusInStage(dev); +#if USB_INTERFACE_EVENT + if(dev->g_pfn_interfacec_callback != NULL) + { + dev->g_pfn_interfacec_callback(0); + } +#endif + break; + + default: + goto stall_i; + } + break; /* end case REQUEST_STANDARD */ + +#if USB_CLASS + case REQUEST_CLASS: + switch (dev->SetupPacket.bmRequestType.BM.Recipient) + { + case REQUEST_TO_DEVICE: + goto stall_i; /* not supported */ + + case REQUEST_TO_INTERFACE: +#if USB_HID + if (dev->SetupPacket.wIndex.WB.L == USB_HID_IF_NUM) + { /* IF number correct? */ + switch (dev->SetupPacket.bRequest) + { + case HID_REQUEST_GET_REPORT: + if(dev->g_pfn_hid_get_report!=NULL) + { + if (dev->g_pfn_hid_get_report(dev->hid_data)) + { + dev->EP0Data.pData = dev->EP0Buf; /* point to data to be sent */ + USB_DataInStage(dev); /* send requested data */ + goto setup_class_ok; + } + } + else + { + goto stall_i; + } + break; + case HID_REQUEST_SET_REPORT: + dev->EP0Data.pData = dev->EP0Buf; /* data to be received */ + xUSBControlOutEnble(); + goto setup_class_ok; + case HID_REQUEST_GET_IDLE: + if(dev->g_pfn_hid_get_idle!=NULL) + { + if (dev->g_pfn_hid_get_idle(dev->hid_data)) + { + dev->EP0Data.pData = dev->EP0Buf; /* point to data to be sent */ + USB_DataInStage(dev); /* send requested data */ + goto setup_class_ok; + } + } + else + { + goto stall_i; + } + break; + case HID_REQUEST_SET_IDLE: + if(dev->g_pfn_hid_set_idle!=NULL) + { + if (dev->g_pfn_hid_set_idle(dev->hid_data)) + { + USB_StatusInStage(dev); /* send Acknowledge */ + goto setup_class_ok; + } + } + else + { + goto stall_i; + } + break; + case HID_REQUEST_GET_PROTOCOL: + if(dev->g_pfn_hid_get_procotol!=NULL) + { + if (dev->g_pfn_hid_get_procotol(dev->hid_data)) + { + dev->EP0Data.pData = dev->EP0Buf; /* point to data to be sent */ + USB_DataInStage(dev); /* send requested data */ + goto setup_class_ok; + } + } + else + { + goto stall_i; + } + break; + case HID_REQUEST_SET_PROTOCOL: + if(dev->g_pfn_hid_set_procotol!=NULL) + { + if (dev->g_pfn_hid_set_procotol(dev->hid_data)) + { + USB_StatusInStage(dev); /* send Acknowledge */ + goto setup_class_ok; + } + } + else + { + goto stall_i; + } + break; + } + } +#endif /* USB_HID */ +#if USB_MSC + if (dev->SetupPacket.wIndex.WB.L == USB_MSC_IF_NUM) + { /* IF number correct? */ + switch (dev->SetupPacket.bRequest) + { + case MSC_REQUEST_RESET: + if ((dev->SetupPacket.wValue.W == 0) && /* RESET with invalid parameters -> STALL */ + (dev->SetupPacket.wLength == 0)) + { + if(dev->g_pfn_msc_request_reset!=NULL) + { + if (dev->g_pfn_msc_request_reset(dev->msc_data,0)) + { + USB_StatusInStage(dev); + goto setup_class_ok; + } + } + else + { + goto stall_i; + } + } + break; + case MSC_REQUEST_GET_MAX_LUN: + if ((dev->SetupPacket.wValue.W == 0) && /* GET_MAX_LUN with invalid parameters -> STALL */ + (dev->SetupPacket.wLength == 1)) + { + if(dev->g_pfn_msc_request_get_max_lun!=NULL) + { + if (dev->g_pfn_msc_request_get_max_lun(dev->msc_data,0)) + { + dev->EP0Data.pData = dev->EP0Buf; + USB_DataInStage(dev); + goto setup_class_ok; + } + } + else + { + goto stall_i; + } + } + break; + case MSC_REQUEST_ADSC: + dev->EP0Data.pData = dev->EP0Buf; /* data to be received, see USB_EVT_OUT */ + xUSBControlOutEnble(); + goto setup_class_ok; + break; + case MSC_REQUEST_GET_REQ: + if ( (dev->SetupPacket.wValue.W == MSC_REQ_GLI) ) /* GET_MAX_LUN with invalid parameters -> STALL */ + { + if(dev->g_pfn_msc_request_get_req!=NULL) + { + if (dev->g_pfn_msc_request_get_req(dev->msc_data,0)) + { + dev->EP0Data.pData = dev->EP0Buf; + USB_DataInStage(dev); + goto setup_class_ok; + } + } + else + { + goto stall_i; + } + } + break; + case MSC_REQUEST_PUT_REQ: + dev->EP0Data.pData = dev->EP0Buf; /* data to be received, see USB_EVT_OUT */ + xUSBControlOutEnble(); + goto setup_class_ok; + break; + } + } +#endif /* USB_MSC */ +#if USB_AUDIO + if ((dev->SetupPacket.wIndex.WB.L == USB_ADC_CIF_NUM) || /* IF number correct? */ + (dev->SetupPacket.wIndex.WB.L == USB_ADC_SIF1_NUM) || + (dev->SetupPacket.wIndex.WB.L == USB_ADC_SIF2_NUM)) + { + switch (dev->SetupPacket.bRequest) + { + case AUDIO_REQUEST_GET_CUR: + case AUDIO_REQUEST_GET_MIN: + case AUDIO_REQUEST_GET_MAX: + case AUDIO_REQUEST_GET_RES: + if(dev->g_pfn_adc_if_getrequestt != NULL) + { + if (dev->g_pfn_adc_if_getrequestt(dev->adc_data)) + { + dev->EP0Data.pData = dev->EP0Buf; /* point to data to be sent */ + USB_DataInStage(dev); /* send requested data */ + goto setup_class_ok; + } + } + else + { + goto stall_i; + } + break; + case AUDIO_REQUEST_SET_CUR: + // case AUDIO_REQUEST_SET_MIN: + // case AUDIO_REQUEST_SET_MAX: + // case AUDIO_REQUEST_SET_RES: + dev->EP0Data.pData = dev->EP0Buf; /* data to be received */ + goto setup_class_ok; + } + } +#endif /* USB_AUDIO */ +#if USB_CDC + if ((dev->SetupPacket.wIndex.WB.L == USB_CDC_CIF_NUM) || /* IF number correct? */ + (dev->SetupPacket.wIndex.WB.L == USB_CDC_DIF_NUM)) + { + switch (dev->SetupPacket.bRequest) + { + case CDC_SEND_ENCAPSULATED_COMMAND://out data + dev->EP0Data.pData = dev->EP0Buf; /* data to be received, see USB_EVT_OUT */ + xUSBControlOutEnble(); + xUSBControlOutEnble(); + goto setup_class_ok; + case CDC_GET_ENCAPSULATED_RESPONSE://in data + if(dev->g_pfn_cdc_GetEncapsulatedResponse != NULL) + { + if (dev->g_pfn_cdc_GetEncapsulatedResponse(dev->cdc_data,0)) + { + dev->EP0Data.pData = dev->EP0Buf; /* point to data to be sent */ + USB_DataInStage(dev); /* send requested data */ + goto setup_class_ok; + } + } + else + { + goto stall_i; + } + break; + case CDC_SET_COMM_FEATURE://out data + dev->EP0Data.pData = dev->EP0Buf; /* data to be received, see USB_EVT_OUT */ + xUSBControlOutEnble(); + goto setup_class_ok; + case CDC_GET_COMM_FEATURE://in data + if(dev->g_pfn_cdc_GetCommFeature != NULL) + { + if (dev->g_pfn_cdc_GetCommFeature(dev->cdc_data,dev->SetupPacket.wValue.W)) + { + dev->EP0Data.pData = dev->EP0Buf; /* point to data to be sent */ + USB_DataInStage(dev); /* send requested data */ + goto setup_class_ok; + } + } + else + { + goto stall_i; + } + break; + case CDC_CLEAR_COMM_FEATURE://out none + if(dev->g_pfn_cdc_ClearCommFeature != NULL) + { + if (dev->g_pfn_cdc_ClearCommFeature(dev->cdc_data,dev->SetupPacket.wValue.W)) + { + USB_StatusInStage(dev); /* send Acknowledge */ + goto setup_class_ok; + } + } + else + { + goto stall_i; + } + break; + case CDC_SET_AUX_LINE_STATE://out none + if(dev->g_pfn_cdc_SetAuxLineState != NULL) + { + if (dev->g_pfn_cdc_SetAuxLineState(dev->cdc_data,dev->SetupPacket.wValue.W)) + { + USB_StatusInStage(dev); /* send Acknowledge */ + goto setup_class_ok; + } + } + else + { + goto stall_i; + } + break; + case CDC_SET_HOOK_STATE://out none + if(dev->g_pfn_cdc_SetHookState != NULL) + { + if (dev->g_pfn_cdc_SetHookState(dev->cdc_data,dev->SetupPacket.wValue.W)) + { + USB_StatusInStage(dev); /* send Acknowledge */ + goto setup_class_ok; + } + } + else + { + goto stall_i; + } + break; + case CDC_PULSE_SETUP://out none + if(dev->g_pfn_cdc_PulseSetup != NULL) + { + if (dev->g_pfn_cdc_PulseSetup(dev->cdc_data,dev->SetupPacket.wValue.W)) + { + USB_StatusInStage(dev); /* send Acknowledge */ + goto setup_class_ok; + } + } + else + { + goto stall_i; + } + break; + case CDC_SEND_PULSE://out none + if(dev->g_pfn_cdc_SendPulse != NULL) + { + if (dev->g_pfn_cdc_SendPulse(dev->cdc_data,dev->SetupPacket.wValue.W)) + { + USB_StatusInStage(dev); /* send Acknowledge */ + goto setup_class_ok; + } + } + else + { + goto stall_i; + } + break; + case CDC_SET_PULSE_TIME://out none + if(dev->g_pfn_cdc_SetPulseTime != NULL) + { + if (dev->g_pfn_cdc_SetPulseTime(dev->cdc_data,dev->SetupPacket.wValue.W)) + { + USB_StatusInStage(dev); /* send Acknowledge */ + goto setup_class_ok; + } + } + else + { + goto stall_i; + } + break; + case CDC_RING_AUX_JACK://out none + if(dev->g_pfn_cdc_RingAuxJack != NULL) + { + if (dev->g_pfn_cdc_RingAuxJack(dev->cdc_data,dev->SetupPacket.wValue.W)) + { + USB_StatusInStage(dev); /* send Acknowledge */ + goto setup_class_ok; + } + } + else + { + goto stall_i; + } + break; + case CDC_SET_LINE_CODING: + dev->EP0Data.pData = dev->EP0Buf; /* data to be received, see USB_EVT_OUT */ + xUSBControlOutEnble(); + goto setup_class_ok; + case CDC_GET_LINE_CODING: + if(dev->g_pfn_cdc_GetLineCoding != NULL) + { + if (dev->g_pfn_cdc_GetLineCoding(dev->cdc_data,0)) + { + dev->EP0Data.pData = dev->EP0Buf; /* point to data to be sent */ + USB_DataInStage(dev); /* send requested data */ + goto setup_class_ok; + } + } + else + { + goto stall_i; + } + break; + case CDC_SET_CONTROL_LINE_STATE: + if(dev->g_pfn_cdc_SetControlLineState != NULL) + { + if (dev->g_pfn_cdc_SetControlLineState(dev->cdc_data,dev->SetupPacket.wValue.W)) + { + USB_StatusInStage(dev); /* send Acknowledge */ + goto setup_class_ok; + } + } + else + { + goto stall_i; + } + break; + case CDC_SEND_BREAK: + if(dev->g_pfn_cdc_SendBreak != NULL) + { + if (dev->g_pfn_cdc_SendBreak(dev->cdc_data,dev->SetupPacket.wValue.W)) + { + USB_StatusInStage(dev); /* send Acknowledge */ + goto setup_class_ok; + } + } + else + { + goto stall_i; + } + break; + case CDC_SET_RINGER_PARMS: + dev->EP0Data.pData = dev->EP0Buf; /* data to be received, see USB_EVT_OUT */ + xUSBControlOutEnble(); + goto setup_class_ok; + case CDC_GET_RINGER_PARMS: + if(dev->g_pfn_cdc_GetRingerParms != NULL) + { + if (dev->g_pfn_cdc_GetRingerParms(dev->cdc_data,0)) + { + dev->EP0Data.pData = dev->EP0Buf; /* point to data to be sent */ + USB_DataInStage(dev); /* send requested data */ + goto setup_class_ok; + } + } + else + { + goto stall_i; + } + break; + case CDC_SET_OPERATION_PARMS: + if(dev->g_pfn_cdc_SetOperationParms != NULL) + { + if (dev->g_pfn_cdc_SetOperationParms(dev->cdc_data,dev->SetupPacket.wValue.W)) + { + USB_StatusInStage(dev); /* send Acknowledge */ + goto setup_class_ok; + } + } + else + { + goto stall_i; + } + break; + case CDC_GET_OPERATION_PARMS: + if(dev->g_pfn_cdc_GetOperationParms != NULL) + { + if (dev->g_pfn_cdc_GetOperationParms(dev->cdc_data,0)) + { + dev->EP0Data.pData = dev->EP0Buf; /* point to data to be sent */ + USB_DataInStage(dev); /* send requested data */ + goto setup_class_ok; + } + } + else + { + goto stall_i; + } + break; + case CDC_SET_LINE_PARMS: + dev->EP0Data.pData = dev->EP0Buf; /* data to be received, see USB_EVT_OUT */ + xUSBControlOutEnble(); + goto setup_class_ok; + case CDC_GET_LINE_PARMS: + if(dev->g_pfn_cdc_GetLineParms != NULL) + { + if (dev->g_pfn_cdc_GetLineParms(dev->cdc_data,0)) + { + dev->EP0Data.pData = dev->EP0Buf; /* point to data to be sent */ + USB_DataInStage(dev); /* send requested data */ + goto setup_class_ok; + } + } + else + { + goto stall_i; + } + break; + case CDC_DIAL_DIGITS: + dev->EP0Data.pData = dev->EP0Buf; /* data to be received, see USB_EVT_OUT */ + xUSBControlOutEnble(); + goto setup_class_ok; + case CDC_SET_UNIT_PARAMETER: + dev->EP0Data.pData = dev->EP0Buf; /* data to be received, see USB_EVT_OUT */ + xUSBControlOutEnble(); + goto setup_class_ok; + case CDC_GET_UNIT_PARAMETER: + if(dev->g_pfn_cdc_GetUnitParameter != NULL) + { + if (dev->g_pfn_cdc_GetUnitParameter(dev->cdc_data,dev->SetupPacket.wValue.W)) + { + dev->EP0Data.pData = dev->EP0Buf; /* point to data to be sent */ + USB_DataInStage(dev); /* send requested data */ + goto setup_class_ok; + } + } + else + { + goto stall_i; + } + break; + case CDC_CLEAR_UNIT_PARAMETER: + if(dev->g_pfn_cdc_ClearUnitParameter != NULL) + { + if (dev->g_pfn_cdc_ClearUnitParameter(dev->cdc_data,dev->SetupPacket.wValue.W)) + { + USB_StatusInStage(dev); /* send Acknowledge */ + goto setup_class_ok; + } + } + else + { + goto stall_i; + } + break; + case CDC_GET_PROFILE: + if(dev->g_pfn_cdc_GetProfile != NULL) + { + if (dev->g_pfn_cdc_GetProfile(dev->cdc_data,0)) + { + dev->EP0Data.pData = dev->EP0Buf; /* point to data to be sent */ + USB_DataInStage(dev); /* send requested data */ + goto setup_class_ok; + } + } + else + { + goto stall_i; + } + break; + case CDC_SET_ETHERNET_MULTICAST_FILTERS: + dev->EP0Data.pData = dev->EP0Buf; /* data to be received, see USB_EVT_OUT */ + xUSBControlOutEnble(); + goto setup_class_ok; + case CDC_SET_ETHERNET_PMP_FILTER: + dev->EP0Data.pData = dev->EP0Buf; /* data to be received, see USB_EVT_OUT */ + xUSBControlOutEnble(); + goto setup_class_ok; + case CDC_GET_ETHERNET_PMP_FILTER: + if(dev->g_pfn_cdc_GetEthernetPowerManagementPatternFilter != NULL) + { + if (dev->g_pfn_cdc_GetEthernetPowerManagementPatternFilter(dev->cdc_data,dev->SetupPacket.wValue.W)) + { + dev->EP0Data.pData = dev->EP0Buf; /* point to data to be sent */ + USB_DataInStage(dev); /* send requested data */ + goto setup_class_ok; + } + } + else + { + goto stall_i; + } + break; + case CDC_SET_ETHERNET_PACKET_FILTER: + if(dev->g_pfn_cdc_SetEthernetPacketFilter != NULL) + { + if (dev->g_pfn_cdc_SetEthernetPacketFilter(dev->cdc_data,dev->SetupPacket.wValue.W)) + { + USB_StatusInStage(dev); /* send Acknowledge */ + goto setup_class_ok; + } + } + else + { + goto stall_i; + } + break; + case CDC_GET_ETHERNET_STATISTIC: + if(dev->g_pfn_cdc_GetEthernetStatistic != NULL) + { + if (dev->g_pfn_cdc_GetEthernetStatistic(dev->cdc_data,dev->SetupPacket.wValue.W)) + { + dev->EP0Data.pData = dev->EP0Buf; /* point to data to be sent */ + USB_DataInStage(dev); /* send requested data */ + goto setup_class_ok; + } + } + else + { + goto stall_i; + } + break; + case CDC_SET_ATM_DATA_FORMAT: + if(dev->g_pfn_cdc_SetATMDataFormat != NULL) + { + if (dev->g_pfn_cdc_SetATMDataFormat(dev->cdc_data,dev->SetupPacket.wValue.W)) + { + USB_StatusInStage(dev); /* send Acknowledge */ + goto setup_class_ok; + } + } + else + { + goto stall_i; + } + break; + case CDC_GET_ATM_DEVICE_STATISTICS: + if(dev->g_pfn_cdc_GetATMDeviceStatistics != NULL) + { + if (dev->g_pfn_cdc_GetATMDeviceStatistics(dev->cdc_data,dev->SetupPacket.wValue.W)) + { + dev->EP0Data.pData = dev->EP0Buf; /* point to data to be sent */ + USB_DataInStage(dev); /* send requested data */ + goto setup_class_ok; + } + } + else + { + goto stall_i; + } + break; + case CDC_SET_ATM_DEFAULT_VC: + dev->EP0Data.pData = dev->EP0Buf; /* data to be received, see USB_EVT_OUT */ + xUSBControlOutEnble(); + goto setup_class_ok; + case CDC_GET_ATM_VC_STATISTICS: + if(dev->g_pfn_cdc_GetATMVCStatistics != NULL) + { + if (dev->g_pfn_cdc_GetATMVCStatistics(dev->cdc_data,dev->SetupPacket.wValue.W)) + { + dev->EP0Data.pData = dev->EP0Buf; /* point to data to be sent */ + USB_DataInStage(dev); /* send requested data */ + goto setup_class_ok; + } + } + else + { + goto stall_i; + } + break; + } + } +#endif /* USB_CDC */ + goto stall_i; /* not supported */ + /* end case REQUEST_TO_INTERFACE */ + + case REQUEST_TO_ENDPOINT: +#if USB_AUDIO + switch (dev->SetupPacket.bRequest) + { + case AUDIO_REQUEST_GET_CUR: + case AUDIO_REQUEST_GET_MIN: + case AUDIO_REQUEST_GET_MAX: + case AUDIO_REQUEST_GET_RES: + if(dev->g_pfn_adc_ep_getrequestt != NULL) + { + if (dev->g_pfn_adc_ep_getrequestt(dev->adc_data)) + { + dev->EP0Data.pData = dev->EP0Buf; /* point to data to be sent */ + USB_DataInStage(dev); /* send requested data */ + goto setup_class_ok; + } + } + else + { + goto stall_i; + } + break; + case AUDIO_REQUEST_SET_CUR: + // case AUDIO_REQUEST_SET_MIN: + // case AUDIO_REQUEST_SET_MAX: + // case AUDIO_REQUEST_SET_RES: + dev->EP0Data.pData = dev->EP0Buf; /* data to be received */ + goto setup_class_ok; + } +#endif /* USB_AUDIO */ + goto stall_i; + /* end case REQUEST_TO_ENDPOINT */ + + default: + goto stall_i; + } + setup_class_ok: /* request finished successfully */ + break; /* end case REQUEST_CLASS */ +#endif /* USB_CLASS */ + +#if USB_VENDOR + case REQUEST_VENDOR: + switch (dev->SetupPacket.bmRequestType.BM.Recipient) + { + + case REQUEST_TO_DEVICE: + if(dev->g_pfn_vender_device != NULL) + { + if (!dev->g_pfn_vender_device(dev->vender_data, TRUE)) + { + goto stall_i; /* not supported */ + } + } + else + { + goto stall_i; + } + break; + + case REQUEST_TO_INTERFACE: + if(dev->g_pfn_vender_interface != NULL) + { + if (!dev->g_pfn_vender_interface(dev->vender_data, TRUE)) + { + goto stall_i; /* not supported */ + } + } + else + { + goto stall_i; + } + break; + + case REQUEST_TO_ENDPOINT: + if(dev->g_pfn_vender_endpoint != NULL) + { + if (!dev->g_pfn_vender_endpoint(dev->vender_data, TRUE)) + { + goto stall_i; /* not supported */ + } + } + else + { + goto stall_i; + } + break; + + default: + goto stall_i; + } + + if (dev->SetupPacket.wLength) + { + if (dev->SetupPacket.bmRequestType.BM.Dir == REQUEST_DEVICE_TO_HOST) + { + USB_DataInStage(dev); + } + } + else + { + USB_StatusInStage(dev); + } + + break; /* end case REQUEST_VENDOR */ +#endif /* USB_VENDOR */ + + default: +stall_i: + xUSBEndpointStallSet(0x80); + dev->EP0Data.Count = 0; + break; + } + break; /* end case USB_EVT_SETUP */ + + case USB_EVT_OUT: + if (dev->SetupPacket.bmRequestType.BM.Dir == REQUEST_HOST_TO_DEVICE) + { + if (dev->EP0Data.Count) + { /* still data to receive ? */ + USB_DataOutStage(dev); /* receive data */ + if (dev->EP0Data.Count == 0) + { /* data complete ? */ + switch (dev->SetupPacket.bmRequestType.BM.Type) + { + + case REQUEST_STANDARD: + goto stall_i; /* not supported */ + +#if (USB_CLASS) + case REQUEST_CLASS: + switch (dev->SetupPacket.bmRequestType.BM.Recipient) + { + case REQUEST_TO_DEVICE: + goto stall_i; /* not supported */ + + case REQUEST_TO_INTERFACE: +#if USB_MSC + if (dev->SetupPacket.wIndex.WB.L == USB_MSC_IF_NUM) + { /* IF number correct? */ + switch (dev->SetupPacket.bRequest) + { + case MSC_REQUEST_ADSC: + if(dev->g_pfn_msc_request_adsc != NULL) + { + if (dev->g_pfn_msc_request_adsc(dev->msc_data,0)) + { + USB_StatusInStage(dev); /* send Acknowledge */ + goto out_class_ok; + } + } + else + { + goto stall_i; + } + break; + case MSC_REQUEST_PUT_REQ: + if(dev->g_pfn_msc_request_put_req != NULL) + { + if (dev->g_pfn_msc_request_put_req(dev->msc_data,dev->SetupPacket.wValue.W)) + { + USB_StatusInStage(dev); /* send Acknowledge */ + goto out_class_ok; + } + } + else + { + goto stall_i; + } + break; + } + } +#endif /* USB_MSC */ +#if USB_HID + if (dev->SetupPacket.wIndex.WB.L == USB_HID_IF_NUM) + { /* IF number correct? */ + switch (dev->SetupPacket.bRequest) + { + case HID_REQUEST_SET_REPORT: + if(dev->g_pfn_hid_set_report != NULL) + { + if (dev->g_pfn_hid_set_report(dev->hid_data)) + { + USB_StatusInStage(dev); /* send Acknowledge */ + goto out_class_ok; + } + } + else + { + goto stall_i; + } + break; + } + } +#endif /* USB_HID */ +#if USB_AUDIO + if ((dev->SetupPacket.wIndex.WB.L == USB_ADC_CIF_NUM) || /* IF number correct? */ + (dev->SetupPacket.wIndex.WB.L == USB_ADC_SIF1_NUM) || + (dev->SetupPacket.wIndex.WB.L == USB_ADC_SIF2_NUM)) + { + switch (dev->SetupPacket.bRequest) + { + case AUDIO_REQUEST_SET_CUR: + // case AUDIO_REQUEST_SET_MIN: + // case AUDIO_REQUEST_SET_MAX: + // case AUDIO_REQUEST_SET_RES: + if(dev->g_pfn_adc_if_setrequestt != NULL) + { + if (dev->g_pfn_adc_if_setrequestt(dev->adc_data)) + { + USB_StatusInStage(dev); /* send Acknowledge */ + goto out_class_ok; + } + } + else + { + goto stall_i; + } + break; + } + } +#endif /* USB_AUDIO */ +#if USB_CDC + if ((dev->SetupPacket.wIndex.WB.L == USB_CDC_CIF_NUM) || /* IF number correct? */ + (dev->SetupPacket.wIndex.WB.L == USB_CDC_DIF_NUM)) + { + switch (dev->SetupPacket.bRequest) + { + case CDC_SEND_ENCAPSULATED_COMMAND: + if(dev->g_pfn_cdc_SendEncapsulatedCommand != NULL) + { + if (dev->g_pfn_cdc_SendEncapsulatedCommand(dev->cdc_data,0)) + { + USB_StatusInStage(dev); /* send Acknowledge */ + goto out_class_ok; + } + } + else + { + goto stall_i; + } + break; + case CDC_SET_COMM_FEATURE: + if(dev->g_pfn_cdc_SetCommFeature != NULL) + { + if (dev->g_pfn_cdc_SetCommFeature(dev->cdc_data,dev->SetupPacket.wValue.W)) + { + USB_StatusInStage(dev); /* send Acknowledge */ + goto out_class_ok; + } + } + else + { + goto stall_i; + } + break; + case CDC_SET_LINE_CODING: + if(dev->g_pfn_cdc_SetLineCoding != NULL) + { + if (dev->g_pfn_cdc_SetLineCoding(dev->cdc_data,0)) + { + USB_StatusInStage(dev); /* send Acknowledge */ + goto out_class_ok; + } + } + else + { + goto stall_i; + } + break; + case CDC_SET_RINGER_PARMS: + if(dev->g_pfn_cdc_SetLineCoding != NULL) + { + if (dev->g_pfn_cdc_SetLineCoding(dev->cdc_data,0)) + { + USB_StatusInStage(dev); /* send Acknowledge */ + goto out_class_ok; + } + } + else + { + goto stall_i; + } + break; + case CDC_SET_LINE_PARMS: + if(dev->g_pfn_cdc_SetLineParms != NULL) + { + if (dev->g_pfn_cdc_SetLineParms(dev->cdc_data,dev->SetupPacket.wValue.W)) + { + USB_StatusInStage(dev); /* send Acknowledge */ + goto out_class_ok; + } + } + else + { + goto stall_i; + } + break; + case CDC_DIAL_DIGITS: + if(dev->g_pfn_cdc_DialDigits != NULL) + { + if (dev->g_pfn_cdc_DialDigits(dev->cdc_data,0)) + { + USB_StatusInStage(dev); /* send Acknowledge */ + goto out_class_ok; + } + } + else + { + goto stall_i; + } + break; + case CDC_SET_UNIT_PARAMETER: + if(dev->g_pfn_cdc_SetUnitParameter != NULL) + { + if (dev->g_pfn_cdc_SetUnitParameter(dev->cdc_data,dev->SetupPacket.wValue.W)) + { + USB_StatusInStage(dev); /* send Acknowledge */ + goto out_class_ok; + } + } + else + { + goto stall_i; + } + break; + case CDC_SET_ETHERNET_MULTICAST_FILTERS: + if(dev->g_pfn_cdc_SetEthernetMulticastFilters != NULL) + { + if (dev->g_pfn_cdc_SetEthernetMulticastFilters(dev->cdc_data,dev->SetupPacket.wValue.W)) + { + USB_StatusInStage(dev); /* send Acknowledge */ + goto out_class_ok; + } + } + else + { + goto stall_i; + } + break; + case CDC_SET_ETHERNET_PMP_FILTER: + if(dev->g_pfn_cdc_SetEthernetPowerManagementPatternFilter != NULL) + { + if (dev->g_pfn_cdc_SetEthernetPowerManagementPatternFilter(dev->cdc_data,dev->SetupPacket.wValue.W)) + { + USB_StatusInStage(dev); /* send Acknowledge */ + goto out_class_ok; + } + } + else + { + goto stall_i; + } + break; + case CDC_SET_ATM_DEFAULT_VC: + if(dev->g_pfn_cdc_SetATMDefaultVC != NULL) + { + if (dev->g_pfn_cdc_SetATMDefaultVC(dev->cdc_data,0)) + { + USB_StatusInStage(dev); /* send Acknowledge */ + goto out_class_ok; + } + } + else + { + goto stall_i; + } + break; + + } + } +#endif /* USB_CDC */ + goto stall_i; + /* end case REQUEST_TO_INTERFACE */ + + case REQUEST_TO_ENDPOINT: +#if USB_AUDIO + switch (dev->SetupPacket.bRequest) + { + case AUDIO_REQUEST_SET_CUR: + // case AUDIO_REQUEST_SET_MIN: + // case AUDIO_REQUEST_SET_MAX: + // case AUDIO_REQUEST_SET_RES: + if(dev->g_pfn_adc_ep_setrequestt != NULL) + { + if (dev->g_pfn_adc_ep_setrequestt(dev->adc_data)) + { + USB_StatusInStage(dev); /* send Acknowledge */ + goto out_class_ok; + } + } + else + { + goto stall_i; + } + break; + } +#endif /* USB_AUDIO */ + goto stall_i; + /* end case REQUEST_TO_ENDPOINT */ + + default: + goto stall_i; + } +out_class_ok: /* request finished successfully */ + break; /* end case REQUEST_CLASS */ +#endif /* USB_CLASS */ + +#if USB_VENDOR + case REQUEST_VENDOR: + switch (dev->SetupPacket.bmRequestType.BM.Recipient) + { + + case REQUEST_TO_DEVICE: + if(dev->g_pfn_vender_device != NULL) + { + if (!dev->g_pfn_vender_device(dev->vender_data, TRUE)) + { + goto stall_i; /* not supported */ + } + } + else + { + goto stall_i; + } + break; + + case REQUEST_TO_INTERFACE: + if(dev->g_pfn_vender_interface != NULL) + { + if (!dev->g_pfn_vender_interface(dev->vender_data, TRUE)) + { + goto stall_i; /* not supported */ + } + } + else + { + goto stall_i; + } + break; + + case REQUEST_TO_ENDPOINT: + if(dev->g_pfn_vender_endpoint != NULL) + { + if (!dev->g_pfn_vender_endpoint(dev->vender_data, TRUE)) + { + goto stall_i; /* not supported */ + } + } + else + { + goto stall_i; + } + break; + + default: + goto stall_i; + } + + USB_StatusInStage(dev); + + break; /* end case REQUEST_VENDOR */ +#endif /* USB_VENDOR */ + + default: + goto stall_i; + } + } + } + } + else + { + USB_StatusOutStage(dev); /* receive Acknowledge */ + } + break; /* end case USB_EVT_OUT */ + + case USB_EVT_IN : + if (dev->SetupPacket.bmRequestType.BM.Dir == REQUEST_DEVICE_TO_HOST) + { + xUSBControlOutEnble(); + USB_DataInStage(dev); /* send data */ + } + else + { + if (dev->USB_DeviceAddress & 0x80) + { + dev->USB_DeviceAddress &= 0x7F; + xUSBSetAddress(dev->USB_DeviceAddress); + } + } + break; /* end case USB_EVT_IN */ + + case USB_EVT_OUT_STALL: + xUSBEndpointStallClear(0x00); + break; + + case USB_EVT_IN_STALL: + xUSBEndpointStallClear(0x80); + break; + + } +} + +/********************************************************************************************************//** + * @brief USB_Init - Initialization of the USB + * @param[in] dev : a point which contains all the global variables which using in this function + * @return None +************************************************************************************************************/ +void USB_Init(USB_ENU_Dev *dev) +{ + xUSBEventHandler(0,(xtEventCallback)USB_EndPoint0,(void *)dev ); + xUSBInit(); +} + +/********************************************************************************************************//** + * @brief USB conecet - pull up the USB to conecet to the host + * @param[in] dev : a point which contains all the global variables which using in this function + * @param[in] con : TRUE \ FALSE + * @return None +************************************************************************************************************/ +void USB_conecet(USB_ENU_Dev *dev, uint32_t con) +{ + xUSBConnect(con); +} + + diff --git a/CoX/middleware/USB_ENUMERATE/usb_Enumerate.h b/CoX/middleware/USB_ENUMERATE/usb_Enumerate.h new file mode 100644 index 00000000..a0c00904 --- /dev/null +++ b/CoX/middleware/USB_ENUMERATE/usb_Enumerate.h @@ -0,0 +1,185 @@ +/***************************************************************************** + * U S B - C O M M O M - C O M P O N E N T + ****************************************************************************/ +/** + * @file : usb_Enumerate.h + * @brief : USB Enumerate Definitions + * @version : 1.1 + * @date : 3. Mar. 2011 + * @author : CooCox + ****************************************************************************/ +#ifndef __USB_ENUMERATE_H__ +#define __USB_ENUMERATE_H__ +#include "xusb.h" +#include "usb.h" +#include "type.h" +#include "usb_desc.h" +#include "usb_com_config.h" + +#if (USB_CLASS) + +#if (USB_AUDIO) +typedef uint32_t (PFN_ADC_CALLBACK)(void *data); +#include "usb_audio.h" +#include "usb_adc_config.h" +#endif + +#if (USB_HID) +typedef uint32_t (PFN_HID_CALLBACK)(void *data); +#include "usb_hid.h" +#include "usb_hid_config.h" +#endif + +#if (USB_MSC) +typedef uint32_t (PFN_MSC_CALLBACK)(void *data,uint32_t para); +#include"usb_msc_config.h" +#include"usb_msc.h" +#endif + +#if (USB_CDC) +typedef uint32_t (PFN_CDC_CALLBACK)(void *data,uint32_t para); +#include "usb_cdc.h" +#include "usb_cdc_config.h" +#endif + +#endif + +#if (USB_VENDOR) +//#include "vendor.h" +typedef uint32_t (PFN_VENDOR_CALLBACK)(void *data,uint32_t para); +#endif + +/*********************************************************************** + * USB BUS event call back function definition + **********************************************************************/ +typedef void (PFN_CONFIG_CALLBACK)(uint32_t event); + +/*********************************************************************** + * USB end point event call back function definition + **********************************************************************/ +typedef void (PFN_EP_CALLBACK)(void *data,uint32_t event); + +/** + * @brief USB End Point Data Structure + */ +typedef struct _USB_EP_DATA { + uint8_t *pData; /**< point of EP data */ + uint16_t Count; /**< count of EP data */ +} USB_EP_DATA; + +/** + * @brief USB Enumerate Structure + */ +typedef struct +{ + //COX_USB_PI *usb; /**< USB Peripheral Interface Used */ + + PFN_CONFIG_CALLBACK *g_pfn_config_callback; + PFN_CONFIG_CALLBACK *g_pfn_reset_callback; + PFN_CONFIG_CALLBACK *g_pfn_suspend_callback; + PFN_CONFIG_CALLBACK *g_pfn_resume_callback; + PFN_CONFIG_CALLBACK *g_pfn_wakeup_callback; + PFN_CONFIG_CALLBACK *g_pfn_interfacec_callback; + PFN_CONFIG_CALLBACK *g_pfn_feature_callback; + + const uint8_t *USB_DeviceDescriptor; + const uint8_t *USB_ConfigDescriptor; + const uint8_t *USB_StringDescriptor; + +#if (USB_AUDIO) + + void *adc_data; + PFN_ADC_CALLBACK *g_pfn_adc_if_getrequestt; + PFN_ADC_CALLBACK *g_pfn_adc_if_setrequestt; + PFN_ADC_CALLBACK *g_pfn_adc_ep_getrequestt; + PFN_ADC_CALLBACK *g_pfn_adc_ep_setrequestt; + +#endif +#if (USB_HID) + const uint8_t *HID_ReportDescriptor; + void *hid_data; + PFN_HID_CALLBACK *g_pfn_hid_get_report; + PFN_HID_CALLBACK *g_pfn_hid_set_report; + PFN_HID_CALLBACK *g_pfn_hid_get_idle; + PFN_HID_CALLBACK *g_pfn_hid_set_idle; + PFN_HID_CALLBACK *g_pfn_hid_get_procotol; + PFN_HID_CALLBACK *g_pfn_hid_set_procotol; + +#endif + +#if (USB_MSC) + void *msc_data; + PFN_MSC_CALLBACK *g_pfn_msc_request_adsc; + PFN_MSC_CALLBACK *g_pfn_msc_request_get_req; + PFN_MSC_CALLBACK *g_pfn_msc_request_put_req; + PFN_MSC_CALLBACK *g_pfn_msc_request_reset; + PFN_MSC_CALLBACK *g_pfn_msc_request_get_max_lun; +#endif +#if (USB_CDC) + void *cdc_data; + PFN_CDC_CALLBACK *g_pfn_cdc_SendEncapsulatedCommand; + PFN_CDC_CALLBACK *g_pfn_cdc_GetEncapsulatedResponse; + PFN_CDC_CALLBACK *g_pfn_cdc_SetCommFeature; + PFN_CDC_CALLBACK *g_pfn_cdc_GetCommFeature; + PFN_CDC_CALLBACK *g_pfn_cdc_ClearCommFeature ; + PFN_CDC_CALLBACK *g_pfn_cdc_SetAuxLineState; + PFN_CDC_CALLBACK *g_pfn_cdc_SetHookState; + PFN_CDC_CALLBACK *g_pfn_cdc_PulseSetup; + PFN_CDC_CALLBACK *g_pfn_cdc_SendPulse; + PFN_CDC_CALLBACK *g_pfn_cdc_SetPulseTime; + PFN_CDC_CALLBACK *g_pfn_cdc_RingAuxJack ; + PFN_CDC_CALLBACK *g_pfn_cdc_GetLineCoding; + PFN_CDC_CALLBACK *g_pfn_cdc_SetLineCoding; + PFN_CDC_CALLBACK *g_pfn_cdc_SetControlLineState; + PFN_CDC_CALLBACK *g_pfn_cdc_SendBreak; + PFN_CDC_CALLBACK *g_pfn_cdc_SetRingerParms; + PFN_CDC_CALLBACK *g_pfn_cdc_GetRingerParms; + PFN_CDC_CALLBACK *g_pfn_cdc_SetOperationParms; + PFN_CDC_CALLBACK *g_pfn_cdc_GetOperationParms; + PFN_CDC_CALLBACK *g_pfn_cdc_SetLineParms; + PFN_CDC_CALLBACK *g_pfn_cdc_GetLineParms; + PFN_CDC_CALLBACK *g_pfn_cdc_DialDigits; + PFN_CDC_CALLBACK *g_pfn_cdc_SetUnitParameter; + PFN_CDC_CALLBACK *g_pfn_cdc_GetUnitParameter; + PFN_CDC_CALLBACK *g_pfn_cdc_ClearUnitParameter; + PFN_CDC_CALLBACK *g_pfn_cdc_GetProfile; + PFN_CDC_CALLBACK *g_pfn_cdc_SetEthernetMulticastFilters; + PFN_CDC_CALLBACK *g_pfn_cdc_SetEthernetPowerManagementPatternFilter; + PFN_CDC_CALLBACK *g_pfn_cdc_GetEthernetPowerManagementPatternFilter; + PFN_CDC_CALLBACK *g_pfn_cdc_SetEthernetPacketFilter; + PFN_CDC_CALLBACK *g_pfn_cdc_GetEthernetStatistic ; + PFN_CDC_CALLBACK *g_pfn_cdc_SetATMDataFormat ; + PFN_CDC_CALLBACK *g_pfn_cdc_GetATMDeviceStatistics ; + PFN_CDC_CALLBACK *g_pfn_cdc_SetATMDefaultVC ; + PFN_CDC_CALLBACK *g_pfn_cdc_GetATMVCStatistics ; + +#endif + +#if (USB_VENDOR) + void *vender_data; + PFN_VENDOR_CALLBACK *g_pfn_vender_device; + PFN_VENDOR_CALLBACK *g_pfn_vender_interface; + PFN_VENDOR_CALLBACK *g_pfn_vender_endpoint; +#endif + + uint16_t USB_DeviceStatus; + uint8_t USB_DeviceAddress; + uint8_t USB_Configuration; + uint32_t USB_EndPointMask; + uint32_t USB_EndPointHalt; + uint32_t USB_EndPointStall; + uint8_t USB_NumInterfaces; + uint8_t USB_AltSetting[1]; + uint8_t EP0Buf[USB_MAX_PACKET0]; + USB_EP_DATA EP0Data; + USB_SETUP_PACKET SetupPacket; + +} USB_ENU_Dev; + + +/*********************************************************************** + * extern API of this component + **********************************************************************/ +extern void USB_Init(USB_ENU_Dev *dev); + +#endif /* __USB_ENUMERATE_H__ */ diff --git a/CoX/middleware/USB_ENUMERATE/usb_com_config.h b/CoX/middleware/USB_ENUMERATE/usb_com_config.h new file mode 100644 index 00000000..9ab0844e --- /dev/null +++ b/CoX/middleware/USB_ENUMERATE/usb_com_config.h @@ -0,0 +1,36 @@ +/***************************************************************************** + * U S B - C O M M O M - C O M P O N E N T + ****************************************************************************/ +/** + * @file : usb_com_config.h + * @brief : usb_com_config + * Microprocessors + * @version : 1.0 + * @date : 28. Dec. 2010 + * @author : CooCox + ****************************************************************************/ +#ifndef __USB_COM_CONFIG_H__ +#define __USB_COM_CONFIG_H__ + +#define USB_POWER 0 /*!<0=> Bus-powered,1=> Self-powered */ +#define USB_IF_NUM 1 /*! */ +#define USB_LOGIC_EP_NUM 16 /*! */ +#define USB_MAX_PACKET0 64 /*! */ +#define USB_MSC 1 /*! */ +#define USB_AUDIO 0 /*!