Core kernel code:

Allow the stats formatting functions to be built in without stdio.h being included inside tasks.c.

Kernel port code:
- Slight change to the Cortex-A GIC-less port to move all non portable code to the application level.

SAMA5D4 demo project:
- Update the Atmel provided library to V1.1.
- Create a DDR build configuration.
- Ensure interrupts are all edge sensitive.
- Update the regtest code to use all 32 flop registers.
This commit is contained in:
Richard Barry 2014-10-15 21:01:31 +00:00
parent e3263bb9b3
commit ca22607d14
75 changed files with 12981 additions and 495 deletions

View File

@ -186,8 +186,6 @@ uint8_t *pc1, *pc2;
usTemp = ( ( *pc2 ) << 8 ) | *pc1;
return usTemp;
#warning The above code replaces the line below to ensure aborts are not received due to unaligned accesses. Alternatively use the --no_unaligned_access compiler option.
//return endpoint->wMaxPacketSize;
}
/**
@ -208,15 +206,9 @@ uint8_t USBEndpointDescriptor_GetInterval(
* \param configuration Pointer to a USBConfigurationDescriptor instance.
* \return Total length (in bytes) of the configuration.
*/
volatile unsigned long ulCount = 0;
uint32_t USBConfigurationDescriptor_GetTotalLength(
const USBConfigurationDescriptor *configuration)
{
ulCount++;
if( ulCount == 5 )
{
__asm volatile( "NOP" );
}
return configuration->wTotalLength;
}

View File

@ -54,7 +54,6 @@
WEAK void USBDCallbacks_Initialized(void)
{
/* Does nothing */
__asm volatile( "NOP" );
}
/**

View File

@ -114,7 +114,7 @@ void vConfigureTickInterrupt( void )
is shared with other system peripherals, so System_Handler() must be
installed in place of FreeRTOS_Tick_Handler() if other system handlers are
required. The tick must be given the lowest priority (0 in the SAMA5 AIC) */
IRQ_ConfigureIT( ID_PIT, 0, FreeRTOS_Tick_Handler );
IRQ_ConfigureIT( ID_PIT, AIC_SMR_SRCTYPE_EXT_POSITIVE_EDGE, FreeRTOS_Tick_Handler );
/* See commend directly above IRQ_ConfigureIT( ID_PIT, 0, System_Handler ); */
IRQ_EnableIT( ID_PIT );
PIT_EnableIT();

View File

@ -214,7 +214,7 @@
</option>
<option>
<name>CCDiagSuppress</name>
<state>Pa131</state>
<state>Pa131, Pa039</state>
</option>
<option>
<name>CCDiagRemark</name>

View File

@ -97,7 +97,7 @@
/* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,
or 0 to run the more comprehensive test and demo application. */
#define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 0
#define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 1
/*-----------------------------------------------------------*/
@ -124,11 +124,8 @@ void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
void vApplicationTickHook( void );
/* Prototype for the IRQ handler called by the generic Cortex-A5 RTOS port
layer. The address of the ISR is passed into this function as a parameter.
Note this level of indirection could be removed by creating a SAMA5 specific
port layer that calls the IRQ directly from the port layer rather than via this
application callback. */
void vApplicationIRQHandler( uint32_t ulInterruptVectorAddress );
layer. */
void vApplicationIRQHandler( void );
/*-----------------------------------------------------------*/
@ -164,7 +161,12 @@ static void prvSetupHardware( void )
/* Configure ports used by LEDs. */
vParTestInitialise();
CP15_EnableIcache();
#if defined (ddram)
MMU_Initialize( ( uint32_t * ) 0x30C000 );
CP15_EnableMMU();
CP15_EnableDcache();
CP15_EnableIcache();
#endif
}
/*-----------------------------------------------------------*/
@ -175,8 +177,9 @@ void vApplicationMallocFailedHook( void )
internally by FreeRTOS API functions that create tasks, queues, software
timers, and semaphores. The size of the FreeRTOS heap is set by the
configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
taskDISABLE_INTERRUPTS();
for( ;; );
/* Force an assert. */
configASSERT( ( volatile void * ) NULL );
}
/*-----------------------------------------------------------*/
@ -188,8 +191,9 @@ void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
/* Run time stack overflow checking is performed if
configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
function is called if a stack overflow is detected. */
taskDISABLE_INTERRUPTS();
for( ;; );
/* Force an assert. */
configASSERT( ( volatile void * ) NULL );
}
/*-----------------------------------------------------------*/
@ -251,19 +255,19 @@ void vApplicationTickHook( void )
/* The function called by the RTOS port layer after it has managed interrupt
entry. */
void vApplicationIRQHandler( uint32_t ulInterruptVectorAddress )
void vApplicationIRQHandler( void )
{
typedef void (*ISRFunction_t)( void );
ISRFunction_t pxISRFunction;
volatile uint32_t * pulAIC_IVR = ( uint32_t * ) configINTERRUPT_VECTOR_ADDRESS;
/* On the SAMA5 the parameter is a pointer to the ISR handling function. */
pxISRFunction = ( ISRFunction_t ) ulInterruptVectorAddress;
/* Obtain the address of the interrupt handler from the AIR. */
pxISRFunction = ( ISRFunction_t ) *pulAIC_IVR;
/* Write back to the SAMA5's interrupt controller's IVR register in case the
CPU is in protect mode. If the interrupt controller is not in protect mode
then this write is not necessary. */
*pulAIC_IVR = 0;
*pulAIC_IVR = ( uint32_t ) pxISRFunction;
/* Ensure the write takes before re-enabling interrupts. */
__DSB();

View File

@ -51,20 +51,20 @@
</Tab>
</Tabs>
<SelectedTab>0</SelectedTab></Wnd0><Wnd5><Tabs><Tab><Identity>TabID-31713-7906</Identity><TabName>Debug Log</TabName><Factory>Debug-Log</Factory><Session/></Tab></Tabs><SelectedTab>0</SelectedTab></Wnd5></Windows>
<SelectedTab>0</SelectedTab></Wnd0><Wnd3><Tabs><Tab><Identity>TabID-31713-7906</Identity><TabName>Debug Log</TabName><Factory>Debug-Log</Factory><Session/></Tab></Tabs><SelectedTab>0</SelectedTab></Wnd3></Windows>
<Editor>
<Pane><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\main.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>127</YPos2><SelStart2>6411</SelStart2><SelEnd2>6411</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\Full_Demo\main_full.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>63</YPos2><SelStart2>0</SelStart2><SelEnd2>0</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\blinky_demo\main_blinky.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>63</YPos2><SelStart2>1373</SelStart2><SelEnd2>1373</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\..\Common\Minimal\GenQTest.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>796</YPos2><SelStart2>27238</SelStart2><SelEnd2>27238</SelEnd2></Tab><ActiveTab>3</ActiveTab></Pane><ActivePane>0</ActivePane><Sizes><Pane><X>1000000</X><Y>1000000</Y></Pane></Sizes><SplitMode>1</SplitMode></Editor>
<Pane><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\CDCCommandConsole.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>441</YPos2><SelStart2>16342</SelStart2><SelEnd2>16359</SelEnd2></Tab><ActiveTab>0</ActiveTab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\main.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>111</YPos2><SelStart2>6131</SelStart2><SelEnd2>6131</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\..\..\Source\portable\IAR\ARM_CA5_No_GIC\portASM.s</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>117</YPos2><SelStart2>5123</SelStart2><SelEnd2>5123</SelEnd2></Tab></Pane><ActivePane>0</ActivePane><Sizes><Pane><X>1000000</X><Y>1000000</Y></Pane></Sizes><SplitMode>1</SplitMode></Editor>
<Positions>
<Top><Row0><Sizes><Toolbar-011172A8><key>iaridepm.enu1</key></Toolbar-011172A8></Sizes></Row0><Row1><Sizes><Toolbar-07251300><key>debuggergui.enu1</key></Toolbar-07251300></Sizes></Row1></Top><Left><Row0><Sizes><Wnd0><Rect><Top>-2</Top><Left>-2</Left><Bottom>718</Bottom><Right>332</Right><x>-2</x><y>-2</y><xscreen>200</xscreen><yscreen>200</yscreen><sizeHorzCX>119048</sizeHorzCX><sizeHorzCY>203252</sizeHorzCY><sizeVertCX>198810</sizeVertCX><sizeVertCY>731707</sizeVertCY></Rect></Wnd0></Sizes></Row0></Left><Right><Row0><Sizes/></Row0></Right><Bottom><Row0><Sizes><Wnd5><Rect><Top>-2</Top><Left>-2</Left><Bottom>198</Bottom><Right>1682</Right><x>-2</x><y>-2</y><xscreen>1684</xscreen><yscreen>200</yscreen><sizeHorzCX>1002381</sizeHorzCX><sizeHorzCY>203252</sizeHorzCY><sizeVertCX>119048</sizeVertCX><sizeVertCY>203252</sizeVertCY></Rect></Wnd5></Sizes></Row0></Bottom><Float><Sizes/></Float></Positions>
<Top><Row0><Sizes><Toolbar-002781D8><key>iaridepm.enu1</key></Toolbar-002781D8></Sizes></Row0><Row1><Sizes><Toolbar-1A6225A0><key>debuggergui.enu1</key></Toolbar-1A6225A0></Sizes></Row1></Top><Left><Row0><Sizes><Wnd0><Rect><Top>-2</Top><Left>-2</Left><Bottom>718</Bottom><Right>332</Right><x>-2</x><y>-2</y><xscreen>200</xscreen><yscreen>200</yscreen><sizeHorzCX>119048</sizeHorzCX><sizeHorzCY>203252</sizeHorzCY><sizeVertCX>198810</sizeVertCX><sizeVertCY>731707</sizeVertCY></Rect></Wnd0></Sizes></Row0></Left><Right><Row0><Sizes/></Row0></Right><Bottom><Row0><Sizes><Wnd3><Rect><Top>-2</Top><Left>-2</Left><Bottom>198</Bottom><Right>1682</Right><x>-2</x><y>-2</y><xscreen>1684</xscreen><yscreen>200</yscreen><sizeHorzCX>1002381</sizeHorzCX><sizeHorzCY>203252</sizeHorzCY><sizeVertCX>119048</sizeVertCX><sizeVertCY>203252</sizeVertCY></Rect></Wnd3></Sizes></Row0></Bottom><Float><Sizes/></Float></Positions>
</Desktop>
</Project>

View File

@ -14,7 +14,7 @@ Watch0=_ 0 "" 0 "" 0 "" 0 "" 0 0 0 0
Watch1=_ 0 "" 0 "" 0 "" 0 "" 0 0 0 0
CStepIntDis=_ 0
[DebugChecksum]
Checksum=-1280642381
Checksum=1420081031
[Exceptions]
StopOnUncaught=_ 0
StopOnThrow=_ 0
@ -42,8 +42,9 @@ Exclusions=
[Disassemble mode]
mode=0
[Breakpoints2]
Bp0=_ 1 "EMUL_CODE" "{$PROJ_DIR$\main.c}.221.2" 0 0 1 "" 0 "" 0
Count=1
Bp0=_ 1 "EMUL_CODE" "{$PROJ_DIR$\main.c}.229.3" 0 0 1 "" 0 "" 0
Bp1=_ 1 "EMUL_CODE" "{$PROJ_DIR$\CDCCommandConsole.c}.397.9" 0 0 1 "" 0 "" 0
Count=2
[Aliases]
Count=0
SuppressDialog=0

View File

@ -32,11 +32,11 @@
<ColumnWidth0>20</ColumnWidth0><ColumnWidth1>1216</ColumnWidth1><ColumnWidth2>324</ColumnWidth2><ColumnWidth3>81</ColumnWidth3></Build>
<Debug-Log><ColumnWidth0>18</ColumnWidth0><ColumnWidth1>1624</ColumnWidth1></Debug-Log><TerminalIO/><Select-Ambiguous-Definitions><ColumnWidth0>552</ColumnWidth0><ColumnWidth1>78</ColumnWidth1><ColumnWidth2>946</ColumnWidth2></Select-Ambiguous-Definitions><Find-in-Files><ColumnWidth0>497</ColumnWidth0><ColumnWidth1>82</ColumnWidth1><ColumnWidth2>746</ColumnWidth2><ColumnWidth3>331</ColumnWidth3></Find-in-Files><Breakpoints><col-names><item>Breakpoint</item><item>_I0</item></col-names><col-widths><item>500</item><item>35</item></col-widths><PreferedWindows><Position>3</Position><ScreenPosX>0</ScreenPosX><ScreenPosY>0</ScreenPosY><Windows/></PreferedWindows></Breakpoints></Static>
<Debug-Log><ColumnWidth0>18</ColumnWidth0><ColumnWidth1>1624</ColumnWidth1></Debug-Log><TerminalIO/><Select-Ambiguous-Definitions><ColumnWidth0>552</ColumnWidth0><ColumnWidth1>78</ColumnWidth1><ColumnWidth2>946</ColumnWidth2></Select-Ambiguous-Definitions><Find-in-Files><ColumnWidth0>846</ColumnWidth0><ColumnWidth1>82</ColumnWidth1><ColumnWidth2>746</ColumnWidth2><ColumnWidth3>331</ColumnWidth3></Find-in-Files><Breakpoints><col-names><item>Breakpoint</item><item>_I0</item></col-names><col-widths><item>500</item><item>35</item></col-widths><PreferedWindows><Position>3</Position><ScreenPosX>0</ScreenPosX><ScreenPosY>0</ScreenPosY><Windows/></PreferedWindows></Breakpoints></Static>
<Windows>
<Wnd0>
<Wnd2>
<Tabs>
<Tab>
<Identity>TabID-22351-19008</Identity>
@ -48,7 +48,7 @@
</Tab>
</Tabs>
<SelectedTab>0</SelectedTab></Wnd0><Wnd2>
<SelectedTab>0</SelectedTab></Wnd2><Wnd3>
<Tabs>
<Tab>
<Identity>TabID-21076-19237</Identity>
@ -58,20 +58,20 @@
</Tab>
<Tab><Identity>TabID-23502-23081</Identity><TabName>Debug Log</TabName><Factory>Debug-Log</Factory><Session/></Tab><Tab><Identity>TabID-24431-23894</Identity><TabName>Ambiguous Definitions</TabName><Factory>Select-Ambiguous-Definitions</Factory><Session/></Tab><Tab><Identity>TabID-9033-6116</Identity><TabName>Find in Files</TabName><Factory>Find-in-Files</Factory><Session/></Tab></Tabs>
<SelectedTab>0</SelectedTab></Wnd2></Windows>
<SelectedTab>0</SelectedTab></Wnd3></Windows>
<Editor>
<Pane><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\main.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>63</YPos2><SelStart2>5074</SelStart2><SelEnd2>5074</SelEnd2></Tab><ActiveTab>0</ActiveTab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\Full_Demo\main_full.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>63</YPos2><SelStart2>0</SelStart2><SelEnd2>0</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\blinky_demo\main_blinky.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>63</YPos2><SelStart2>1373</SelStart2><SelEnd2>1373</SelEnd2></Tab></Pane><ActivePane>0</ActivePane><Sizes><Pane><X>1000000</X><Y>1000000</Y></Pane></Sizes><SplitMode>1</SplitMode></Editor>
<Pane><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\main.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>63</YPos2><SelStart2>5118</SelStart2><SelEnd2>5118</SelEnd2></Tab><ActiveTab>0</ActiveTab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\blinky_demo\main_blinky.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>63</YPos2><SelStart2>0</SelStart2><SelEnd2>0</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\Full_Demo\main_full.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>63</YPos2><SelStart2>924</SelStart2><SelEnd2>924</SelEnd2></Tab></Pane><ActivePane>0</ActivePane><Sizes><Pane><X>1000000</X><Y>1000000</Y></Pane></Sizes><SplitMode>1</SplitMode></Editor>
<Positions>
<Top><Row0><Sizes><Toolbar-011172A8><key>iaridepm.enu1</key></Toolbar-011172A8></Sizes></Row0><Row1><Sizes/></Row1></Top><Left><Row0><Sizes><Wnd0><Rect><Top>-2</Top><Left>-2</Left><Bottom>668</Bottom><Right>352</Right><x>-2</x><y>-2</y><xscreen>190</xscreen><yscreen>170</yscreen><sizeHorzCX>113095</sizeHorzCX><sizeHorzCY>172764</sizeHorzCY><sizeVertCX>210714</sizeVertCX><sizeVertCY>680894</sizeVertCY></Rect></Wnd0></Sizes></Row0></Left><Right><Row0><Sizes/></Row0></Right><Bottom><Row0><Sizes><Wnd2><Rect><Top>-2</Top><Left>-2</Left><Bottom>272</Bottom><Right>1682</Right><x>-2</x><y>-2</y><xscreen>1684</xscreen><yscreen>274</yscreen><sizeHorzCX>1002381</sizeHorzCX><sizeHorzCY>278455</sizeHorzCY><sizeVertCX>113095</sizeVertCX><sizeVertCY>172764</sizeVertCY></Rect></Wnd2></Sizes></Row0></Bottom><Float><Sizes/></Float></Positions>
<Top><Row0><Sizes><Toolbar-002781D8><key>iaridepm.enu1</key></Toolbar-002781D8></Sizes></Row0><Row1><Sizes/></Row1></Top><Left><Row0><Sizes><Wnd2><Rect><Top>-2</Top><Left>-2</Left><Bottom>668</Bottom><Right>352</Right><x>-2</x><y>-2</y><xscreen>190</xscreen><yscreen>170</yscreen><sizeHorzCX>113095</sizeHorzCX><sizeHorzCY>172764</sizeHorzCY><sizeVertCX>210714</sizeVertCX><sizeVertCY>680894</sizeVertCY></Rect></Wnd2></Sizes></Row0></Left><Right><Row0><Sizes/></Row0></Right><Bottom><Row0><Sizes><Wnd3><Rect><Top>-2</Top><Left>-2</Left><Bottom>272</Bottom><Right>1682</Right><x>-2</x><y>-2</y><xscreen>1684</xscreen><yscreen>274</yscreen><sizeHorzCX>1002381</sizeHorzCX><sizeHorzCY>278455</sizeHorzCY><sizeVertCX>113095</sizeVertCX><sizeVertCY>172764</sizeVertCY></Rect></Wnd3></Sizes></Row0></Bottom><Float><Sizes/></Float></Positions>
</Desktop>
</Workspace>

View File

@ -1,2 +1,2 @@
[MainWindow]
WindowPlacement=_ 68 69 855 818 3
WindowPlacement=_ 90 4 1190 900 3

View File

@ -105,6 +105,22 @@ typedef void (*fGmacdTransferCallback)(uint32_t status);
/** Wakeup callback */
typedef void (*fGmacdWakeupCallback)(void);
/**
* GMAC scatter-gather entry.
*/
typedef struct _GmacSG {
uint32_t size;
void *pBuffer;
} sGmacSG;
/**
* GMAC scatter-gather list.
*/
typedef struct _GmacSGList {
uint32_t len;
sGmacSG *sg;
} sGmacSGList;
/**
* GMAC driver struct.
*/
@ -175,6 +191,10 @@ extern uint8_t GMACD_InitTransfer( sGmacd *pGmacd,
extern void GMACD_Reset(sGmacd *pGmacd);
extern uint8_t GMACD_SendSG(sGmacd *pGmacd,
const sGmacSGList *sgl,
fGmacdTransferCallback fTxCb);
extern uint8_t GMACD_Send(sGmacd *pGmacd,
void *pBuffer,
uint32_t size,

View File

@ -6,13 +6,13 @@ define symbol __ICFEDIT_region_RAM_start__ = 0x200000;
define symbol __ICFEDIT_region_RAM_end__ = 0x21FFFF;
/*-Sizes-*/
define symbol __ICFEDIT_size_vectors__ = 0x100;
define symbol __ICFEDIT_size_cstack__ = 0x4000;
define symbol __ICFEDIT_size_irqstack__ = 0x60;
define symbol __ICFEDIT_size_cstack__ = 0x900;
define symbol __ICFEDIT_size_irqstack__ = 0x400;
define symbol __ICFEDIT_size_fiqstack__ = 0x60;
define symbol __ICFEDIT_size_abtstack__ = 0x60;
define symbol __ICFEDIT_size_undstack__ = 0x40;
define symbol __ICFEDIT_size_heap__ = 0x400;
define symbol __ICFEDIT_size_heap__ = 0x0;
/*-Exports-*/
export symbol __ICFEDIT_region_RAM_start__;
export symbol __ICFEDIT_region_RAM_end__;
@ -35,7 +35,7 @@ define block ABT_STACK with alignment = 8, size = __ICFEDIT_size_abtstack__ { };
define block UND_STACK with alignment = 8, size = __ICFEDIT_size_undstack__ { };
define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { };
initialize by copy with packing=none { readwrite };
initialize by copy with packing=none { readwrite };
do not initialize { readonly section .noinit };
place in VEC_region { section .vectors };

View File

@ -208,6 +208,7 @@ void v_ARM_ClrCPSR_bits(unsigned int mask)
asm("AND R0, R0, R1"); // Calculate new CPSR value
asm("MSR CPSR_c,R0"); // Set new value
asm("bx lr");
( void ) mask;
}
void Dummy_Handler( void );
@ -285,23 +286,15 @@ void Spurious_Handler( void );
/**
* \brief Dummy default handler.
*/
volatile uint32_t ulx = 0;
void Dummy_Handler( void )
{
while ( ulx == 0 )
{
__asm volatile( "NOP" );
}
ulx = 0;
while ( 1 ) ;
}
volatile uint32_t ulSpuriousCount = 0;
void Spurious_Handler( void )
{
while ( ulx == 0 )
{
__asm volatile( "NOP" );
}
ulx = 0;
ulSpuriousCount++;
}
/**

View File

@ -27,12 +27,12 @@
* ----------------------------------------------------------------------------
*/
/** \addtogroup ddrd_module
/** \addtogroup ddrd_module
*
* The DDR/SDR SDRAM Controller (DDRSDRC) is a multiport memory controller. It comprises
* four slave AHB interfaces. All simultaneous accesses (four independent AHB ports) are interleaved
* to maximize memory bandwidth and minimize transaction latency due to SDRAM protocol.
*
*
* \section ddr2 Configures DDR2
*
* The DDR2-SDRAM devices are initialized by the following sequence:
@ -77,8 +77,8 @@
* <li> Step 1. Program the memory device type into the Memory Device Register</li>
* <li> Step 2. Program the features of the SDR-SDRAM device into the Timing Register and into the Configuration Register.</li>
* <li> Step 3. For low-power SDRAM, temperature-compensated self refresh (TCSR), drive strength (DS) and partial array self refresh (PASR) must be set in the Low-power Register.</li>
* <li> Step 4. A NOP command is issued to the SDR-SDRAM. Program NOP command into Mode Register, the application must
* set Mode to 1 in the Mode Register. Perform a write access to any SDR-SDRAM address to acknowledge this command.
* <li> Step 4. A NOP command is issued to the SDR-SDRAM. Program NOP command into Mode Register, the application must
* set Mode to 1 in the Mode Register. Perform a write access to any SDR-SDRAM address to acknowledge this command.
* Now the clock which drives SDR-SDRAM device is enabled.</li>
* <li> Step 5. An all banks precharge command is issued to the SDR-SDRAM. Program all banks precharge command into Mode Register, the application must set Mode to 2 in the
* Mode Register . Perform a write access to any SDRSDRAM address to acknowledge this command.</li>
@ -95,8 +95,8 @@
/*@{*/
/*@}*/
/**
* \file
*
@ -104,7 +104,7 @@
*
*/
/*----------------------------------------------------------------------------
* Headers
*----------------------------------------------------------------------------*/
@ -139,8 +139,9 @@ void BOARD_RemapRam( void )
*/
void BOARD_ConfigureVddMemSel( uint8_t VddMemSel )
{
( void ) VddMemSel;
}
#define DDR2_BA0(r) (1 << (26 + r))
#define DDR2_BA1(r) (1 << (27 + r))
@ -149,17 +150,17 @@ void BOARD_ConfigureVddMemSel( uint8_t VddMemSel )
static void matrix_configure_slave_ddr(void)
{
int ddr_port;
/* Disable write protection */
MATRIX0->MATRIX_WPMR = MPDDRC_WPMR_WPKEY_PASSWD;
/* Partition internal SRAM */
MATRIX0->MATRIX_SSR[11] = 0;
MATRIX0->MATRIX_SRTSR[11] = 0x05;
MATRIX0->MATRIX_SASSR[11] = 0x04;
ddr_port = 1;
/* Partition external DDR */
/* DDR port 0 not used from NWd */
for (ddr_port = 1 ; ddr_port < 8 ; ddr_port++) {
@ -198,7 +199,7 @@ static void matrix_configure_slave_nand(void)
Refresh count: 8K
Row address: A[12:0] (8K)
Column address A[9:0] (1K)
Bank address BA[2:0] a(24,25) (8)
Bank address BA[2:0] a(24,25) (8)
*/
void BOARD_ConfigureDdram( void )
{
@ -206,13 +207,13 @@ void BOARD_ConfigureDdram( void )
volatile uint32_t i;
volatile uint32_t dummy_value;
matrix_configure_slave_ddr();
/* Enable DDR2 clock x2 in PMC */
PMC->PMC_PCER0 = (1 << (ID_MPDDRC));
PMC->PMC_SCER |= PMC_SCER_DDRCK;
/* MPDDRC I/O Calibration Register */
dummy_value = MPDDRC->MPDDRC_IO_CALIBR;
dummy_value &= ~MPDDRC_IO_CALIBR_RDIV_Msk;
@ -227,7 +228,7 @@ void BOARD_ConfigureDdram( void )
/* Step 1: Program the memory device type */
/* DBW = 0 (32 bits bus wide); Memory Device = 6 = DDR2-SDRAM = 0x00000006*/
MPDDRC->MPDDRC_MD = MPDDRC_MD_MD_DDR2_SDRAM | MPDDRC_MD_DBW_DBW_32_BITS;
MPDDRC->MPDDRC_MD = MPDDRC_MD_MD_DDR2_SDRAM | MPDDRC_MD_DBW_DBW_32_BITS;
MPDDRC->MPDDRC_RD_DATA_PATH = MPDDRC_RD_DATA_PATH_SHIFT_SAMPLING_SHIFT_ONE_CYCLE;
@ -241,8 +242,8 @@ void BOARD_ConfigureDdram( void )
MPDDRC_CR_NB_8_BANKS |
MPDDRC_CR_NDQS_DISABLED |
MPDDRC_CR_UNAL_SUPPORTED |
MPDDRC_CR_OCD_DDR2_EXITCALIB;
MPDDRC_CR_OCD_DDR2_EXITCALIB;
MPDDRC->MPDDRC_TPR0 = MPDDRC_TPR0_TRAS(8) // 40 ns
| MPDDRC_TPR0_TRCD(3) // 12.5 ns
| MPDDRC_TPR0_TWR(3) // 15 ns
@ -251,14 +252,14 @@ void BOARD_ConfigureDdram( void )
| MPDDRC_TPR0_TRRD(2) // 8 ns
| MPDDRC_TPR0_TWTR(2) // 2 clock cycle
| MPDDRC_TPR0_TMRD(2); // 2 clock cycles
MPDDRC->MPDDRC_TPR1 = MPDDRC_TPR1_TRFC(23)
| MPDDRC_TPR1_TXSNR(25)
| MPDDRC_TPR1_TXSRD(200)
| MPDDRC_TPR1_TXP(2);
MPDDRC->MPDDRC_TPR2 = MPDDRC_TPR2_TXARD(8)
MPDDRC->MPDDRC_TPR2 = MPDDRC_TPR2_TXARD(8)
| MPDDRC_TPR2_TXARDS(2)
| MPDDRC_TPR2_TRPA(3)
| MPDDRC_TPR2_TRTP(2)
@ -267,19 +268,19 @@ void BOARD_ConfigureDdram( void )
/* DDRSDRC Low-power Register */
for (i = 0; i < 13300; i++) {
asm("nop");
}
}
/* Step 3: An NOP command is issued to the DDR2-SDRAM. Program the NOP command into
the Mode Register, the application must set MODE to 1 in the Mode Register. */
MPDDRC->MPDDRC_MR = MPDDRC_MR_MODE_NOP_CMD;
/* Perform a write access to any DDR2-SDRAM address to acknowledge this command */
*pDdr = 0; /* Now clocks which drive DDR2-SDRAM device are enabled.*/
/* A minimum pause of 200 ¦Ìs is provided to precede any signal toggle. (6 core cycles per iteration, core is at 396MHz: min 13200 loops) */
for (i = 0; i < 13300; i++) {
asm("nop");
}
}
/* Step 4: An NOP command is issued to the DDR2-SDRAM */
MPDDRC->MPDDRC_MR = MPDDRC_MR_MODE_NOP_CMD;
/* Perform a write access to any DDR2-SDRAM address to acknowledge this command.*/
@ -288,7 +289,7 @@ void BOARD_ConfigureDdram( void )
for (i = 0; i < 100; i++) {
asm("nop");
}
/* Step 5: An all banks precharge command is issued to the DDR2-SDRAM. */
MPDDRC->MPDDRC_MR = MPDDRC_MR_MODE_PRCGALL_CMD;
/* Perform a write access to any DDR2-SDRAM address to acknowledge this command.*/
@ -332,7 +333,7 @@ void BOARD_ConfigureDdram( void )
for (i = 0; i < 100; i++) {
asm("nop");
}
/* Step 11: An all banks precharge command is issued to the DDR2-SDRAM. */
MPDDRC->MPDDRC_MR = MPDDRC_MR_MODE_PRCGALL_CMD;
*(pDdr) = 0; /* Perform a write access to any DDR2-SDRAM address to acknowledge this command */
@ -357,7 +358,7 @@ void BOARD_ConfigureDdram( void )
}
/* Step 13: Program DLL field into the Configuration Register to low(Disable DLL reset). */
MPDDRC->MPDDRC_CR &= ~MPDDRC_CR_DLL_RESET_ENABLED;
MPDDRC->MPDDRC_CR &= ~MPDDRC_CR_DLL_RESET_ENABLED;
/* Step 14: A Mode Register set (MRS) cycle is issued to program the parameters of the DDR2-SDRAM devices. */
MPDDRC->MPDDRC_MR = MPDDRC_MR_MODE_LMR_CMD;
@ -393,10 +394,10 @@ void BOARD_ConfigureDdram( void )
MPDDRC->MPDDRC_MR = MPDDRC_MR_MODE_NORMAL_CMD;
*(pDdr) = 0;
/* Step 21: Write the refresh rate into the count field in the Refresh Timer register. The DDR2-SDRAM device requires a refresh every 15.625 ¦Ìs or 7.81 ¦Ìs.
/* Step 21: Write the refresh rate into the count field in the Refresh Timer register. The DDR2-SDRAM device requires a refresh every 15.625 ¦Ìs or 7.81 ¦Ìs.
With a 100MHz frequency, the refresh timer count register must to be set with (15.625 /100 MHz) = 1562 i.e. 0x061A or (7.81 /100MHz) = 781 i.e. 0x030d. */
/* For MT47H64M16HR, The refresh period is 64ms (commercial), This equates to an average
refresh rate of 7.8125¦Ìs (commercial), To ensure all rows of all banks are properly
refresh rate of 7.8125¦Ìs (commercial), To ensure all rows of all banks are properly
refreshed, 8192 REFRESH commands must be issued every 64ms (commercial) */
/* ((64 x 10(^-3))/8192) x133 x (10^6) */
MPDDRC->MPDDRC_RTR = MPDDRC_RTR_COUNT(0x2b0); /* Set Refresh timer 7.8125 us*/
@ -447,7 +448,7 @@ void BOARD_ConfigureNandFlash( uint8_t busWidth )
HSMC->HSMC_CS_NUMBER[3].HSMC_MODE = HSMC_MODE_READ_MODE |
HSMC_MODE_WRITE_MODE |
((busWidth == 8 )? HSMC_MODE_DBW_BIT_8 :HSMC_MODE_DBW_BIT_16) |
HSMC_MODE_TDF_CYCLES(1);
HSMC_MODE_TDF_CYCLES(1);
}
@ -455,7 +456,7 @@ void BOARD_ConfigureNorFlash( uint8_t busWidth )
{
uint32_t dbw;
PMC_EnablePeripheral(ID_HSMC);
if (busWidth == 8)
if (busWidth == 8)
{
dbw = HSMC_MODE_DBW_BIT_8;
}

View File

@ -42,8 +42,35 @@
/*----------------------------------------------------------------------------
* Macro
*----------------------------------------------------------------------------*/
/** Memory barriers */
#define rmb() __ASM("dsb ")
#if defined ( __ICCARM__ )
#define wmb() __ASM("dsb #st")
#else
#define wmb() __ASM("dsb st")
#endif
/** ISO/IEC 14882:2003(E) - 5.6 Multiplicative operators:
* The binary / operator yields the quotient, and the binary % operator yields the remainder
* from the division of the first expression by the second.
* If the second operand of / or % is zero the behavior is undefined; otherwise (a/b)*b + a%b is equal to a.
* If both operands are nonnegative then the remainder is nonnegative;
* if not, the sign of the remainder is implementation-defined 74).
*/
static inline int fixed_mod(int a, int b)
{
int rem = a % b;
while (rem < 0)
rem += b;
return rem;
}
/** Return count in buffer */
#define GCIRC_CNT(head,tail,size) (((head) - (tail)) % (size))
#define GCIRC_CNT(head,tail,size) fixed_mod((head) - (tail), (size))
/** Return space available, 0..size-1. always leave one free char as a completely full buffer
has head == tail, which is the same as empty */
@ -53,13 +80,13 @@
so they can change underneath us without returning inconsistent results */
#define GCIRC_CNT_TO_END(head,tail,size) \
({int end = (size) - (tail); \
int n = ((head) + end) % (size); \
int n = fixed_mod((head) + end, (size)); \
n < end ? n : end;})
/** Return space available up to the end of the buffer */
#define GCIRC_SPACE_TO_END(head,tail,size) \
({int end = (size) - 1 - (head); \
int n = (end + (tail)) % (size); \
int n = fixed_mod(end + (tail), (size)); \
n <= end ? n : end+1;})
/** Increment head or tail */
@ -100,6 +127,14 @@
#define GMAC_TX_ERR_BITS \
(GMAC_TX_RLE_BIT | GMAC_TX_UND_BIT | GMAC_TX_ERR_BIT)
// Interrupt bits
#define GMAC_INT_RX_BITS \
(GMAC_IER_RCOMP | GMAC_IER_RXUBR | GMAC_IER_ROVR)
#define GMAC_INT_TX_ERR_BITS \
(GMAC_IER_TUR | GMAC_IER_RLEX | GMAC_IER_TFC)
#define GMAC_INT_TX_BITS \
(GMAC_INT_TX_ERR_BITS | GMAC_IER_TCOMP)
/*---------------------------------------------------------------------------
* Local functions
*---------------------------------------------------------------------------*/
@ -161,7 +196,140 @@ static void GMACD_ResetRx(sGmacd *pDrv )
GMAC_SetRxQueue(pHw, (uint32_t) pRd);
}
/**
* \brief Process successfully sent packets
* \param pGmacd Pointer to GMAC Driver instance.
*/
static void GMACD_TxCompleteHandler(sGmacd *pGmacd)
{
Gmac *pHw = pGmacd->pHw;
sGmacTxDescriptor *pTxTd;
fGmacdTransferCallback fTxCb;
uint32_t tsr;
/* Clear status */
tsr = GMAC_GetTxStatus(pHw);
GMAC_ClearTxStatus(pHw, tsr);
while (!GCIRC_EMPTY(pGmacd->wTxHead, pGmacd->wTxTail)) {
pTxTd = &pGmacd->pTxD[pGmacd->wTxTail];
/* Make hw descriptor updates visible to CPU */
rmb();
/* Exit if frame has not been sent yet:
* On TX completion, the GMAC set the USED bit only into the
* very first buffer descriptor of the sent frame.
* Otherwise it updates this descriptor with status error bits.
* This is the descriptor writeback.
*/
if ((pTxTd->status.val & GMAC_TX_USED_BIT) == 0)
break;
/* Process all buffers of the current transmitted frame */
while ((pTxTd->status.val & GMAC_TX_LAST_BUFFER_BIT) == 0) {
GCIRC_INC(pGmacd->wTxTail, pGmacd->wTxListSize);
pTxTd = &pGmacd->pTxD[pGmacd->wTxTail];
rmb();
}
/* Notify upper layer that a frame has been sent */
fTxCb = pGmacd->fTxCbList[pGmacd->wTxTail];
if (fTxCb)
fTxCb(tsr);
/* Go to next frame */
GCIRC_INC(pGmacd->wTxTail, pGmacd->wTxListSize);
}
/* If a wakeup has been scheduled, notify upper layer that it can
send other packets, send will be successfull. */
if (pGmacd->fWakupCb &&
GCIRC_SPACE(pGmacd->wTxHead,
pGmacd->wTxTail,
pGmacd->wTxListSize) >= pGmacd->bWakeupThreshold)
pGmacd->fWakupCb();
}
/**
* \brief Reset TX queue when errors are detected
* \param pGmacd Pointer to GMAC Driver instance.
*/
static void GMACD_TxErrorHandler(sGmacd *pGmacd)
{
Gmac *pHw = pGmacd->pHw;
sGmacTxDescriptor *pTxTd;
fGmacdTransferCallback fTxCb;
uint32_t tsr;
/* Clear TXEN bit into the Network Configuration Register:
* this is a workaround to recover from TX lockups that
* occur on sama5d3 gmac (r1p24f2) when using scatter-gather.
* This issue has never been seen on sama5d4 gmac (r1p31).
*/
GMAC_TransmitEnable(pHw, 0);
/* The following step should be optional since this function is called
* directly by the IRQ handler. Indeed, according to Cadence
* documentation, the transmission is halted on errors such as
* too many retries or transmit under run.
* However it would become mandatory if the call of this function
* were scheduled as a task by the IRQ handler (this is how Linux
* driver works). Then this function might compete with GMACD_Send().
*
* Setting bit 10, tx_halt, of the Network Control Register is not enough:
* We should wait for bit 3, tx_go, of the Transmit Status Register to
* be cleared at transmit completion if a frame is being transmitted.
*/
GMAC_TransmissionHalt(pHw);
while (GMAC_GetTxStatus(pHw) & GMAC_TSR_TXGO);
/* Treat frames in TX queue including the ones that caused the error. */
while (!GCIRC_EMPTY(pGmacd->wTxHead, pGmacd->wTxTail)) {
int tx_completed = 0;
pTxTd = &pGmacd->pTxD[pGmacd->wTxTail];
/* Make hw descriptor updates visible to CPU */
rmb();
/* Check USED bit on the very first buffer descriptor to validate
* TX completion.
*/
if (pTxTd->status.val & GMAC_TX_USED_BIT)
tx_completed = 1;
/* Go to the last buffer descriptor of the frame */
while ((pTxTd->status.val & GMAC_TX_LAST_BUFFER_BIT) == 0) {
GCIRC_INC(pGmacd->wTxTail, pGmacd->wTxListSize);
pTxTd = &pGmacd->pTxD[pGmacd->wTxTail];
rmb();
}
/* Notify upper layer that a frame status */
fTxCb = pGmacd->fTxCbList[pGmacd->wTxTail];
if (fTxCb)
fTxCb(tx_completed ? GMAC_TSR_TXCOMP : 0); // TODO: which error to notify?
/* Go to next frame */
GCIRC_INC(pGmacd->wTxTail, pGmacd->wTxListSize);
}
/* Reset TX queue */
GMACD_ResetTx(pGmacd);
/* Clear status */
tsr = GMAC_GetTxStatus(pHw);
GMAC_ClearTxStatus(pHw, tsr);
/* Now we are ready to start transmission again */
GMAC_TransmitEnable(pHw, 1);
if (pGmacd->fWakupCb)
pGmacd->fWakupCb();
}
/*---------------------------------------------------------------------------
* Exported functions
*---------------------------------------------------------------------------*/
@ -174,122 +342,36 @@ static void GMACD_ResetRx(sGmacd *pDrv )
void GMACD_Handler(sGmacd *pGmacd )
{
Gmac *pHw = pGmacd->pHw;
sGmacTxDescriptor *pTxTd;
fGmacdTransferCallback *pTxCb = NULL;
uint32_t isr;
uint32_t rsr;
uint32_t tsr;
uint32_t rxStatusFlag;
uint32_t txStatusFlag;
isr = GMAC_GetItStatus(pHw);
rsr = GMAC_GetRxStatus(pHw);
tsr = GMAC_GetTxStatus(pHw);
isr &= ~(GMAC_GetItMask(pHw)| 0xF8030300);
/* Interrupt Status Register is cleared on read */
while ((isr = GMAC_GetItStatus(pHw)) != 0) {
/* RX packet */
if (isr & GMAC_INT_RX_BITS) {
/* Clear status */
rsr = GMAC_GetRxStatus(pHw);
GMAC_ClearRxStatus(pHw, rsr);
/* RX packet */
if ((isr & GMAC_ISR_RCOMP) || (rsr & GMAC_RSR_REC)) {
asm("nop");
rxStatusFlag = GMAC_RSR_REC;
/* Frame received */
/* Check OVR */
if (rsr & GMAC_RSR_RXOVR) {
rxStatusFlag |= GMAC_RSR_RXOVR;
/* Invoke callback */
if (pGmacd->fRxCb)
pGmacd->fRxCb(rsr);
}
/* Check BNA */
if (rsr & GMAC_RSR_BNA) {
rxStatusFlag |= GMAC_RSR_BNA;
}
/* Check HNO */
if (rsr & GMAC_RSR_HNO) {
rxStatusFlag |= GMAC_RSR_HNO;
}
/* Clear status */
GMAC_ClearRxStatus(pHw, rxStatusFlag);
/* Invoke callbacks */
if (pGmacd->fRxCb)
{
pGmacd->fRxCb(rxStatusFlag);
/* TX error */
if (isr & GMAC_INT_TX_ERR_BITS) {
GMACD_TxErrorHandler(pGmacd);
break;
}
/* TX packet */
if (isr & GMAC_IER_TCOMP)
GMACD_TxCompleteHandler(pGmacd);
if (isr & GMAC_IER_HRESP) {
TRACE_ERROR("HRESP\n\r");
}
}
/* TX packet */
if ((isr & GMAC_ISR_TCOMP) || (tsr & GMAC_TSR_TXCOMP)) {
asm("nop");
txStatusFlag = GMAC_TSR_TXCOMP;
/* A frame transmitted Check RLE */
if (tsr & GMAC_TSR_RLE) {
/* Status RLE & Number of discarded buffers */
txStatusFlag = GMAC_TSR_RLE
| GCIRC_CNT(pGmacd->wTxHead,
pGmacd->wTxTail,
pGmacd->wTxListSize);
pTxCb = &pGmacd->fTxCbList[pGmacd->wTxTail];
GMACD_ResetTx(pGmacd);
TRACE_INFO("Tx RLE!!\n\r");
GMAC_TransmitEnable(pHw, 1);
}
/* Check COL */
if (tsr & GMAC_TSR_COL) {
txStatusFlag |= GMAC_TSR_COL;
}
/* Check TFC */
if (tsr & GMAC_TSR_TFC) {
txStatusFlag |= GMAC_TSR_TFC;
}
/* Check UND */
if (tsr & GMAC_TSR_UND) {
txStatusFlag |= GMAC_TSR_UND;
}
/* Check HRESP */
if (tsr & GMAC_TSR_HRESP) {
txStatusFlag |= GMAC_TSR_HRESP;
}
/* Clear status */
GMAC_ClearTxStatus(pHw, txStatusFlag);
if (!GCIRC_EMPTY(pGmacd->wTxHead, pGmacd->wTxTail))
{
/* Check the buffers */
do {
pTxTd = &pGmacd->pTxD[pGmacd->wTxTail];
pTxCb = &pGmacd->fTxCbList[pGmacd->wTxTail];
/* Exit if buffer has not been sent yet */
if ((pTxTd->status.val & (uint32_t)GMAC_TX_USED_BIT) == 0) {
break;
}
/* Notify upper layer that a packet has been sent */
if (*pTxCb) {
(*pTxCb)(txStatusFlag);
}
GCIRC_INC( pGmacd->wTxTail, pGmacd->wTxListSize );
} while (GCIRC_CNT(pGmacd->wTxHead, pGmacd->wTxTail, pGmacd->wTxListSize));
}
if (tsr & GMAC_TSR_RLE) {
/* Notify upper layer RLE */
if (*pTxCb) {
(*pTxCb)(txStatusFlag);
}
}
/* If a wakeup has been scheduled, notify upper layer that it can
send other packets, send will be successfull. */
if((GCIRC_SPACE(pGmacd->wTxHead,
pGmacd->wTxTail,
pGmacd->wTxListSize) >= pGmacd->bWakeupThreshold) && pGmacd->fWakupCb)
{
pGmacd->fWakupCb();
}
}
/* PAUSE Frame */
if (isr & GMAC_ISR_PFNZ) TRACE_INFO("Pause!\n\r");
if (isr & GMAC_ISR_PTZ) TRACE_INFO("Pause TO!\n\r");
}
@ -412,30 +494,12 @@ uint8_t GMACD_InitTransfer( sGmacd *pGmacd,
GMAC_ReceiveEnable(pHw, 1);
GMAC_StatisticsWriteEnable(pHw, 1);
/* Setup the interrupts for TX (and errors) */
GMAC_EnableIt(pHw, GMAC_IER_MFS
|GMAC_IER_RCOMP
|GMAC_IER_RXUBR
|GMAC_IER_TXUBR
|GMAC_IER_TUR
|GMAC_IER_RLEX
|GMAC_IER_TFC
|GMAC_IER_TCOMP
|GMAC_IER_ROVR
|GMAC_IER_HRESP
|GMAC_IER_PFNZ
|GMAC_IER_PTZ
|GMAC_IER_PFTR
|GMAC_IER_EXINT
|GMAC_IER_DRQFR
|GMAC_IER_SFR
|GMAC_IER_DRQFT
|GMAC_IER_SFT
|GMAC_IER_PDRQFR
|GMAC_IER_PDRSFR
|GMAC_IER_PDRQFT
|GMAC_IER_PDRSFT);
//0x03FCFCFF
/* Setup the interrupts for RX/TX completion (and errors) */
GMAC_EnableIt(pHw,
GMAC_INT_RX_BITS |
GMAC_INT_TX_BITS |
GMAC_IER_HRESP);
return GMACD_OK;
}
@ -455,6 +519,102 @@ void GMACD_Reset(sGmacd *pGmacd)
| GMAC_NCR_WESTAT | GMAC_NCR_CLRSTAT);
}
/**
* \brief Send a frame splitted into buffers. If the frame size is larger than transfer buffer size
* error returned. If frame transfer status is monitored, specify callback for each frame.
* \param pGmacd Pointer to GMAC Driver instance.
* \param sgl Pointer to a scatter-gather list describing the buffers of the ethernet frame.
*/
uint8_t GMACD_SendSG(sGmacd *pGmacd,
const sGmacSGList *sgl,
fGmacdTransferCallback fTxCb)
{
Gmac *pHw = pGmacd->pHw;
sGmacTxDescriptor *pTxTd;
uint16_t wTxPos, wTxHead;
int i;
TRACE_DEBUG("GMACD_SendSG\n\r");
/* Check parameter */
if (!sgl->len) {
TRACE_ERROR("GMACD_SendSG: ethernet frame is empty.\r\n");
return GMACD_PARAM;
}
if (sgl->len >= pGmacd->wTxListSize) {
TRACE_ERROR("GMACD_SendSG: ethernet frame has too many buffers.\r\n");
return GMACD_PARAM;
}
/* Check available space */
if (GCIRC_SPACE(pGmacd->wTxHead, pGmacd->wTxTail, pGmacd->wTxListSize) < (int)sgl->len)
return GMACD_TX_BUSY;
/* Tag end of TX queue */
wTxHead = fixed_mod(pGmacd->wTxHead + sgl->len, pGmacd->wTxListSize);
wTxPos = wTxHead;
pGmacd->fTxCbList[wTxPos] = NULL;
pTxTd = &pGmacd->pTxD[wTxPos];
pTxTd->status.val = GMAC_TX_USED_BIT;
/* Update buffer descriptors in reverse order to avoid a race
* condition with hardware.
*/
for (i = (int)(sgl->len-1); i >= 0; --i) {
const sGmacSG *sg = &sgl->sg[i];
uint32_t status;
if (sg->size > GMAC_TX_UNITSIZE) {
TRACE_ERROR("GMACD_SendSG: buffer size is too big.\r\n");
return GMACD_PARAM;
}
if (wTxPos == 0)
wTxPos = pGmacd->wTxListSize-1;
else
wTxPos--;
/* Reset TX callback */
pGmacd->fTxCbList[wTxPos] = NULL;
pTxTd = &pGmacd->pTxD[wTxPos];
#ifdef GMAC_ZERO_COPY
/** Update buffer descriptor address word:
* MUST be done before status word to avoid a race condition.
*/
pTxTd->addr = (uint32_t)sg->pBuffer;
wmb();
#else
/* Copy data into transmittion buffer */
if (sg->pBuffer && sg->size)
memcpy((void *)pTxTd->addr, sg->pBuffer, sg->size);
#endif
/* Compute buffer descriptor status word */
status = sg->size & GMAC_LENGTH_FRAME;
if (i == (int)(sgl->len-1)) {
status |= GMAC_TX_LAST_BUFFER_BIT;
pGmacd->fTxCbList[wTxPos] = fTxCb;
}
if (wTxPos == pGmacd->wTxListSize-1)
status |= GMAC_TX_WRAP_BIT;
/* Update buffer descriptor status word: clear USED bit */
pTxTd->status.val = status;
/* Make newly initialized descriptor visible to hardware */
wmb();
}
/* Update TX ring buffer pointers */
pGmacd->wTxHead = wTxHead;
/* Now start to transmit if it is not already done */
GMAC_TransmissionStart(pHw);
return GMACD_OK;
}
/**
* \brief Send a packet with GMAC. If the packet size is larger than transfer buffer size
* error returned. If packet transfer status is monitored, specify callback for each packet.
@ -466,58 +626,20 @@ void GMACD_Reset(sGmacd *pGmacd)
* \return OK, Busy or invalid packet
*/
uint8_t GMACD_Send(sGmacd *pGmacd,
void *pBuffer,
uint32_t size,
fGmacdTransferCallback fTxCb )
void *pBuffer,
uint32_t size,
fGmacdTransferCallback fTxCb)
{
Gmac *pHw = pGmacd->pHw;
sGmacTxDescriptor *pTxTd;
volatile fGmacdTransferCallback *pfTxCb;
TRACE_DEBUG("GMAC_Send\n\r");
/* Check parameter */
if (size > GMAC_TX_UNITSIZE) {
sGmacSGList sgl;
sGmacSG sg;
TRACE_ERROR("GMAC driver does not split send packets.");
return GMACD_PARAM;
}
/* Init single entry scatter-gather list */
sg.size = size;
sg.pBuffer = pBuffer;
sgl.len = 1;
sgl.sg = &sg;
/* Pointers to the current TxTd */
pTxTd = &pGmacd->pTxD[pGmacd->wTxHead];
/* If no free TxTd, buffer can't be sent */
if( GCIRC_SPACE(pGmacd->wTxHead, pGmacd->wTxTail, pGmacd->wTxListSize) == 0)
return GMACD_TX_BUSY;
/* Pointers to the current Tx Callback */
pfTxCb = &pGmacd->fTxCbList[pGmacd->wTxHead];
/* Sanity check */
/* Setup/Copy data to transmition buffer */
if (pBuffer && size) {
// Driver manage the ring buffer
memcpy((void *)pTxTd->addr, pBuffer, size);
}
/* Tx Callback */
*pfTxCb = fTxCb;
/* Update TD status. The buffer size defined is length of ethernet frame
so it's always the last buffer of the frame. */
if (pGmacd->wTxHead == pGmacd->wTxListSize-1) {
pTxTd->status.val =
(size & GMAC_LENGTH_FRAME) | GMAC_TX_LAST_BUFFER_BIT | GMAC_TX_WRAP_BIT;
}
else {
pTxTd->status.val = (size & GMAC_LENGTH_FRAME) | GMAC_TX_LAST_BUFFER_BIT;
}
GCIRC_INC(pGmacd->wTxHead, pGmacd->wTxListSize);
//CP15_flush_dcache_for_dma ((uint32_t)(pTxTd), ((uint32_t)(pTxTd) + sizeof(pTxTd)));
/* Tx packets count */
/* Now start to transmit if it is not already done */
GMAC_TransmissionStart(pHw);
return GMACD_OK;
return GMACD_SendSG(pGmacd, &sgl, fTxCb);
}

View File

@ -77,7 +77,7 @@
*/
/** Softpack Version */
#define SOFTPACK_VERSION "1.0"
#define SOFTPACK_VERSION "1.1"
#define TRACE_LEVEL_DEBUG 5
#define TRACE_LEVEL_INFO 4

View File

@ -1,5 +1,5 @@
/* ----------------------------------------------------------------------------
* SAM Software Package License
* SAM Software Package License
* ----------------------------------------------------------------------------
* Copyright (c) 2013, Atmel Corporation
*
@ -151,6 +151,8 @@ extern void PIO_InitializeInterrupts( uint32_t dwPriority )
{
TRACE_DEBUG( "PIO_Initialize()\n\r" ) ;
( void ) dwPriority;
/* Reset sources */
_dwNumSources = 0 ;
@ -234,7 +236,7 @@ extern void PIO_ConfigureIt( const Pin *pPin )
}
/* if bit field of selected pin is 1, set as edge detection source */
if (pPin->attribute & PIO_IT_EDGE)
if (pPin->attribute & PIO_IT_EDGE)
pio->PIO_ESR = pPin->mask;
else
pio->PIO_LSR = pPin->mask;

View File

@ -0,0 +1,558 @@
/* ----------------------------------------------------------------------------
* SAM Software Package License
* ----------------------------------------------------------------------------
* Copyright (c) 2011, Atmel Corporation
*
* 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 disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
* ----------------------------------------------------------------------------
*/
/** \file
* \addtogroup usbd_cdc
*@{
*/
/*------------------------------------------------------------------------------
* Headers
*------------------------------------------------------------------------------*/
#include "board.h"
#include "include/USBD_Config.h"
#include "CDCDSerialDriver.h"
/*------------------------------------------------------------------------------
* Definitions
*------------------------------------------------------------------------------*/
/** \addtogroup usbd_cdc_serial_device_ids CDC Serial Device IDs
* @{
* This page lists the IDs used in the CDC Serial Device Descriptor.
*
* \section IDs
* - CDCDSerialDriverDescriptors_PRODUCTID
* - CDCDSerialDriverDescriptors_VENDORID
* - CDCDSerialDriverDescriptors_RELEASE
*/
/** Device product ID. */
#define CDCDSerialDriverDescriptors_PRODUCTID 0x6119
/** Device vendor ID (Atmel). */
#define CDCDSerialDriverDescriptors_VENDORID 0x03EB
/** Device release number. */
#define CDCDSerialDriverDescriptors_RELEASE 0x0100
/** @}*/
/*------------------------------------------------------------------------------
* Macros
*------------------------------------------------------------------------------*/
/** Returns the minimum between two values. */
#define MIN(a, b) ((a < b) ? a : b)
/*------------------------------------------------------------------------------
* Exported variables
*------------------------------------------------------------------------------*/
/** Standard USB device descriptor for the CDC serial driver */
const USBDeviceDescriptor deviceDescriptor = {
sizeof(USBDeviceDescriptor),
USBGenericDescriptor_DEVICE,
USBDeviceDescriptor_USB2_00,
CDCDeviceDescriptor_CLASS,
CDCDeviceDescriptor_SUBCLASS,
CDCDeviceDescriptor_PROTOCOL,
CHIP_USB_ENDPOINTS_MAXPACKETSIZE(0),
CDCDSerialDriverDescriptors_VENDORID,
CDCDSerialDriverDescriptors_PRODUCTID,
CDCDSerialDriverDescriptors_RELEASE,
0, /* No string descriptor for manufacturer */
1, /* Index of product string descriptor is #1 */
0, /* No string descriptor for serial number */
1 /* Device has 1 possible configuration */
};
/** Standard USB configuration descriptor for the CDC serial driver */
const CDCDSerialDriverConfigurationDescriptors configurationDescriptorsFS = {
/* Standard configuration descriptor */
{
sizeof(USBConfigurationDescriptor),
USBGenericDescriptor_CONFIGURATION,
sizeof(CDCDSerialDriverConfigurationDescriptors),
2, /* There are two interfaces in this configuration */
1, /* This is configuration #1 */
0, /* No string descriptor for this configuration */
USBD_BMATTRIBUTES,
USBConfigurationDescriptor_POWER(100)
},
/* Communication class interface standard descriptor */
{
sizeof(USBInterfaceDescriptor),
USBGenericDescriptor_INTERFACE,
0, /* This is interface #0 */
0, /* This is alternate setting #0 for this interface */
1, /* This interface uses 1 endpoint */
CDCCommunicationInterfaceDescriptor_CLASS,
CDCCommunicationInterfaceDescriptor_ABSTRACTCONTROLMODEL,
CDCCommunicationInterfaceDescriptor_NOPROTOCOL,
0 /* No string descriptor for this interface */
},
/* Class-specific header functional descriptor */
{
sizeof(CDCHeaderDescriptor),
CDCGenericDescriptor_INTERFACE,
CDCGenericDescriptor_HEADER,
CDCGenericDescriptor_CDC1_10
},
/* Class-specific call management functional descriptor */
{
sizeof(CDCCallManagementDescriptor),
CDCGenericDescriptor_INTERFACE,
CDCGenericDescriptor_CALLMANAGEMENT,
CDCCallManagementDescriptor_SELFCALLMANAGEMENT,
0 /* No associated data interface */
},
/* Class-specific abstract control management functional descriptor */
{
sizeof(CDCAbstractControlManagementDescriptor),
CDCGenericDescriptor_INTERFACE,
CDCGenericDescriptor_ABSTRACTCONTROLMANAGEMENT,
CDCAbstractControlManagementDescriptor_LINE
},
/* Class-specific union functional descriptor with one slave interface */
{
sizeof(CDCUnionDescriptor),
CDCGenericDescriptor_INTERFACE,
CDCGenericDescriptor_UNION,
0, /* Number of master interface is #0 */
1 /* First slave interface is #1 */
},
/* Notification endpoint standard descriptor */
{
sizeof(USBEndpointDescriptor),
USBGenericDescriptor_ENDPOINT,
USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
CDCDSerialDriverDescriptors_NOTIFICATION),
USBEndpointDescriptor_INTERRUPT,
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(CDCDSerialDriverDescriptors_NOTIFICATION),
USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
10 /* Endpoint is polled every 10ms */
},
/* Data class interface standard descriptor */
{
sizeof(USBInterfaceDescriptor),
USBGenericDescriptor_INTERFACE,
1, /* This is interface #1 */
0, /* This is alternate setting #0 for this interface */
2, /* This interface uses 2 endpoints */
CDCDataInterfaceDescriptor_CLASS,
CDCDataInterfaceDescriptor_SUBCLASS,
CDCDataInterfaceDescriptor_NOPROTOCOL,
0 /* No string descriptor for this interface */
},
/* Bulk-OUT endpoint standard descriptor */
{
sizeof(USBEndpointDescriptor),
USBGenericDescriptor_ENDPOINT,
USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT,
CDCDSerialDriverDescriptors_DATAOUT),
USBEndpointDescriptor_BULK,
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(CDCDSerialDriverDescriptors_DATAOUT),
USBEndpointDescriptor_MAXBULKSIZE_FS),
0 /* Must be 0 for full-speed bulk endpoints */
},
/* Bulk-IN endpoint descriptor */
{
sizeof(USBEndpointDescriptor),
USBGenericDescriptor_ENDPOINT,
USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
CDCDSerialDriverDescriptors_DATAIN),
USBEndpointDescriptor_BULK,
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(CDCDSerialDriverDescriptors_DATAIN),
USBEndpointDescriptor_MAXBULKSIZE_FS),
0 /* Must be 0 for full-speed bulk endpoints */
}
};
/** Other-speed configuration descriptor (when in full-speed). */
const CDCDSerialDriverConfigurationDescriptors otherSpeedDescriptorsFS = {
/* Standard configuration descriptor */
{
sizeof(USBConfigurationDescriptor),
USBGenericDescriptor_OTHERSPEEDCONFIGURATION,
sizeof(CDCDSerialDriverConfigurationDescriptors),
2, /* There are two interfaces in this configuration */
1, /* This is configuration #1 */
0, /* No string descriptor for this configuration */
BOARD_USB_BMATTRIBUTES,
USBConfigurationDescriptor_POWER(100)
},
/* Communication class interface standard descriptor */
{
sizeof(USBInterfaceDescriptor),
USBGenericDescriptor_INTERFACE,
0, /* This is interface #0 */
0, /* This is alternate setting #0 for this interface */
1, /* This interface uses 1 endpoint */
CDCCommunicationInterfaceDescriptor_CLASS,
CDCCommunicationInterfaceDescriptor_ABSTRACTCONTROLMODEL,
CDCCommunicationInterfaceDescriptor_NOPROTOCOL,
0 /* No string descriptor for this interface */
},
/* Class-specific header functional descriptor */
{
sizeof(CDCHeaderDescriptor),
CDCGenericDescriptor_INTERFACE,
CDCGenericDescriptor_HEADER,
CDCGenericDescriptor_CDC1_10
},
/* Class-specific call management functional descriptor */
{
sizeof(CDCCallManagementDescriptor),
CDCGenericDescriptor_INTERFACE,
CDCGenericDescriptor_CALLMANAGEMENT,
CDCCallManagementDescriptor_SELFCALLMANAGEMENT,
0 /* No associated data interface */
},
/* Class-specific abstract control management functional descriptor */
{
sizeof(CDCAbstractControlManagementDescriptor),
CDCGenericDescriptor_INTERFACE,
CDCGenericDescriptor_ABSTRACTCONTROLMANAGEMENT,
CDCAbstractControlManagementDescriptor_LINE
},
/* Class-specific union functional descriptor with one slave interface */
{
sizeof(CDCUnionDescriptor),
CDCGenericDescriptor_INTERFACE,
CDCGenericDescriptor_UNION,
0, /* Number of master interface is #0 */
1 /* First slave interface is #1 */
},
/* Notification endpoint standard descriptor */
{
sizeof(USBEndpointDescriptor),
USBGenericDescriptor_ENDPOINT,
USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
CDCDSerialDriverDescriptors_NOTIFICATION),
USBEndpointDescriptor_INTERRUPT,
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(CDCDSerialDriverDescriptors_NOTIFICATION),
USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
8 /* Endpoint is polled every 16ms */
},
/* Data class interface standard descriptor */
{
sizeof(USBInterfaceDescriptor),
USBGenericDescriptor_INTERFACE,
1, /* This is interface #1 */
0, /* This is alternate setting #0 for this interface */
2, /* This interface uses 2 endpoints */
CDCDataInterfaceDescriptor_CLASS,
CDCDataInterfaceDescriptor_SUBCLASS,
CDCDataInterfaceDescriptor_NOPROTOCOL,
0 /* No string descriptor for this interface */
},
/* Bulk-OUT endpoint standard descriptor */
{
sizeof(USBEndpointDescriptor),
USBGenericDescriptor_ENDPOINT,
USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT,
CDCDSerialDriverDescriptors_DATAOUT),
USBEndpointDescriptor_BULK,
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(CDCDSerialDriverDescriptors_DATAOUT),
USBEndpointDescriptor_MAXBULKSIZE_HS),
0 /* Must be 0 for full-speed bulk endpoints */
},
/* Bulk-IN endpoint descriptor */
{
sizeof(USBEndpointDescriptor),
USBGenericDescriptor_ENDPOINT,
USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
CDCDSerialDriverDescriptors_DATAIN),
USBEndpointDescriptor_BULK,
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(CDCDSerialDriverDescriptors_DATAIN),
USBEndpointDescriptor_MAXBULKSIZE_HS),
0 /* Must be 0 for full-speed bulk endpoints */
}
};
/** Configuration descriptor (when in high-speed). */
const CDCDSerialDriverConfigurationDescriptors configurationDescriptorsHS = {
/* Standard configuration descriptor */
{
sizeof(USBConfigurationDescriptor),
USBGenericDescriptor_CONFIGURATION,
sizeof(CDCDSerialDriverConfigurationDescriptors),
2, /* There are two interfaces in this configuration */
1, /* This is configuration #1 */
0, /* No string descriptor for this configuration */
BOARD_USB_BMATTRIBUTES,
USBConfigurationDescriptor_POWER(100)
},
/* Communication class interface standard descriptor */
{
sizeof(USBInterfaceDescriptor),
USBGenericDescriptor_INTERFACE,
0, /* This is interface #0 */
0, /* This is alternate setting #0 for this interface */
1, /* This interface uses 1 endpoint */
CDCCommunicationInterfaceDescriptor_CLASS,
CDCCommunicationInterfaceDescriptor_ABSTRACTCONTROLMODEL,
CDCCommunicationInterfaceDescriptor_NOPROTOCOL,
0 /* No string descriptor for this interface */
},
/* Class-specific header functional descriptor */
{
sizeof(CDCHeaderDescriptor),
CDCGenericDescriptor_INTERFACE,
CDCGenericDescriptor_HEADER,
CDCGenericDescriptor_CDC1_10
},
/* Class-specific call management functional descriptor */
{
sizeof(CDCCallManagementDescriptor),
CDCGenericDescriptor_INTERFACE,
CDCGenericDescriptor_CALLMANAGEMENT,
CDCCallManagementDescriptor_SELFCALLMANAGEMENT,
0 /* No associated data interface */
},
/* Class-specific abstract control management functional descriptor */
{
sizeof(CDCAbstractControlManagementDescriptor),
CDCGenericDescriptor_INTERFACE,
CDCGenericDescriptor_ABSTRACTCONTROLMANAGEMENT,
CDCAbstractControlManagementDescriptor_LINE
},
/* Class-specific union functional descriptor with one slave interface */
{
sizeof(CDCUnionDescriptor),
CDCGenericDescriptor_INTERFACE,
CDCGenericDescriptor_UNION,
0, /* Number of master interface is #0 */
1 /* First slave interface is #1 */
},
/* Notification endpoint standard descriptor */
{
sizeof(USBEndpointDescriptor),
USBGenericDescriptor_ENDPOINT,
USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
CDCDSerialDriverDescriptors_NOTIFICATION),
USBEndpointDescriptor_INTERRUPT,
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(CDCDSerialDriverDescriptors_NOTIFICATION),
USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
8 /* Endpoint is polled every 16ms */
},
/* Data class interface standard descriptor */
{
sizeof(USBInterfaceDescriptor),
USBGenericDescriptor_INTERFACE,
1, /* This is interface #1 */
0, /* This is alternate setting #0 for this interface */
2, /* This interface uses 2 endpoints */
CDCDataInterfaceDescriptor_CLASS,
CDCDataInterfaceDescriptor_SUBCLASS,
CDCDataInterfaceDescriptor_NOPROTOCOL,
0 /* No string descriptor for this interface */
},
/* Bulk-OUT endpoint standard descriptor */
{
sizeof(USBEndpointDescriptor),
USBGenericDescriptor_ENDPOINT,
USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT,
CDCDSerialDriverDescriptors_DATAOUT),
USBEndpointDescriptor_BULK,
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(CDCDSerialDriverDescriptors_DATAOUT),
USBEndpointDescriptor_MAXBULKSIZE_HS),
0 /* Must be 0 for full-speed bulk endpoints */
},
/* Bulk-IN endpoint descriptor */
{
sizeof(USBEndpointDescriptor),
USBGenericDescriptor_ENDPOINT,
USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
CDCDSerialDriverDescriptors_DATAIN),
USBEndpointDescriptor_BULK,
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(CDCDSerialDriverDescriptors_DATAIN),
USBEndpointDescriptor_MAXBULKSIZE_HS),
0 /* Must be 0 for full-speed bulk endpoints */
}
};
/** Other-speed configuration descriptor (when in high-speed). */
const CDCDSerialDriverConfigurationDescriptors otherSpeedDescriptorsHS = {
/* Standard configuration descriptor */
{
sizeof(USBConfigurationDescriptor),
USBGenericDescriptor_OTHERSPEEDCONFIGURATION,
sizeof(CDCDSerialDriverConfigurationDescriptors),
2, /* There are two interfaces in this configuration */
1, /* This is configuration #1 */
0, /* No string descriptor for this configuration */
BOARD_USB_BMATTRIBUTES,
USBConfigurationDescriptor_POWER(100)
},
/* Communication class interface standard descriptor */
{
sizeof(USBInterfaceDescriptor),
USBGenericDescriptor_INTERFACE,
0, /* This is interface #0 */
0, /* This is alternate setting #0 for this interface */
1, /* This interface uses 1 endpoint */
CDCCommunicationInterfaceDescriptor_CLASS,
CDCCommunicationInterfaceDescriptor_ABSTRACTCONTROLMODEL,
CDCCommunicationInterfaceDescriptor_NOPROTOCOL,
0 /* No string descriptor for this interface */
},
/* Class-specific header functional descriptor */
{
sizeof(CDCHeaderDescriptor),
CDCGenericDescriptor_INTERFACE,
CDCGenericDescriptor_HEADER,
CDCGenericDescriptor_CDC1_10
},
/* Class-specific call management functional descriptor */
{
sizeof(CDCCallManagementDescriptor),
CDCGenericDescriptor_INTERFACE,
CDCGenericDescriptor_CALLMANAGEMENT,
CDCCallManagementDescriptor_SELFCALLMANAGEMENT,
0 /* No associated data interface */
},
/* Class-specific abstract control management functional descriptor */
{
sizeof(CDCAbstractControlManagementDescriptor),
CDCGenericDescriptor_INTERFACE,
CDCGenericDescriptor_ABSTRACTCONTROLMANAGEMENT,
CDCAbstractControlManagementDescriptor_LINE
},
/* Class-specific union functional descriptor with one slave interface */
{
sizeof(CDCUnionDescriptor),
CDCGenericDescriptor_INTERFACE,
CDCGenericDescriptor_UNION,
0, /* Number of master interface is #0 */
1 /* First slave interface is #1 */
},
/* Notification endpoint standard descriptor */
{
sizeof(USBEndpointDescriptor),
USBGenericDescriptor_ENDPOINT,
USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
CDCDSerialDriverDescriptors_NOTIFICATION),
USBEndpointDescriptor_INTERRUPT,
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(CDCDSerialDriverDescriptors_NOTIFICATION),
USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
10 /* Endpoint is polled every 10ms */
},
/* Data class interface standard descriptor */
{
sizeof(USBInterfaceDescriptor),
USBGenericDescriptor_INTERFACE,
1, /* This is interface #1 */
0, /* This is alternate setting #0 for this interface */
2, /* This interface uses 2 endpoints */
CDCDataInterfaceDescriptor_CLASS,
CDCDataInterfaceDescriptor_SUBCLASS,
CDCDataInterfaceDescriptor_NOPROTOCOL,
0 /* No string descriptor for this interface */
},
/* Bulk-OUT endpoint standard descriptor */
{
sizeof(USBEndpointDescriptor),
USBGenericDescriptor_ENDPOINT,
USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT,
CDCDSerialDriverDescriptors_DATAOUT),
USBEndpointDescriptor_BULK,
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(CDCDSerialDriverDescriptors_DATAOUT),
USBEndpointDescriptor_MAXBULKSIZE_FS),
0 /* Must be 0 for full-speed bulk endpoints */
},
/* Bulk-IN endpoint descriptor */
{
sizeof(USBEndpointDescriptor),
USBGenericDescriptor_ENDPOINT,
USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
CDCDSerialDriverDescriptors_DATAIN),
USBEndpointDescriptor_BULK,
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(CDCDSerialDriverDescriptors_DATAIN),
USBEndpointDescriptor_MAXBULKSIZE_FS),
0 /* Must be 0 for full-speed bulk endpoints */
}
};
/** Language ID string descriptor */
const unsigned char languageIdStringDescriptor[] = {
USBStringDescriptor_LENGTH(1),
USBGenericDescriptor_STRING,
USBStringDescriptor_ENGLISH_US
};
/** Product string descriptor */
const unsigned char productStringDescriptor[] = {
USBStringDescriptor_LENGTH(13),
USBGenericDescriptor_STRING,
USBStringDescriptor_UNICODE('A'),
USBStringDescriptor_UNICODE('T'),
USBStringDescriptor_UNICODE('9'),
USBStringDescriptor_UNICODE('1'),
USBStringDescriptor_UNICODE('U'),
USBStringDescriptor_UNICODE('S'),
USBStringDescriptor_UNICODE('B'),
USBStringDescriptor_UNICODE('S'),
USBStringDescriptor_UNICODE('e'),
USBStringDescriptor_UNICODE('r'),
USBStringDescriptor_UNICODE('i'),
USBStringDescriptor_UNICODE('a'),
USBStringDescriptor_UNICODE('l')
};
/** List of string descriptors used by the device */
const unsigned char *stringDescriptors[] = {
languageIdStringDescriptor,
productStringDescriptor,
};
/** List of standard descriptors for the serial driver. */
WEAK const USBDDriverDescriptors cdcdSerialDriverDescriptors = {
&deviceDescriptor,
(USBConfigurationDescriptor *) &(configurationDescriptorsFS),
0, /* No full-speed device qualifier descriptor */
(USBConfigurationDescriptor *) &(otherSpeedDescriptorsFS),
0, /* No high-speed device descriptor (uses FS one) */
(USBConfigurationDescriptor *) &(configurationDescriptorsHS),
0, /* No high-speed device qualifier descriptor */
(USBConfigurationDescriptor *) &(otherSpeedDescriptorsHS),
stringDescriptors,
2 /* 2 string descriptors in list */
};
/**@}*/

View File

@ -0,0 +1,71 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
*
* 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 disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
* ----------------------------------------------------------------------------
*/
/** \file
Implementation of the CDCLineCoding class.
*/
/** \addtogroup usb_cdc
*@{
*/
/*----------------------------------------------------------------------------
* Headers
*----------------------------------------------------------------------------*/
#include <CDCRequests.h>
/*----------------------------------------------------------------------------
* Exported functions
*----------------------------------------------------------------------------*/
/**
* Initializes the bitrate, number of stop bits, parity checking and
* number of data bits of a CDCLineCoding object.
* \param lineCoding Pointer to a CDCLineCoding instance.
* \param bitrate Bitrate of the virtual COM connection.
* \param stopbits Number of stop bits
* (\ref usb_cdc_stop CDC LineCoding StopBits).
* \param parity Parity check type
* (\ref usb_cdc_parity CDC LineCoding ParityChecking).
* \param databits Number of data bits.
*/
void CDCLineCoding_Initialize(CDCLineCoding *lineCoding,
uint32_t bitrate,
uint8_t stopbits,
uint8_t parity,
uint8_t databits)
{
lineCoding->dwDTERate = bitrate;
lineCoding->bCharFormat = stopbits;
lineCoding->bParityType = parity;
lineCoding->bDataBits = databits;
}
/**@}*/

View File

@ -0,0 +1,87 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
*
* 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 disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
* ----------------------------------------------------------------------------
*/
/** \file
*
* Implementation of the CDCSetControlLineStateRequest class.
*/
/** \addtogroup usb_cdc
*@{
*/
/*----------------------------------------------------------------------------
* Headers
*----------------------------------------------------------------------------*/
#include <CDCRequests.h>
/*----------------------------------------------------------------------------
* Exported functions
*----------------------------------------------------------------------------*/
/**
* Notifies if the given request indicates that the DTE signal is present.
* \param request Pointer to a USBGenericRequest instance.
* \return 1 if the DTE signal is present, otherwise 0.
*/
uint8_t CDCSetControlLineStateRequest_IsDtePresent(
const USBGenericRequest *request)
{
if ((USBGenericRequest_GetValue(request) & 0x0001) != 0) {
return 1;
}
else {
return 0;
}
}
/**
* Notifies if the given request indicates that the device carrier should
* be activated.
* \param request Pointer to a USBGenericRequest instance.
* \return 1 is the device should activate its carrier, 0 otherwise.
*/
uint8_t CDCSetControlLineStateRequest_ActivateCarrier(
const USBGenericRequest *request)
{
if ((USBGenericRequest_GetValue(request) & 0x0002) != 0) {
return 1;
}
else {
return 0;
}
}
/**@}*/

View File

@ -0,0 +1,319 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2010, Atmel Corporation
*
* 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 disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
* ----------------------------------------------------------------------------
*/
/** \file
*
* Implements for USB descriptor methods described by the USB specification.
*/
/** \addtogroup usb_descriptor
*@{
*/
/*------------------------------------------------------------------------------
* Headers
*------------------------------------------------------------------------------*/
#include "USBDescriptors.h"
/*------------------------------------------------------------------------------
* Exported functions
*------------------------------------------------------------------------------*/
/**
* Returns the length of a descriptor.
* \param descriptor Pointer to a USBGenericDescriptor instance.
* \return Length of descriptor in bytes.
*/
uint32_t USBGenericDescriptor_GetLength(
const USBGenericDescriptor *descriptor)
{
return descriptor->bLength;
}
/**
* Returns the type of a descriptor.
* \param descriptor Pointer to a USBGenericDescriptor instance.
* \return Type of descriptor.
*/
uint8_t USBGenericDescriptor_GetType(
const USBGenericDescriptor *descriptor)
{
return descriptor->bDescriptorType;
}
/**
* Returns a pointer to the descriptor right after the given one, when
* parsing a Configuration descriptor.
* \param descriptor - Pointer to a USBGenericDescriptor instance.
* \return Pointer to the next descriptor.
*/
USBGenericDescriptor *USBGenericDescriptor_GetNextDescriptor(
const USBGenericDescriptor *descriptor)
{
return (USBGenericDescriptor *)
(((char *) descriptor) + USBGenericDescriptor_GetLength(descriptor));
}
/** Parses the given descriptor list via costomized function.
* \param descriptor Pointer to the start of the whole descriptors list.
* \param totalLength Total size of descriptors in bytes.
* \param parseFunction Function to parse each descriptor scanned.
* Return 0 to continue parsing.
* \param parseArg Argument passed to parse function.
* \return Pointer to USBGenericDescriptor instance for next descriptor.
*/
USBGenericDescriptor *USBGenericDescriptor_Parse(
const USBGenericDescriptor *descriptor,
uint32_t totalLength,
USBDescriptorParseFunction parseFunction,
void *parseArg)
{
int32_t size = totalLength;
if (size == 0)
return 0;
/* Start parsing descriptors */
while (1) {
uint32_t parseRC = 0;
/* Parse current descriptor */
if (parseFunction) {
parseRC = parseFunction((void*)descriptor, parseArg);
}
/* Get next descriptor */
size -= USBGenericDescriptor_GetLength(descriptor);
descriptor = USBGenericDescriptor_GetNextDescriptor(descriptor);
if (size) {
if (parseRC != 0) {
return (USBGenericDescriptor *)descriptor;
}
}
else
break;
}
/* No descriptors remaining */
return 0;
}
/**
* Returns the number of an endpoint given its descriptor.
* \param endpoint Pointer to a USBEndpointDescriptor instance.
* \return Endpoint number.
*/
uint8_t USBEndpointDescriptor_GetNumber(
const USBEndpointDescriptor *endpoint)
{
return endpoint->bEndpointAddress & 0xF;
}
/**
* Returns the direction of an endpoint given its descriptor.
* \param endpoint Pointer to a USBEndpointDescriptor instance.
* \return Endpoint direction (see \ref usb_ep_dir).
*/
uint8_t USBEndpointDescriptor_GetDirection(
const USBEndpointDescriptor *endpoint)
{
if ((endpoint->bEndpointAddress & 0x80) != 0) {
return USBEndpointDescriptor_IN;
}
else {
return USBEndpointDescriptor_OUT;
}
}
/**
* Returns the type of an endpoint given its descriptor.
* \param endpoint Pointer to a USBEndpointDescriptor instance.
* \return Endpoint type (see \ref usb_ep_type).
*/
uint8_t USBEndpointDescriptor_GetType(
const USBEndpointDescriptor *endpoint)
{
return endpoint->bmAttributes & 0x3;
}
/**
* Returns the maximum size of a packet (in bytes) on an endpoint given
* its descriptor.
* \param endpoint - Pointer to a USBEndpointDescriptor instance.
* \return Maximum packet size of endpoint.
*/
uint16_t USBEndpointDescriptor_GetMaxPacketSize(
const USBEndpointDescriptor *endpoint)
{
uint16_t usTemp;
uint8_t *pc1, *pc2;
/* Note this is an unaligned access hence it is performed as two byte
accesses. */
pc1 = ( uint8_t * ) &( endpoint->wMaxPacketSize );
pc2 = pc1 + 1;
usTemp = ( ( *pc2 ) << 8 ) | *pc1;
return usTemp;
}
/**
* Returns the polling interval on an endpoint given its descriptor.
* \param endpoint - Pointer to a USBEndpointDescriptor instance.
* \return Polling interval of endpoint.
*/
uint8_t USBEndpointDescriptor_GetInterval(
const USBEndpointDescriptor *endpoint)
{
return endpoint->bInterval;
}
/** Returns the total length of a configuration, i.e. including the
* descriptors following it.
* \param configuration Pointer to a USBConfigurationDescriptor instance.
* \return Total length (in bytes) of the configuration.
*/
uint32_t USBConfigurationDescriptor_GetTotalLength(
const USBConfigurationDescriptor *configuration)
{
return configuration->wTotalLength;
}
/** Returns the number of interfaces in a configuration.
* \param configuration Pointer to a USBConfigurationDescriptor instance.
* \return Number of interfaces in configuration.
*/
unsigned char USBConfigurationDescriptor_GetNumInterfaces(
const USBConfigurationDescriptor *configuration)
{
return configuration->bNumInterfaces;
}
/** Indicates if the device is self-powered when in a given configuration.
* \param configuration Pointer to a USBConfigurationDescriptor instance.
* \return 1 if the device is self-powered when in the given configuration;
* otherwise 0.
*/
unsigned char USBConfigurationDescriptor_IsSelfPowered(
const USBConfigurationDescriptor *configuration)
{
if ((configuration->bmAttributes & (1 << 6)) != 0) {
return 1;
}
else {
return 0;
}
}
/** Parses the given Configuration descriptor (followed by relevant
* interface, endpoint and class-specific descriptors) into three arrays.
* *Each array must have its size equal or greater to the number of
* descriptors it stores plus one*. A null-value is inserted after the last
* descriptor of each type to indicate the array end.
*
* Note that if the pointer to an array is null (0), nothing is stored in
* it.
* \param configuration Pointer to the start of the whole Configuration
* descriptor.
* \param interfaces Pointer to the Interface descriptor array.
* \param endpoints Pointer to the Endpoint descriptor array.
* \param others Pointer to the class-specific descriptor array.
*/
void USBConfigurationDescriptor_Parse(
const USBConfigurationDescriptor *configuration,
USBInterfaceDescriptor **interfaces,
USBEndpointDescriptor **endpoints,
USBGenericDescriptor **others)
{
/* Get size of configuration to parse */
int size = USBConfigurationDescriptor_GetTotalLength(configuration);
size -= sizeof(USBConfigurationDescriptor);
/* Start parsing descriptors */
USBGenericDescriptor *descriptor = (USBGenericDescriptor *) configuration;
while (size > 0) {
/* Get next descriptor */
descriptor = USBGenericDescriptor_GetNextDescriptor(descriptor);
size -= USBGenericDescriptor_GetLength(descriptor);
/* Store descriptor in correponding array */
if (USBGenericDescriptor_GetType(descriptor)
== USBGenericDescriptor_INTERFACE) {
if (interfaces) {
*interfaces = (USBInterfaceDescriptor *) descriptor;
interfaces++;
}
}
else if (USBGenericDescriptor_GetType(descriptor)
== USBGenericDescriptor_ENDPOINT) {
if (endpoints) {
*endpoints = (USBEndpointDescriptor *) descriptor;
endpoints++;
}
}
else if (others) {
*others = descriptor;
others++;
}
}
/* Null-terminate arrays */
if (interfaces) {
*interfaces = 0;
}
if (endpoints) {
*endpoints = 0;
}
if (others) {
*others = 0;
}
}
/**@}*/

View File

@ -0,0 +1,244 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2010, Atmel Corporation
*
* 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 disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
* ----------------------------------------------------------------------------
*/
/** \file
* \section Purpose
*
* Implements for USB requests described by the USB specification.
*/
/** \addtogroup usb_request
* @{
*/
/*------------------------------------------------------------------------------
* Headers
*------------------------------------------------------------------------------*/
#include <USBRequests.h>
/*------------------------------------------------------------------------------
* Exported functions
*------------------------------------------------------------------------------*/
/**
* Returns the type of the given request.
* \param request Pointer to a USBGenericRequest instance.
* \return "USB Request Types"
*/
extern uint8_t USBGenericRequest_GetType(const USBGenericRequest *request)
{
return ((request->bmRequestType >> 5) & 0x3);
}
/**
* Returns the request code of the given request.
* \param request Pointer to a USBGenericRequest instance.
* \return Request code.
* \sa "USB Request Codes"
*/
uint8_t USBGenericRequest_GetRequest(const USBGenericRequest *request)
{
return request->bRequest;
}
/**
* Returns the wValue field of the given request.
* \param request - Pointer to a USBGenericRequest instance.
* \return Request value.
*/
uint16_t USBGenericRequest_GetValue(const USBGenericRequest *request)
{
return request->wValue;
}
/**
* Returns the wIndex field of the given request.
* \param request Pointer to a USBGenericRequest instance.
* \return Request index;
*/
uint16_t USBGenericRequest_GetIndex(const USBGenericRequest *request)
{
return request->wIndex;
}
/**
* Returns the expected length of the data phase following a request.
* \param request Pointer to a USBGenericRequest instance.
* \return Length of data phase.
*/
uint16_t USBGenericRequest_GetLength(const USBGenericRequest *request)
{
return request->wLength;
}
/**
* Returns the endpoint number targetted by a given request.
* \param request Pointer to a USBGenericRequest instance.
* \return Endpoint number.
*/
uint8_t USBGenericRequest_GetEndpointNumber(
const USBGenericRequest *request)
{
return USBGenericRequest_GetIndex(request) & 0xF;
}
/**
* Returns the intended recipient of a given request.
* \param request Pointer to a USBGenericRequest instance.
* \return Request recipient.
* \sa "USB Request Recipients"
*/
uint8_t USBGenericRequest_GetRecipient(const USBGenericRequest *request)
{
/* Recipient is in bits [0..4] of the bmRequestType field */
return request->bmRequestType & 0xF;
}
/**
* Returns the direction of the data transfer following the given request.
* \param request Pointer to a USBGenericRequest instance.
* \return Transfer direction.
* \sa "USB Request Directions"
*/
uint8_t USBGenericRequest_GetDirection(const USBGenericRequest *request)
{
/* Transfer direction is located in bit D7 of the bmRequestType field */
if ((request->bmRequestType & 0x80) != 0) {
return USBGenericRequest_IN;
}
else {
return USBGenericRequest_OUT;
}
}
/**
* Returns the type of the descriptor requested by the host given the
* corresponding GET_DESCRIPTOR request.
* \param request Pointer to a USBGenericDescriptor instance.
* \return Type of the requested descriptor.
*/
uint8_t USBGetDescriptorRequest_GetDescriptorType(
const USBGenericRequest *request)
{
/* Requested descriptor type is in the high-byte of the wValue field */
return (USBGenericRequest_GetValue(request) >> 8) & 0xFF;
}
/**
* Returns the index of the requested descriptor, given the corresponding
* GET_DESCRIPTOR request.
* \param request Pointer to a USBGenericDescriptor instance.
* \return Index of the requested descriptor.
*/
uint8_t USBGetDescriptorRequest_GetDescriptorIndex(
const USBGenericRequest *request)
{
/* Requested descriptor index if in the low byte of the wValue field */
return USBGenericRequest_GetValue(request) & 0xFF;
}
/**
* Returns the address that the device must take in response to a
* SET_ADDRESS request.
* \param request Pointer to a USBGenericRequest instance.
* \return New device address.
*/
uint8_t USBSetAddressRequest_GetAddress(const USBGenericRequest *request)
{
return USBGenericRequest_GetValue(request) & 0x7F;
}
/**
* Returns the number of the configuration that should be set in response
* to the given SET_CONFIGURATION request.
* \param request Pointer to a USBGenericRequest instance.
* \return Number of the requested configuration.
*/
uint8_t USBSetConfigurationRequest_GetConfiguration(
const USBGenericRequest *request)
{
return USBGenericRequest_GetValue(request);
}
/**
* Indicates which interface is targetted by a GET_INTERFACE or
* SET_INTERFACE request.
* \param request Pointer to a USBGenericRequest instance.
* \return Interface number.
*/
uint8_t USBInterfaceRequest_GetInterface(const USBGenericRequest *request)
{
return (USBGenericRequest_GetIndex(request) & 0xFF);
}
/**
* Indicates the new alternate setting that the interface targetted by a
* SET_INTERFACE request should use.
* \param request Pointer to a USBGenericRequest instance.
* \return New active setting for the interface.
*/
uint8_t USBInterfaceRequest_GetAlternateSetting(
const USBGenericRequest *request)
{
return (USBGenericRequest_GetValue(request) & 0xFF);
}
/**
* Returns the feature selector of a given CLEAR_FEATURE or SET_FEATURE
* request.
* \param request Pointer to a USBGenericRequest instance.
* \return Feature selector.
*/
uint8_t USBFeatureRequest_GetFeatureSelector(
const USBGenericRequest *request)
{
return USBGenericRequest_GetValue(request);
}
/**
* Indicates the test that the device must undertake following a
* SET_FEATURE request.
* \param request Pointer to a USBGenericRequest instance.
* \return Test selector.
*/
uint8_t USBFeatureRequest_GetTestSelector(
const USBGenericRequest *request)
{
return (USBGenericRequest_GetIndex(request) >> 8) & 0xFF;
}
/**@}*/

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

View File

@ -0,0 +1,228 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
*
* 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 disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
* ----------------------------------------------------------------------------
*/
/**\file
* Implementation of a single CDC serial port function for USB device.
*/
/** \addtogroup usbd_cdc
*@{
*/
/*------------------------------------------------------------------------------
* Headers
*------------------------------------------------------------------------------*/
#include "CDCDSerial.h"
#include <USBLib_Trace.h>
#include <USBDDriver.h>
#include <USBD_HAL.h>
/*------------------------------------------------------------------------------
* Types
*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------
* Internal variables
*------------------------------------------------------------------------------*/
/** Serial Port instance list */
static CDCDSerialPort cdcdSerial;
/*------------------------------------------------------------------------------
* Internal functions
*------------------------------------------------------------------------------*/
/**
* USB CDC Serial Port Event Handler.
* \param event Event code.
* \param param Event parameter.
*/
static uint32_t CDCDSerial_EventHandler(uint32_t event,
uint32_t param)
{
switch (event) {
case CDCDSerialPortEvent_SETCONTROLLINESTATE:
{
if (CDCDSerial_ControlLineStateChanged != NULL) {
CDCDSerial_ControlLineStateChanged(
(param & CDCControlLineState_DTR) > 0,
(param & CDCControlLineState_RTS) > 0);
}
}
break;
case CDCDSerialPortEvent_SETLINECODING:
{
if (NULL != CDCDSerial_LineCodingIsToChange) {
event = CDCDSerial_LineCodingIsToChange(
(CDCLineCoding*)param);
if (event != USBRC_SUCCESS)
return event;
}
}
break;
default:
return USBRC_SUCCESS;
}
return USBRC_SUCCESS;
}
/*------------------------------------------------------------------------------
* Exported functions
*------------------------------------------------------------------------------*/
/**
* Initializes the USB Device CDC serial driver & USBD Driver.
* \param pUsbd Pointer to USBDDriver instance.
* \param bInterfaceNb Interface number for the function.
*/
void CDCDSerial_Initialize(
USBDDriver *pUsbd, uint8_t bInterfaceNb)
{
CDCDSerialPort *pCdcd = &cdcdSerial;
TRACE_INFO("CDCDSerial_Initialize\n\r");
/* Initialize serial port function */
CDCDSerialPort_Initialize(
pCdcd, pUsbd,
(CDCDSerialPortEventHandler)CDCDSerial_EventHandler,
0,
bInterfaceNb, 2);
}
/**
* Invoked whenever the device is changed by the
* host.
* \pDescriptors Pointer to the descriptors for function configure.
* \wLength Length of descriptors in number of bytes.
*/
void CDCDSerial_ConfigureFunction(USBGenericDescriptor *pDescriptors,
uint16_t wLength)
{
CDCDSerialPort *pCdcd = &cdcdSerial;
CDCDSerialPort_ParseInterfaces(pCdcd,
(USBGenericDescriptor*)pDescriptors,
wLength);
}
/**
* Handles CDC-specific SETUP requests. Should be called from a
* re-implementation of USBDCallbacks_RequestReceived() method.
* \param request Pointer to a USBGenericRequest instance.
*/
uint32_t CDCDSerial_RequestHandler(const USBGenericRequest *request)
{
CDCDSerialPort * pCdcd = &cdcdSerial;
TRACE_INFO_WP("Cdcf ");
return CDCDSerialPort_RequestHandler(pCdcd, request);
}
/**
* Receives data from the host through the virtual COM port created by
* the CDC device serial driver. This function behaves like USBD_Read.
* \param data Pointer to the data buffer to put received data.
* \param size Size of the data buffer in bytes.
* \param callback Optional callback function to invoke when the transfer
* finishes.
* \param argument Optional argument to the callback function.
* \return USBD_STATUS_SUCCESS if the read operation has been started normally;
* otherwise, the corresponding error code.
*/
uint32_t CDCDSerial_Read(void *data,
uint32_t size,
TransferCallback callback,
void *argument)
{
CDCDSerialPort * pCdcd = &cdcdSerial;
return CDCDSerialPort_Read(pCdcd, data, size, callback, argument);
}
/**
* Sends a data buffer through the virtual COM port created by the CDC
* device serial driver. This function behaves exactly like USBD_Write.
* \param data Pointer to the data buffer to send.
* \param size Size of the data buffer in bytes.
* \param callback Optional callback function to invoke when the transfer
* finishes.
* \param argument Optional argument to the callback function.
* \return USBD_STATUS_SUCCESS if the read operation has been started normally;
* otherwise, the corresponding error code.
*/
uint32_t CDCDSerial_Write(void *data,
uint32_t size,
TransferCallback callback,
void *argument)
{
CDCDSerialPort * pCdcd = &cdcdSerial;
return CDCDSerialPort_Write(pCdcd, data, size, callback, argument);
}
/**
* Returns the current control line state of the RS-232 line.
*/
uint8_t CDCDSerial_GetControlLineState(void)
{
CDCDSerialPort * pCdcd = &cdcdSerial;
return CDCDSerialPort_GetControlLineState(pCdcd);
}
/**
* Copy current line coding settings to pointered space.
* \param pLineCoding Pointer to CDCLineCoding instance.
*/
void CDCDSerial_GetLineCoding(CDCLineCoding* pLineCoding)
{
CDCDSerialPort * pCdcd = &cdcdSerial;
CDCDSerialPort_GetLineCoding(pCdcd, pLineCoding);
}
/**
* Returns the current status of the RS-232 line.
*/
uint16_t CDCDSerial_GetSerialState(void)
{
CDCDSerialPort * pCdcd = &cdcdSerial;
return CDCDSerialPort_GetSerialState(pCdcd);
}
/**
* Sets the current serial state of the device to the given value.
* \param serialState New device state.
*/
void CDCDSerial_SetSerialState(uint16_t serialState)
{
CDCDSerialPort * pCdcd = &cdcdSerial;
CDCDSerialPort_SetSerialState(pCdcd, serialState);
}
/**@}*/

View File

@ -0,0 +1,116 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
*
* 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 disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
* ----------------------------------------------------------------------------
*/
/**\file
* Title: CDCDSerialDriver implementation
*
* About: Purpose
* Implementation of the CDCDSerialDriver class methods.
*/
/** \addtogroup usbd_cdc
*@{
*/
/*------------------------------------------------------------------------------
* Headers
*------------------------------------------------------------------------------*/
#include "CDCDSerialDriver.h"
#include <USBLib_Trace.h>
#include <USBDDriver.h>
#include <USBD_HAL.h>
/*------------------------------------------------------------------------------
* Types
*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------
* Internal variables
*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------
* Internal functions
*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------
* Exported functions
*------------------------------------------------------------------------------*/
/**
* Initializes the USB Device CDC serial driver & USBD Driver.
* \param pDescriptors Pointer to Descriptors list for CDC Serial Device.
*/
void CDCDSerialDriver_Initialize(const USBDDriverDescriptors *pDescriptors)
{
USBDDriver *pUsbd = USBD_GetDriver();
/* Initialize the standard driver */
USBDDriver_Initialize(pUsbd,
pDescriptors,
0); /* Multiple settings for interfaces not supported */
CDCDSerial_Initialize(pUsbd, CDCDSerialDriver_CC_INTERFACE);
/* Initialize the USB driver */
USBD_Init();
}
/**
* Invoked whenever the active configuration of device is changed by the
* host.
* \param cfgnum Configuration number.
*/
void CDCDSerialDriver_ConfigurationChangedHandler(uint8_t cfgnum)
{
USBDDriver *pUsbd = USBD_GetDriver();
USBConfigurationDescriptor *pDesc;
if (cfgnum) {
pDesc = USBDDriver_GetCfgDescriptors(pUsbd, cfgnum);
CDCDSerial_ConfigureFunction((USBGenericDescriptor *)pDesc,
pDesc->wTotalLength);
}
}
/**
* Handles CDC-specific SETUP requests. Should be called from a
* re-implementation of USBDCallbacks_RequestReceived() method.
* \param request Pointer to a USBGenericRequest instance.
*/
void CDCDSerialDriver_RequestHandler(const USBGenericRequest *request)
{
USBDDriver *pUsbd = USBD_GetDriver();
TRACE_INFO_WP("NewReq ");
if (CDCDSerial_RequestHandler(request))
USBDDriver_RequestHandler(pUsbd, request);
}
/**@}*/

View File

@ -0,0 +1,458 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
*
* 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 disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
* ----------------------------------------------------------------------------
*/
/**\file
* Implementation of the CDCDSerialPort class methods.
*/
/** \addtogroup usbd_cdc
*@{
*/
/*------------------------------------------------------------------------------
* Headers
*------------------------------------------------------------------------------*/
#include <CDCDSerialPort.h>
#include <CDCDescriptors.h>
#include <USBLib_Trace.h>
/*------------------------------------------------------------------------------
* Types
*------------------------------------------------------------------------------*/
/** Parse data extention for descriptor parsing */
typedef struct _CDCDParseData {
/** Pointer to CDCDSerialPort instance */
CDCDSerialPort * pCdcd;
/** Pointer to found interface descriptor */
USBInterfaceDescriptor * pIfDesc;
} CDCDParseData;
/*------------------------------------------------------------------------------
* Internal variables
*------------------------------------------------------------------------------*/
/** Line coding values */
static CDCLineCoding lineCoding;
/*------------------------------------------------------------------------------
* Internal functions
*------------------------------------------------------------------------------*/
/**
* Parse descriptors: Interface, Bulk IN/OUT, Interrupt IN.
* \param desc Pointer to descriptor list.
* \param arg Argument, pointer to AUDDParseData instance.
*/
static uint32_t _Interfaces_Parse(USBGenericDescriptor *pDesc,
CDCDParseData * pArg)
{
CDCDSerialPort *pCdcd = pArg->pCdcd;
/* Not a valid descriptor */
if (pDesc->bLength == 0)
return USBRC_PARAM_ERR;
/* Find interface descriptor */
if (pDesc->bDescriptorType == USBGenericDescriptor_INTERFACE) {
USBInterfaceDescriptor *pIf = (USBInterfaceDescriptor*)pDesc;
/* Obtain interface from descriptor */
if (pCdcd->bInterfaceNdx == 0xFF) {
/* First interface is communication */
if (pIf->bInterfaceClass ==
CDCCommunicationInterfaceDescriptor_CLASS) {
pCdcd->bInterfaceNdx = pIf->bInterfaceNumber;
pCdcd->bNumInterface = 2;
}
/* Only data interface */
else if(pIf->bInterfaceClass == CDCDataInterfaceDescriptor_CLASS) {
pCdcd->bInterfaceNdx = pIf->bInterfaceNumber;
pCdcd->bNumInterface = 1;
}
pArg->pIfDesc = pIf;
}
else if (pCdcd->bInterfaceNdx <= pIf->bInterfaceNumber
&& pCdcd->bInterfaceNdx + pCdcd->bNumInterface
> pIf->bInterfaceNumber) {
pArg->pIfDesc = pIf;
}
}
/* Parse valid interfaces */
if (pArg->pIfDesc == 0)
return 0;
/* Find endpoint descriptors */
if (pDesc->bDescriptorType == USBGenericDescriptor_ENDPOINT) {
USBEndpointDescriptor *pEp = (USBEndpointDescriptor*)pDesc;
switch(pEp->bmAttributes & 0x3) {
case USBEndpointDescriptor_INTERRUPT:
if (pEp->bEndpointAddress & 0x80)
pCdcd->bIntInPIPE = pEp->bEndpointAddress & 0x7F;
break;
case USBEndpointDescriptor_BULK:
if (pEp->bEndpointAddress & 0x80)
pCdcd->bBulkInPIPE = pEp->bEndpointAddress & 0x7F;
else
pCdcd->bBulkOutPIPE = pEp->bEndpointAddress;
}
}
if ( pCdcd->bInterfaceNdx != 0xFF
&& pCdcd->bBulkInPIPE != 0
&& pCdcd->bBulkOutPIPE != 0)
return USBRC_FINISHED;
return 0;
}
/**
* Callback function which should be invoked after the data of a
* SetLineCoding request has been retrieved. Sends a zero-length packet
* to the host for acknowledging the request.
* \param pCdcd Pointer to CDCDSerialPort instance.
*/
static void _SetLineCodingCallback(CDCDSerialPort * pCdcd)
{
uint32_t exec = 1;
if (pCdcd->fEventHandler) {
uint32_t rc = pCdcd->fEventHandler(
CDCDSerialPortEvent_SETLINECODING,
(uint32_t)(&lineCoding),
pCdcd->pArg);
if (rc == USBD_STATUS_SUCCESS) {
pCdcd->lineCoding.dwDTERate = lineCoding.dwDTERate;
pCdcd->lineCoding.bCharFormat = lineCoding.bCharFormat;
pCdcd->lineCoding.bParityType = lineCoding.bParityType;
pCdcd->lineCoding.bDataBits = lineCoding.bDataBits;
}
else
exec = 0;
}
if (exec) USBD_Write(0, 0, 0, 0, 0);
else USBD_Stall(0);
}
/**
* Receives new line coding information from the USB host.
* \param pCdcd Pointer to CDCDSerialPort instance.
*/
static void _SetLineCoding(CDCDSerialPort * pCdcd)
{
TRACE_INFO_WP("sLineCoding ");
USBD_Read(0,
(void *) & (lineCoding),
sizeof(CDCLineCoding),
(TransferCallback)_SetLineCodingCallback,
(void*)pCdcd);
}
/**
* Sends the current line coding information to the host through Control
* endpoint 0.
* \param pCdcd Pointer to CDCDSerialPort instance.
*/
static void _GetLineCoding(CDCDSerialPort * pCdcd)
{
TRACE_INFO_WP("gLineCoding ");
USBD_Write(0,
(void *) &(pCdcd->lineCoding),
sizeof(CDCLineCoding),
0,
0);
}
/**
* Changes the state of the serial driver according to the information
* sent by the host via a SetControlLineState request, and acknowledges
* the request with a zero-length packet.
* \param pCdcd Pointer to CDCDSerialPort instance.
* \param request Pointer to a USBGenericRequest instance.
*/
static void _SetControlLineState(
CDCDSerialPort * pCdcd,
const USBGenericRequest *request)
{
#if (TRACE_LEVEL >= TRACE_LEVEL_INFO)
uint8_t DTR, RTS;
DTR = ((request->wValue & CDCControlLineState_DTR) > 0);
RTS = ((request->wValue & CDCControlLineState_RTS) > 0);
TRACE_INFO_WP("sControlLineState(%d, %d) ", DTR, RTS);
#endif
pCdcd->bControlLineState = (uint8_t)request->wValue;
USBD_Write(0, 0, 0, 0, 0);
if (pCdcd->fEventHandler)
pCdcd->fEventHandler(CDCDSerialPortEvent_SETCONTROLLINESTATE,
(uint32_t)pCdcd->bControlLineState,
pCdcd->pArg);
}
/*------------------------------------------------------------------------------
* Exported functions
*------------------------------------------------------------------------------*/
/**
* Initializes the USB Device CDC serial port function.
* \param pCdcd Pointer to CDCDSerialPort instance.
* \param pUsbd Pointer to USBDDriver instance.
* \param fEventHandler Pointer to event handler function.
* \param firstInterface First interface index for the function
* (0xFF to parse from descriptors).
* \param numInterface Number of interfaces for the function.
*/
void CDCDSerialPort_Initialize(CDCDSerialPort * pCdcd,
USBDDriver * pUsbd,
CDCDSerialPortEventHandler fEventHandler,
void * pArg,
uint8_t firstInterface,uint8_t numInterface)
{
TRACE_INFO("CDCDSerialPort_Initialize\n\r");
/* Initialize event handler */
pCdcd->fEventHandler = fEventHandler;
pCdcd->pArg = pArg;
/* Initialize USB Device Driver interface */
pCdcd->pUsbd = pUsbd;
pCdcd->bInterfaceNdx = firstInterface;
pCdcd->bNumInterface = numInterface;
pCdcd->bIntInPIPE = 0;
pCdcd->bBulkInPIPE = 0;
pCdcd->bBulkOutPIPE = 0;
/* Initialize Abstract Control Model attributes */
pCdcd->bControlLineState = 0;
pCdcd->wSerialState = 0;
CDCLineCoding_Initialize(&(pCdcd->lineCoding),
115200,
CDCLineCoding_ONESTOPBIT,
CDCLineCoding_NOPARITY,
8);
}
/**
* Parse CDC Serial Port information for CDCDSerialPort instance.
* Accepted interfaces:
* - Communication Interface + Data Interface
* - Data Interface ONLY
* \param pCdcd Pointer to CDCDSerialPort instance.
* \param pDescriptors Pointer to descriptor list.
* \param dwLength Descriptor list size in bytes.
*/
USBGenericDescriptor *CDCDSerialPort_ParseInterfaces(
CDCDSerialPort *pCdcd,
USBGenericDescriptor *pDescriptors,
uint32_t dwLength)
{
CDCDParseData parseData;
parseData.pCdcd = pCdcd;
parseData.pIfDesc = 0;
return USBGenericDescriptor_Parse(
pDescriptors, dwLength,
(USBDescriptorParseFunction)_Interfaces_Parse,
&parseData);
}
/**
* Handles CDC-specific SETUP requests. Should be called from a
* re-implementation of USBDCallbacks_RequestReceived() method.
* \param pCdcd Pointer to CDCDSerialPort instance.
* \param request Pointer to a USBGenericRequest instance.
* \return USBRC_SUCCESS if request handled, otherwise error.
*/
uint32_t CDCDSerialPort_RequestHandler(
CDCDSerialPort *pCdcd,
const USBGenericRequest *request)
{
if (USBGenericRequest_GetType(request) != USBGenericRequest_CLASS)
return USBRC_PARAM_ERR;
TRACE_INFO_WP("Cdcs ");
/* Validate interface */
if (request->wIndex >= pCdcd->bInterfaceNdx &&
request->wIndex < pCdcd->bInterfaceNdx + pCdcd->bNumInterface) {
}
else {
return USBRC_PARAM_ERR;
}
/* Handle the request */
switch (USBGenericRequest_GetRequest(request)) {
case CDCGenericRequest_SETLINECODING:
_SetLineCoding(pCdcd);
break;
case CDCGenericRequest_GETLINECODING:
_GetLineCoding(pCdcd);
break;
case CDCGenericRequest_SETCONTROLLINESTATE:
_SetControlLineState(pCdcd, request);
break;
default:
return USBRC_PARAM_ERR;
}
return USBRC_SUCCESS;
}
/**
* Receives data from the host through the virtual COM port created by
* the CDC device serial driver. This function behaves like USBD_Read.
* \param pCdcd Pointer to CDCDSerialPort instance.
* \param pData Pointer to the data buffer to put received data.
* \param dwSize Size of the data buffer in bytes.
* \param fCallback Optional callback function to invoke when the transfer
* finishes.
* \param pArg Optional argument to the callback function.
* \return USBD_STATUS_SUCCESS if the read operation has been started normally;
* otherwise, the corresponding error code.
*/
uint32_t CDCDSerialPort_Read(const CDCDSerialPort * pCdcd,
void * pData,uint32_t dwSize,
TransferCallback fCallback,void * pArg)
{
if (pCdcd->bBulkOutPIPE == 0)
return USBRC_PARAM_ERR;
return USBD_Read(pCdcd->bBulkOutPIPE,
pData, dwSize,
fCallback, pArg);
}
/**
* Sends a data buffer through the virtual COM port created by the CDC
* device serial driver. This function behaves exactly like USBD_Write.
* \param pCdcd Pointer to CDCDSerialPort instance.
* \param pData Pointer to the data buffer to send.
* \param dwSize Size of the data buffer in bytes.
* \param fCallback Optional callback function to invoke when the transfer
* finishes.
* \param pArg Optional argument to the callback function.
* \return USBD_STATUS_SUCCESS if the read operation has been started normally;
* otherwise, the corresponding error code.
*/
uint32_t CDCDSerialPort_Write(const CDCDSerialPort * pCdcd,
void * pData, uint32_t dwSize,
TransferCallback fCallback, void * pArg)
{
if (pCdcd->bBulkInPIPE == 0)
return USBRC_PARAM_ERR;
return USBD_Write(pCdcd->bBulkInPIPE,
pData, dwSize,
fCallback, pArg);
}
/**
* Returns the current control line state of the RS-232 line.
* \param pCdcd Pointer to CDCDSerialPort instance.
*/
uint8_t CDCDSerialPort_GetControlLineState(const CDCDSerialPort * pCdcd)
{
return pCdcd->bControlLineState;
}
/**
* Copy current line coding settings to pointered space.
* \param pCdcd Pointer to CDCDSerialPort instance.
* \param pLineCoding Pointer to CDCLineCoding instance.
*/
void CDCDSerialPort_GetLineCoding(const CDCDSerialPort * pCdcd,
CDCLineCoding* pLineCoding)
{
if (pLineCoding) {
pLineCoding->dwDTERate = pCdcd->lineCoding.dwDTERate;
pLineCoding->bCharFormat = pCdcd->lineCoding.bCharFormat;
pLineCoding->bParityType = pCdcd->lineCoding.bParityType;
pLineCoding->bDataBits = pCdcd->lineCoding.bDataBits;
}
}
/**
* Returns the current status of the RS-232 line.
* \param pCdcd Pointer to CDCDSerialPort instance.
*/
uint16_t CDCDSerialPort_GetSerialState(const CDCDSerialPort * pCdcd)
{
return pCdcd->wSerialState;
}
/**
* Sets the current serial state of the device to the given value.
* \param pCdcd Pointer to CDCDSerialPort instance.
* \param wSerialState New device state.
*/
void CDCDSerialPort_SetSerialState(CDCDSerialPort * pCdcd,
uint16_t wSerialState)
{
if (pCdcd->bIntInPIPE == 0)
return;
/* If new state is different from previous one, send a notification to the
host */
if (pCdcd->wSerialState != wSerialState) {
pCdcd->wSerialState = wSerialState;
USBD_Write(pCdcd->bIntInPIPE,
&(pCdcd->wSerialState),
2,
0,
0);
/* Reset one-time flags */
pCdcd->wSerialState &= ~(CDCSerialState_OVERRUN
| CDCSerialState_PARITY
| CDCSerialState_FRAMING
| CDCSerialState_RINGSIGNAL
| CDCSerialState_BREAK);
}
}
/**@}*/

View File

@ -0,0 +1,70 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2010, Atmel Corporation
*
* 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 disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
* ----------------------------------------------------------------------------
*/
/*---------------------------------------------------------------------------
* Headers
*---------------------------------------------------------------------------*/
/* These headers were introduced in C99
by working group ISO/IEC JTC1/SC22/WG14. */
#include <stdint.h>
#include "CDCDSerial.h"
/*---------------------------------------------------------------------------
* Default callback functions
*---------------------------------------------------------------------------*/
/**
* Invoked when the CDC LineCoding is requested to changed
* \param port Port number.
* \param pLineCoding Pointer to new LineCoding settings.
* \return USBRC_SUCCESS if ready to receive the line coding.
*/
extern WEAK uint8_t CDCDSerial_LineCodingIsToChange(
CDCLineCoding * pLineCoding)
{
/* Accept any of linecoding settings */
pLineCoding = pLineCoding;
return USBRC_SUCCESS;
}
/**
* Invoked when the CDC ControlLineState is changed
* \param port Port number.
* \param DTR New DTR value.
* \param RTS New RTS value.
*/
extern WEAK void CDCDSerial_ControlLineStateChanged(uint8_t DTR,
uint8_t RTS)
{
/* Do nothing */
DTR = DTR; RTS = RTS;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

View File

@ -0,0 +1,45 @@
; $Id: 6119.inf,v 1.1.2.1 2006/12/05 08:33:25 danielru Exp $
[Version] ; Version section
Signature="$Chicago$" ; All Windows versions
Class=Ports ; This is a serial port driver
ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318} ; Associated GUID
Provider=%ATMEL% ; Driver is provided by ATMEL
DriverVer=09/12/2006,1.1.1.5 ; Driver version 1.1.1.5 published on 23 February 2007
[DestinationDirs] ; DestinationDirs section
DefaultDestDir=12 ; Default install directory is \drivers or \IOSubSys
[Manufacturer] ; Manufacturer section
%ATMEL%=AtmelMfg ; Only one manufacturer (ATMEL), models section is named
; AtmelMfg
[AtmelMfg] ; Models section corresponding to ATMEL
%USBtoSerialConverter%=USBtoSer.Install,USB\VID_03EB&PID_6119 ; Identifies a device with ATMEL Vendor ID (03EBh) and
; Product ID equal to 6119h. Corresponding Install section
; is named USBtoSer.Install
[USBtoSer.Install] ; Install section
include=mdmcpq.inf
CopyFiles=FakeModemCopyFileSection
AddReg=USBtoSer.AddReg ; Registry keys to add are listed in USBtoSer.AddReg
[USBtoSer.AddReg] ; AddReg section
HKR,,DevLoader,,*ntkern ;
HKR,,NTMPDriver,,usbser.sys
HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider"
[USBtoSer.Install.Services] ; Services section
AddService=usbser,0x00000002,USBtoSer.AddService ; Assign usbser as the PnP driver for the device
[USBtoSer.AddService] ; Service install section
DisplayName=%USBSer% ; Name of the serial driver
ServiceType=1 ; Service kernel driver
StartType=3 ; Driver is started by the PnP manager
ErrorControl=1 ; Warn about errors
ServiceBinary=%12%\usbser.sys ; Driver filename
[Strings] ; Strings section
ATMEL="ATMEL Corp." ; String value for the ATMEL symbol
USBtoSerialConverter="AT91 USB to Serial Converter" ; String value for the USBtoSerialConverter symbol
USBSer="USB Serial Driver" ; String value for the USBSer symbol

View File

@ -0,0 +1,550 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
*
* 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 disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
* ----------------------------------------------------------------------------
*/
/** \file
*
* \section Purpose
*
* Implementation of USB device functions on a UDP controller.
*
* See \ref usbd_api "USBD API Methods".
*/
/** \addtogroup usbd_interface
*@{
*/
/*---------------------------------------------------------------------------
* Headers
*---------------------------------------------------------------------------*/
#include "USBD.h"
#include "USBD_HAL.h"
#include <USBLib_Trace.h>
/*---------------------------------------------------------------------------
* Definitions
*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------
* Internal variables
*---------------------------------------------------------------------------*/
/** Device current state. */
static uint8_t deviceState;
/** Indicates the previous device state */
static uint8_t previousDeviceState;
/*---------------------------------------------------------------------------
* Internal Functions
*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------
* Exported functions
*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------
* USBD: Event handlers
*---------------------------------------------------------------------------*/
/**
* Handle the USB suspend event, should be invoked whenever
* HW reports a suspend signal.
*/
void USBD_SuspendHandler(void)
{
/* Don't do anything if the device is already suspended */
if (deviceState != USBD_STATE_SUSPENDED) {
/* Switch to the Suspended state */
previousDeviceState = deviceState;
deviceState = USBD_STATE_SUSPENDED;
/* Suspend HW interface */
USBD_HAL_Suspend();
/* Invoke the User Suspended callback (Suspend System?) */
if (NULL != USBDCallbacks_Suspended)
USBDCallbacks_Suspended();
}
}
/**
* Handle the USB resume event, should be invoked whenever
* HW reports a resume signal.
*/
void USBD_ResumeHandler(void)
{
/* Don't do anything if the device was not suspended */
if (deviceState == USBD_STATE_SUSPENDED) {
/* Active the device */
USBD_HAL_Activate();
deviceState = previousDeviceState;
if (deviceState >= USBD_STATE_DEFAULT) {
/* Invoke the Resume callback */
if (NULL != USBDCallbacks_Resumed)
USBDCallbacks_Resumed();
}
}
}
/**
* Handle the USB reset event, should be invoked whenever
* HW found USB reset signal on bus, which usually is called
* "end of bus reset" status.
*/
void USBD_ResetHandler()
{
/* The device enters the Default state */
deviceState = USBD_STATE_DEFAULT;
/* Active the USB HW */
USBD_HAL_Activate();
/* Only EP0 enabled */
USBD_HAL_ResetEPs(0xFFFFFFFF, USBD_STATUS_RESET, 0);
USBD_ConfigureEndpoint(0);
/* Invoke the Reset callback */
if (NULL != USBDCallbacks_Reset)
USBDCallbacks_Reset();
}
/**
* Handle the USB setup package received, should be invoked
* when an endpoint got a setup package as request.
* \param bEndpoint Endpoint number.
* \param pRequest Pointer to content of request.
*/
void USBD_RequestHandler(uint8_t bEndpoint,
const USBGenericRequest* pRequest)
{
if (bEndpoint != 0) {
TRACE_WARNING("EP%d request not supported, default EP only",
bEndpoint);
}
else if (NULL != USBDCallbacks_RequestReceived) {
USBDCallbacks_RequestReceived(pRequest);
}
}
/*---------------------------------------------------------------------------
* USBD: Library interface
*---------------------------------------------------------------------------*/
/**
* Configures an endpoint according to its Endpoint Descriptor.
* \param pDescriptor Pointer to an Endpoint descriptor.
*/
void USBD_ConfigureEndpoint(const USBEndpointDescriptor *pDescriptor)
{
USBD_HAL_ConfigureEP(pDescriptor);
}
/**
* Sends data through a USB endpoint. Sets up the transfer descriptor,
* writes one or two data payloads (depending on the number of FIFO bank
* for the endpoint) and then starts the actual transfer. The operation is
* complete when all the data has been sent.
*
* *If the size of the buffer is greater than the size of the endpoint
* (or twice the size if the endpoint has two FIFO banks), then the buffer
* must be kept allocated until the transfer is finished*. This means that
* it is not possible to declare it on the stack (i.e. as a local variable
* of a function which returns after starting a transfer).
*
* \param bEndpoint Endpoint number.
* \param pData Pointer to a buffer with the data to send.
* \param dLength Size of the data buffer.
* \param fCallback Optional callback function to invoke when the transfer is
* complete.
* \param pArgument Optional argument to the callback function.
* \return USBD_STATUS_SUCCESS if the transfer has been started;
* otherwise, the corresponding error status code.
*/
uint8_t USBD_Write( uint8_t bEndpoint,
const void *pData,
uint32_t dLength,
TransferCallback fCallback,
void *pArgument )
{
USBD_HAL_SetTransferCallback(bEndpoint, fCallback, pArgument);
return USBD_HAL_Write(bEndpoint, pData, dLength);
}
#if 0
/**
* Sends data frames through a USB endpoint. Sets up the transfer descriptor
* list, writes one or two data payloads (depending on the number of FIFO bank
* for the endpoint) and then starts the actual transfer. The operation is
* complete when all the data has been sent.
*
* *If the size of the frame is greater than the size of the endpoint
* (or twice the size if the endpoint has two FIFO banks), then the buffer
* must be kept allocated until the frame is finished*. This means that
* it is not possible to declare it on the stack (i.e. as a local variable
* of a function which returns after starting a transfer).
*
* \param bEndpoint Endpoint number.
* \param pMbl Pointer to a frame (USBDTransferBuffer) list that describes
* the buffer list to send.
* \param wListSize Size of the frame list.
* \param bCircList Circle the list.
* \param wStartNdx For circled list only, the first buffer index to transfer.
* \param fCallback Optional callback function to invoke when the transfer is
* complete.
* \param pArgument Optional argument to the callback function.
* \return USBD_STATUS_SUCCESS if the transfer has been started;
* otherwise, the corresponding error status code.
* \see USBDTransferBuffer, MblTransferCallback, USBD_MblReuse
*/
uint8_t USBD_MblWrite( uint8_t bEndpoint,
void *pMbl,
uint16_t wListSize,
uint8_t bCircList,
uint16_t wStartNdx,
MblTransferCallback fCallback,
void *pArgument )
{
Endpoint *pEndpoint = &(endpoints[bEndpoint]);
MblTransfer *pTransfer = (MblTransfer*)&(pEndpoint->transfer);
uint16_t i;
/* EP0 is not suitable for Mbl */
if (bEndpoint == 0) {
return USBD_STATUS_INVALID_PARAMETER;
}
/* Check that the endpoint is in Idle state */
if (pEndpoint->state != UDP_ENDPOINT_IDLE) {
return USBD_STATUS_LOCKED;
}
pEndpoint->state = UDP_ENDPOINT_SENDINGM;
TRACE_DEBUG_WP("WriteM%d(0x%x,%d) ", bEndpoint, pMbl, wListSize);
/* Start from first if not circled list */
if (!bCircList) wStartNdx = 0;
/* Setup the transfer descriptor */
pTransfer->pMbl = (USBDTransferBuffer*)pMbl;
pTransfer->listSize = wListSize;
pTransfer->fCallback = fCallback;
pTransfer->pArgument = pArgument;
pTransfer->currBuffer = wStartNdx;
pTransfer->freedBuffer = 0;
pTransfer->pLastLoaded = &(((USBDTransferBuffer*)pMbl)[wStartNdx]);
pTransfer->circList = bCircList;
pTransfer->allUsed = 0;
/* Clear all buffer */
for (i = 0; i < wListSize; i ++) {
pTransfer->pMbl[i].transferred = 0;
pTransfer->pMbl[i].buffered = 0;
pTransfer->pMbl[i].remaining = pTransfer->pMbl[i].size;
}
/* Send the first packet */
while((UDP->UDP_CSR[bEndpoint]&UDP_CSR_TXPKTRDY)==UDP_CSR_TXPKTRDY);
UDP_MblWriteFifo(bEndpoint);
SET_CSR(bEndpoint, UDP_CSR_TXPKTRDY);
/* If double buffering is enabled and there is data remaining, */
/* prepare another packet */
if ((CHIP_USB_ENDPOINTS_BANKS(bEndpoint) > 1)
&& (pTransfer->pMbl[pTransfer->currBuffer].remaining > 0)) {
UDP_MblWriteFifo(bEndpoint);
}
/* Enable interrupt on endpoint */
UDP->UDP_IER = 1 << bEndpoint;
return USBD_STATUS_SUCCESS;
}
#endif
/**
* Reads incoming data on an USB endpoint This methods sets the transfer
* descriptor and activate the endpoint interrupt. The actual transfer is
* then carried out by the endpoint interrupt handler. The Read operation
* finishes either when the buffer is full, or a short packet (inferior to
* endpoint maximum size) is received.
*
* *The buffer must be kept allocated until the transfer is finished*.
* \param bEndpoint Endpoint number.
* \param pData Pointer to a data buffer.
* \param dLength Size of the data buffer in bytes.
* \param fCallback Optional end-of-transfer callback function.
* \param pArgument Optional argument to the callback function.
* \return USBD_STATUS_SUCCESS if the read operation has been started;
* otherwise, the corresponding error code.
*/
uint8_t USBD_Read(uint8_t bEndpoint,
void *pData,
uint32_t dLength,
TransferCallback fCallback,
void *pArgument)
{
USBD_HAL_SetTransferCallback(bEndpoint, fCallback, pArgument);
return USBD_HAL_Read(bEndpoint, pData, dLength);
}
#if 0
/**
* Reuse first used/released buffer with new buffer address and size to be used
* in transfer again. Only valid when frame list is ringed. Can be used for
* both read & write.
* \param bEndpoint Endpoint number.
* \param pNewBuffer Pointer to new buffer with data to send (0 to keep last).
* \param wNewSize Size of the data buffer
*/
uint8_t USBD_MblReuse( uint8_t bEndpoint,
uint8_t *pNewBuffer,
uint16_t wNewSize )
{
Endpoint *pEndpoint = &(endpoints[bEndpoint]);
MblTransfer *pTransfer = (MblTransfer*)&(pEndpoint->transfer);
USBDTransferBuffer *pBi = &(pTransfer->pMbl[pTransfer->freedBuffer]);
TRACE_DEBUG_WP("MblReuse(%d), st%x, circ%d\n\r",
bEndpoint, pEndpoint->state, pTransfer->circList);
/* Only for Multi-buffer-circle list */
if (bEndpoint != 0
&& (pEndpoint->state == UDP_ENDPOINT_RECEIVINGM
|| pEndpoint->state == UDP_ENDPOINT_SENDINGM)
&& pTransfer->circList) {
}
else {
return USBD_STATUS_WRONG_STATE;
}
/* Check if there is freed buffer */
if (pTransfer->freedBuffer == pTransfer->currBuffer
&& !pTransfer->allUsed) {
return USBD_STATUS_LOCKED;
}
/* Update transfer information */
if ((++ pTransfer->freedBuffer) == pTransfer->listSize)
pTransfer->freedBuffer = 0;
if (pNewBuffer) {
pBi->pBuffer = pNewBuffer;
pBi->size = wNewSize;
}
pBi->buffered = 0;
pBi->transferred = 0;
pBi->remaining = pBi->size;
/* At least one buffer is not processed */
pTransfer->allUsed = 0;
return USBD_STATUS_SUCCESS;
}
#endif
/**
* Sets the HALT feature on the given endpoint (if not already in this state).
* \param bEndpoint Endpoint number.
*/
void USBD_Halt(uint8_t bEndpoint)
{
USBD_HAL_Halt(bEndpoint, 1);
}
/**
* Clears the Halt feature on the given endpoint.
* \param bEndpoint Index of endpoint
*/
void USBD_Unhalt(uint8_t bEndpoint)
{
USBD_HAL_Halt(bEndpoint, 0);
}
/**
* Returns the current Halt status of an endpoint.
* \param bEndpoint Index of endpoint
* \return 1 if the endpoint is currently halted; otherwise 0
*/
uint8_t USBD_IsHalted(uint8_t bEndpoint)
{
return USBD_HAL_Halt(bEndpoint, 0xFF);
}
/**
* Indicates if the device is running in high or full-speed. Always returns 0
* since UDP does not support high-speed mode.
*/
uint8_t USBD_IsHighSpeed(void)
{
return USBD_HAL_IsHighSpeed();
}
/**
* Causes the given endpoint to acknowledge the next packet it receives
* with a STALL handshake.
* \param bEndpoint Endpoint number.
* \return USBD_STATUS_SUCCESS or USBD_STATUS_LOCKED.
*/
uint8_t USBD_Stall(uint8_t bEndpoint)
{
return USBD_HAL_Stall(bEndpoint);
}
/**
* Sets the device address to the given value.
* \param address New device address.
*/
void USBD_SetAddress(uint8_t address)
{
TRACE_INFO_WP("SetAddr(%d) ", address);
USBD_HAL_SetAddress(address);
if (address == 0) deviceState = USBD_STATE_DEFAULT;
else deviceState = USBD_STATE_ADDRESS;
}
/**
* Sets the current device configuration.
* \param cfgnum - Configuration number to set.
*/
void USBD_SetConfiguration(uint8_t cfgnum)
{
TRACE_INFO_WP("SetCfg(%d) ", cfgnum);
USBD_HAL_SetConfiguration(cfgnum);
if (cfgnum != 0) {
deviceState = USBD_STATE_CONFIGURED;
}
else {
deviceState = USBD_STATE_ADDRESS;
/* Reset all endpoints but Control 0 */
USBD_HAL_ResetEPs(0xFFFFFFFE, USBD_STATUS_RESET, 0);
}
}
/*---------------------------------------------------------------------------
* USBD: Library API
*---------------------------------------------------------------------------*/
/**
* Starts a remote wake-up procedure.
*/
void USBD_RemoteWakeUp(void)
{
/* Device is NOT suspended */
if (deviceState != USBD_STATE_SUSPENDED) {
TRACE_INFO("USBD_RemoteWakeUp: Device is not suspended\n\r");
return;
}
USBD_HAL_Activate();
USBD_HAL_RemoteWakeUp();
}
/**
* Connects the pull-up on the D+ line of the USB.
*/
void USBD_Connect(void)
{
USBD_HAL_Connect();
}
/**
* Disconnects the pull-up from the D+ line of the USB.
*/
void USBD_Disconnect(void)
{
USBD_HAL_Disconnect();
/* Device returns to the Powered state */
if (deviceState > USBD_STATE_POWERED) {
deviceState = USBD_STATE_POWERED;
}
if (previousDeviceState > USBD_STATE_POWERED) {
previousDeviceState = USBD_STATE_POWERED;
}
}
/**
* Initializes the USB driver.
*/
void USBD_Init(void)
{
TRACE_INFO_WP("USBD_Init\n\r");
/* HW Layer Initialize */
USBD_HAL_Init();
/* Device is in the Attached state */
deviceState = USBD_STATE_SUSPENDED;
previousDeviceState = USBD_STATE_POWERED;
/* Upper Layer Initialize */
if (NULL != USBDCallbacks_Initialized)
USBDCallbacks_Initialized();
}
/**
* Returns the current state of the USB device.
* \return Device current state.
*/
uint8_t USBD_GetState(void)
{
return deviceState;
}
/**
* Certification test for High Speed device.
* \param bIndex Test to be done
*/
void USBD_Test(uint8_t bIndex)
{
USBD_HAL_Test(bIndex);
}
/**@}*/

View File

@ -0,0 +1,89 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
*
* 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 disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
* ----------------------------------------------------------------------------
*/
/** \file
* Definitions of callbacks used by the USBD API to notify the user
* application of incoming events. These functions are declared as 'weak',
* so they can be re-implemented elsewhere in the application in a
* transparent way.
*
* \addtogroup usbd_interface
*@{
*/
/*------------------------------------------------------------------------------
* Headers
*------------------------------------------------------------------------------*/
#include "USBD.h"
#include "USBDDriver.h"
/*------------------------------------------------------------------------------
* Exported function
*------------------------------------------------------------------------------*/
/**
* Invoked after the USB driver has been initialized. By default, do nothing.
*/
WEAK void USBDCallbacks_Initialized(void)
{
/* Does nothing */
}
/**
* Invoked when the USB driver is reset. Does nothing by default.
*/
WEAK void USBDCallbacks_Reset(void)
{
/* Does nothing*/
}
/**
* Invoked when the USB device gets suspended. By default, do nothing.
*/
WEAK void USBDCallbacks_Suspended(void) {}
/**
* Invoked when the USB device leaves the Suspended state. By default,
* Do nothing.
*/
WEAK void USBDCallbacks_Resumed(void) {}
/**
* USBDCallbacks_RequestReceived - Invoked when a new SETUP request is
* received. Does nothing by default.
* \param request Pointer to the request to handle.
*/
WEAK void USBDCallbacks_RequestReceived(const USBGenericRequest *request)
{
/* Does basic enumeration */
USBDDriver_RequestHandler(USBD_GetDriver(), request);
}
/**@}*/

View File

@ -0,0 +1,823 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
*
* 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 disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
* ----------------------------------------------------------------------------
*/
/** \file
* \addtogroup usbd_interface
*@{
*/
/*------------------------------------------------------------------------------
* Headers
*------------------------------------------------------------------------------*/
#include <USBLib_Trace.h>
#include "USBDDriver.h"
#include "USBD.h"
#include "USBD_HAL.h"
#include <string.h>
/*------------------------------------------------------------------------------
* Local variables
*------------------------------------------------------------------------------*/
/** Default device driver instance, for all class drivers in USB Lib. */
static USBDDriver usbdDriver;
/*------------------------------------------------------------------------------
* Local functions
*------------------------------------------------------------------------------*/
/**
* Send a NULL packet
*/
static void TerminateCtrlInWithNull(void *pArg,
uint8_t status,
uint32_t transferred,
uint32_t remaining)
{
pArg = pArg; status = status;
transferred = transferred; remaining = remaining;
USBD_Write(0, /* Endpoint #0 */
0, /* No data buffer */
0, /* No data buffer */
(TransferCallback) 0,
(void *) 0);
}
/**
* Configures the device by setting it into the Configured state and
* initializing all endpoints.
* \param pDriver Pointer to a USBDDriver instance.
* \param cfgnum Configuration number to set.
*/
static void SetConfiguration(USBDDriver *pDriver, uint8_t cfgnum)
{
USBEndpointDescriptor *pEndpoints[17];
const USBConfigurationDescriptor *pConfiguration;
/* Use different descriptor depending on device speed */
if ( USBD_HAL_IsHighSpeed()
&& pDriver->pDescriptors->pHsConfiguration) {
pConfiguration = pDriver->pDescriptors->pHsConfiguration;
}
else {
pConfiguration = pDriver->pDescriptors->pFsConfiguration;
}
/* Set & save the desired configuration */
USBD_SetConfiguration(cfgnum);
pDriver->cfgnum = cfgnum;
pDriver->isRemoteWakeUpEnabled =
((pConfiguration->bmAttributes & 0x20) > 0);
/* If the configuration is not 0, configure endpoints */
if (cfgnum != 0) {
/* Parse configuration to get endpoint descriptors */
USBConfigurationDescriptor_Parse(pConfiguration, 0, pEndpoints, 0);
/* Configure endpoints */
int i = 0;
while (pEndpoints[i] != 0) {
USBD_ConfigureEndpoint(pEndpoints[i]);
i++;
}
}
/* Should be done before send the ZLP */
if (NULL != USBDDriverCallbacks_ConfigurationChanged)
USBDDriverCallbacks_ConfigurationChanged(cfgnum);
/* Acknowledge the request */
USBD_Write(0, /* Endpoint #0 */
0, /* No data buffer */
0, /* No data buffer */
(TransferCallback) 0,
(void *) 0);
}
/**
* Sends the current configuration number to the host.
* \param pDriver Pointer to a USBDDriver instance.
*/
static void GetConfiguration(const USBDDriver *pDriver)
{
unsigned long tmp; // Coud be unsigned char : unsigned long has been chose to avoid any potential alignment issue with DMA
if( USBD_GetState() < USBD_STATE_CONFIGURED)
tmp = 0; // If device is unconfigured, returned configuration must be 0
else
tmp = pDriver->cfgnum;
USBD_Write(0, &tmp, 1, 0, 0);
}
/**
* Sends the current status of the device to the host.
* \param pDriver Pointer to a USBDDriver instance.
*/
static void GetDeviceStatus(const USBDDriver *pDriver)
{
static unsigned short data;
const USBConfigurationDescriptor *pConfiguration;
data = 0;
/* Use different configuration depending on device speed */
if (USBD_IsHighSpeed()) {
pConfiguration = pDriver->pDescriptors->pHsConfiguration;
}
else {
pConfiguration = pDriver->pDescriptors->pFsConfiguration;
}
/* Check current configuration for power mode (if device is configured) */
if (pDriver->cfgnum != 0) {
if (USBConfigurationDescriptor_IsSelfPowered(pConfiguration)) {
data |= 1;
}
}
/* Check if remote wake-up is enabled */
if (pDriver->isRemoteWakeUpEnabled) {
data |= 2;
}
/* Send the device status */
USBD_Write(0, &data, 2, 0, 0);
}
/**
* Sends the current status of an endpoints to the USB host.
* \param bEndpoint Endpoint number.
*/
static void GetEndpointStatus(uint8_t bEndpoint)
{
static unsigned short data;
data = 0;
switch (USBD_HAL_Halt(bEndpoint, 0xFF)) {
case USBD_STATUS_INVALID_PARAMETER: /* the endpoint not exists */
USBD_Stall(0);
break;
case 1:
data = 1;
case 0:
/* Send the endpoint status */
USBD_Write(0, &data, 2, 0, 0);
break;
}
}
/**
* Sends the requested USB descriptor to the host if available, or STALLs the
* request.
* \param pDriver Pointer to a USBDDriver instance.
* \param type Type of the requested descriptor
* \param index Index of the requested descriptor.
* \param length Maximum number of bytes to return.
*/
static void GetDescriptor(
const USBDDriver *pDriver,
uint8_t type,
uint8_t indexRDesc,
uint32_t length)
{
const USBDeviceDescriptor *pDevice;
const USBConfigurationDescriptor *pConfiguration;
const USBDeviceQualifierDescriptor *pQualifier;
const USBConfigurationDescriptor *pOtherSpeed;
const USBGenericDescriptor **pStrings =
(const USBGenericDescriptor **) pDriver->pDescriptors->pStrings;
const USBGenericDescriptor *pString;
uint8_t numStrings = pDriver->pDescriptors->numStrings;
uint8_t terminateWithNull = 0;
/* Use different set of descriptors depending on device speed */
/* By default, we uses full speed values */
pDevice = pDriver->pDescriptors->pFsDevice;
pConfiguration = pDriver->pDescriptors->pFsConfiguration;
/* HS, we try HS values */
if (USBD_HAL_IsHighSpeed()) {
TRACE_DEBUG_WP("HS ");
if (pDriver->pDescriptors->pHsDevice)
pDevice = pDriver->pDescriptors->pHsDevice;
if (pDriver->pDescriptors->pHsConfiguration)
pConfiguration = pDriver->pDescriptors->pHsConfiguration;
pQualifier = pDriver->pDescriptors->pHsQualifier;
pOtherSpeed = pDriver->pDescriptors->pHsOtherSpeed;
}
else {
TRACE_DEBUG_WP("FS ");
pQualifier = pDriver->pDescriptors->pFsQualifier;
pOtherSpeed = pDriver->pDescriptors->pFsOtherSpeed;
}
/* Check the descriptor type */
switch (type) {
case USBGenericDescriptor_DEVICE:
TRACE_INFO_WP("Dev ");
/* Adjust length and send descriptor */
if (length > USBGenericDescriptor_GetLength((USBGenericDescriptor *) pDevice)) {
length = USBGenericDescriptor_GetLength((USBGenericDescriptor *) pDevice);
}
USBD_Write(0, pDevice, length, 0, 0);
break;
case USBGenericDescriptor_CONFIGURATION:
TRACE_INFO_WP("Cfg ");
/* Adjust length and send descriptor */
if (length > USBConfigurationDescriptor_GetTotalLength(pConfiguration)) {
length = USBConfigurationDescriptor_GetTotalLength(pConfiguration);
terminateWithNull = ((length % pDevice->bMaxPacketSize0) == 0);
}
USBD_Write(0,
pConfiguration,
length,
terminateWithNull ? TerminateCtrlInWithNull : 0,
0);
break;
case USBGenericDescriptor_DEVICEQUALIFIER:
TRACE_INFO_WP("Qua ");
/* Check if descriptor exists */
if (!pQualifier) {
USBD_Stall(0);
}
else {
/* Adjust length and send descriptor */
if (length > USBGenericDescriptor_GetLength((USBGenericDescriptor *) pQualifier)) {
length = USBGenericDescriptor_GetLength((USBGenericDescriptor *) pQualifier);
}
USBD_Write(0, pQualifier, length, 0, 0);
}
break;
case USBGenericDescriptor_OTHERSPEEDCONFIGURATION:
TRACE_INFO_WP("OSC ");
/* Check if descriptor exists */
if (!pOtherSpeed) {
USBD_Stall(0);
}
else {
/* Adjust length and send descriptor */
if (length > USBConfigurationDescriptor_GetTotalLength(pOtherSpeed)) {
length = USBConfigurationDescriptor_GetTotalLength(pOtherSpeed);
terminateWithNull = ((length % pDevice->bMaxPacketSize0) == 0);
}
USBD_Write(0,
pOtherSpeed,
length,
terminateWithNull ? TerminateCtrlInWithNull : 0,
0);
}
break;
case USBGenericDescriptor_STRING:
TRACE_INFO_WP("Str%d ", indexRDesc);
/* Check if descriptor exists */
if (indexRDesc >= numStrings) {
USBD_Stall(0);
}
else {
pString = pStrings[indexRDesc];
/* Adjust length and send descriptor */
if (length > USBGenericDescriptor_GetLength(pString)) {
length = USBGenericDescriptor_GetLength(pString);
terminateWithNull = ((length % pDevice->bMaxPacketSize0) == 0);
}
USBD_Write(0,
pString,
length,
terminateWithNull ? TerminateCtrlInWithNull : 0,
0);
}
break;
default:
TRACE_WARNING(
"USBDDriver_GetDescriptor: Unknown descriptor type (%d)\n\r",
type);
USBD_Stall(0);
}
}
/**
* Sets the active setting of the given interface if the configuration supports
* it; otherwise, the control pipe is STALLed. If the setting of an interface
* changes.
* \parma pDriver Pointer to a USBDDriver instance.
* \parma infnum Interface number.
* \parma setting New active setting for the interface.
*/
static void SetInterface(
USBDDriver *pDriver,
uint8_t infnum,
uint8_t setting)
{
/* Make sure alternate settings are supported */
if (!pDriver->pInterfaces) {
USBD_Stall(0);
}
else {
/* Change the current setting of the interface and trigger the callback */
/* if necessary */
if (pDriver->pInterfaces[infnum] != setting) {
pDriver->pInterfaces[infnum] = setting;
if (NULL != USBDDriverCallbacks_InterfaceSettingChanged)
USBDDriverCallbacks_InterfaceSettingChanged(infnum, setting);
}
/* Acknowledge the request */
USBD_Write(0, 0, 0, 0, 0);
}
}
/**
* Sends the currently active setting of the given interface to the USB
* host. If alternate settings are not supported, this function STALLs the
* control pipe.
* \param pDriver Pointer to a USBDDriver instance.
* \param infnum Interface number.
*/
static void GetInterface(
const USBDDriver *pDriver,
uint8_t infnum)
{
/* Make sure alternate settings are supported, or STALL the control pipe */
if (!pDriver->pInterfaces) {
USBD_Stall(0);
}
else {
/* Sends the current interface setting to the host */
USBD_Write(0, &(pDriver->pInterfaces[infnum]), 1, 0, 0);
}
}
/**
* Performs the selected test on the USB device (high-speed only).
* \param test Test selector value.
*/
static void USBDDriver_Test(const USBDDriver *pDriver, uint8_t test)
{
pDriver = pDriver;
TRACE_DEBUG("UDPHS_Test\n\r");
/* the lower byte of wIndex must be zero
the most significant byte of wIndex is used to specify the specific test mode */
switch (test) {
case USBFeatureRequest_TESTPACKET:
/*Test mode Test_Packet: */
/*Upon command, a port must repetitively transmit the following test packet until */
/*the exit action is taken. This enables the testing of rise and fall times, eye */
/*patterns, jitter, and any other dynamic waveform specifications. */
/*The test packet is made up by concatenating the following strings. */
/*(Note: For J/K NRZI data, and for NRZ data, the bit on the left is the first one */
/*transmitted. “S?indicates that a bit stuff occurs, which inserts an “extra?NRZI data bit. */
/*? N?is used to indicate N occurrences of a string of bits or symbols.) */
/*A port in Test_Packet mode must send this packet repetitively. The inter-packet timing */
/*must be no less than the minimum allowable inter-packet gap as defined in Section 7.1.18 and */
/*no greater than 125 us. */
/* Send ZLP */
USBD_Test(USBFeatureRequest_TESTSENDZLP);
/* Tst PACKET */
USBD_Test(USBFeatureRequest_TESTPACKET);
while (1);
/*break; not reached */
case USBFeatureRequest_TESTJ:
/*Test mode Test_J: */
/*Upon command, a ports transceiver must enter the high-speed J state and remain in that */
/*state until the exit action is taken. This enables the testing of the high output drive */
/*level on the D+ line. */
/* Send ZLP */
USBD_Test(USBFeatureRequest_TESTSENDZLP);
/* Tst J */
USBD_Test(USBFeatureRequest_TESTJ);
while (1);
/*break; not reached */
case USBFeatureRequest_TESTK:
/*Test mode Test_K: */
/*Upon command, a ports transceiver must enter the high-speed K state and remain in */
/*that state until the exit action is taken. This enables the testing of the high output drive */
/*level on the D- line. */
/* Send a ZLP */
USBD_Test(USBFeatureRequest_TESTSENDZLP);
USBD_Test(USBFeatureRequest_TESTK);
while (1);
/*break; not reached */
case USBFeatureRequest_TESTSE0NAK:
/*Test mode Test_SE0_NAK: */
/*Upon command, a ports transceiver must enter the high-speed receive mode */
/*and remain in that mode until the exit action is taken. This enables the testing */
/*of output impedance, low level output voltage, and loading characteristics. */
/*In addition, while in this mode, upstream facing ports (and only upstream facing ports) */
/*must respond to any IN token packet with a NAK handshake (only if the packet CRC is */
/*determined to be correct) within the normal allowed device response time. This enables testing of */
/*the device squelch level circuitry and, additionally, provides a general purpose stimulus/response */
/*test for basic functional testing. */
/* Send a ZLP */
USBD_Test(USBFeatureRequest_TESTSENDZLP);
/* Test SE0_NAK */
USBD_Test(USBFeatureRequest_TESTSE0NAK);
while (1);
/*break; not reached */
default:
USBD_Stall(0);
break;
}
/* The exit action is to power cycle the device. */
/* The device must be disconnected from the host */
}
/*------------------------------------------------------------------------------
* Exported functions
*------------------------------------------------------------------------------*/
/**
* Return USBDDriver instance pointer for global usage.
*/
USBDDriver *USBD_GetDriver(void)
{
return &usbdDriver;
}
/**
* Initializes a USBDDriver instance with a list of descriptors. If
* interfaces can have multiple alternate settings, an array to store the
* current setting for each interface must be provided.
* \param pDriver Pointer to a USBDDriver instance.
* \param pDescriptors Pointer to a USBDDriverDescriptors instance.
* \param pInterfaces Pointer to an array for storing the current alternate
* setting of each interface (optional).
*/
void USBDDriver_Initialize(
USBDDriver *pDriver,
const USBDDriverDescriptors *pDescriptors,
uint8_t *pInterfaces)
{
pDriver->cfgnum = 0;
pDriver->isRemoteWakeUpEnabled = 0;
pDriver->pDescriptors = pDescriptors;
pDriver->pInterfaces = pInterfaces;
/* Initialize interfaces array if not null */
if (pInterfaces != 0) {
memset(pInterfaces, sizeof(pInterfaces), 0);
}
}
/**
* Returns configuration descriptor list.
* \param pDriver Pointer to a USBDDriver instance.
* \param cfgNum Reserved.
*/
USBConfigurationDescriptor *USBDDriver_GetCfgDescriptors(
USBDDriver *pDriver, uint8_t cfgNum)
{
USBDDriverDescriptors *pDescList = (USBDDriverDescriptors *)pDriver->pDescriptors;
USBConfigurationDescriptor *pCfg;
cfgNum = cfgNum;
if (USBD_HAL_IsHighSpeed() && pDescList->pHsConfiguration)
pCfg = (USBConfigurationDescriptor *)pDescList->pHsConfiguration;
else
pCfg = (USBConfigurationDescriptor *)pDescList->pFsConfiguration;
return pCfg;
}
/**
* Handles the given request if it is standard, otherwise STALLs it.
* \param pDriver Pointer to a USBDDriver instance.
* \param pRequest Pointer to a USBGenericRequest instance.
*/
void USBDDriver_RequestHandler(
USBDDriver *pDriver,
const USBGenericRequest *pRequest)
{
uint8_t cfgnum;
uint8_t infnum;
uint8_t eptnum;
uint8_t setting;
uint8_t type;
uint8_t indexDesc;
uint32_t length;
uint32_t address;
TRACE_INFO_WP("Std ");
/* Check request code */
switch (USBGenericRequest_GetRequest(pRequest)) {
case USBGenericRequest_GETDESCRIPTOR:
TRACE_INFO_WP("gDesc ");
/* Send the requested descriptor */
type = USBGetDescriptorRequest_GetDescriptorType(pRequest);
indexDesc = USBGetDescriptorRequest_GetDescriptorIndex(pRequest);
length = USBGenericRequest_GetLength(pRequest);
GetDescriptor(pDriver, type, indexDesc, length);
break;
case USBGenericRequest_SETADDRESS:
TRACE_INFO_WP("sAddr ");
/* Sends a zero-length packet and then set the device address */
address = USBSetAddressRequest_GetAddress(pRequest);
USBD_Write(0, 0, 0, (TransferCallback) USBD_SetAddress, (void *) address);
break;
case USBGenericRequest_SETCONFIGURATION:
TRACE_INFO_WP("sCfg ");
/* Set the requested configuration */
cfgnum = USBSetConfigurationRequest_GetConfiguration(pRequest);
SetConfiguration(pDriver, cfgnum);
break;
case USBGenericRequest_GETCONFIGURATION:
TRACE_INFO_WP("gCfg ");
/* Send the current configuration number */
GetConfiguration(pDriver);
break;
case USBGenericRequest_GETSTATUS:
TRACE_INFO_WP("gSta ");
/* Check who is the recipient */
switch (USBGenericRequest_GetRecipient(pRequest)) {
case USBGenericRequest_DEVICE:
TRACE_INFO_WP("Dev ");
/* Send the device status */
GetDeviceStatus(pDriver);
break;
case USBGenericRequest_ENDPOINT:
TRACE_INFO_WP("Ept ");
/* Send the endpoint status */
eptnum = USBGenericRequest_GetEndpointNumber(pRequest);
GetEndpointStatus(eptnum);
break;
default:
TRACE_WARNING(
"USBDDriver_RequestHandler: Unknown recipient (%d)\n\r",
USBGenericRequest_GetRecipient(pRequest));
USBD_Stall(0);
}
break;
case USBGenericRequest_CLEARFEATURE:
TRACE_INFO_WP("cFeat ");
/* Check which is the requested feature */
switch (USBFeatureRequest_GetFeatureSelector(pRequest)) {
case USBFeatureRequest_ENDPOINTHALT:
TRACE_INFO_WP("Hlt ");
/* Unhalt endpoint and send a zero-length packet */
USBD_Unhalt(USBGenericRequest_GetEndpointNumber(pRequest));
USBD_Write(0, 0, 0, 0, 0);
break;
case USBFeatureRequest_DEVICEREMOTEWAKEUP:
TRACE_INFO_WP("RmWU ");
/* Disable remote wake-up and send a zero-length packet */
pDriver->isRemoteWakeUpEnabled = 0;
USBD_Write(0, 0, 0, 0, 0);
break;
default:
TRACE_WARNING(
"USBDDriver_RequestHandler: Unknown feature selector (%d)\n\r",
USBFeatureRequest_GetFeatureSelector(pRequest));
USBD_Stall(0);
}
break;
case USBGenericRequest_SETFEATURE:
TRACE_INFO_WP("sFeat ");
/* Check which is the selected feature */
switch (USBFeatureRequest_GetFeatureSelector(pRequest)) {
case USBFeatureRequest_DEVICEREMOTEWAKEUP:
TRACE_INFO_WP("RmWU ");
/* Enable remote wake-up and send a ZLP */
pDriver->isRemoteWakeUpEnabled = 1;
USBD_Write(0, 0, 0, 0, 0);
break;
case USBFeatureRequest_ENDPOINTHALT:
TRACE_INFO_WP("Halt ");
/* Halt endpoint */
USBD_Halt(USBGenericRequest_GetEndpointNumber(pRequest));
USBD_Write(0, 0, 0, 0, 0);
break;
case USBFeatureRequest_TESTMODE:
/* 7.1.20 Test Mode Support, 9.4.9 Set Feature */
if ((USBGenericRequest_GetRecipient(pRequest) == USBGenericRequest_DEVICE)
&& ((USBGenericRequest_GetIndex(pRequest) & 0x000F) == 0)) {
/* Handle test request */
USBDDriver_Test(pDriver,
USBFeatureRequest_GetTestSelector(pRequest));
}
else {
USBD_Stall(0);
}
break;
#if 0
case USBFeatureRequest_OTG_B_HNP_ENABLE:
TRACE_INFO_WP("OTG_B_HNP_ENABLE ");
pDriver->otg_features_supported |=
1<<USBFeatureRequest_OTG_B_HNP_ENABLE;
USBD_Write(0, 0, 0, 0, 0);
break;
case USBFeatureRequest_OTG_A_HNP_SUPPORT:
TRACE_INFO_WP("OTG_A_HNP_SUPPORT ");
pDriver->otg_features_supported |=
1<<USBFeatureRequest_OTG_A_HNP_SUPPORT;
USBD_Write(0, 0, 0, 0, 0);
break;
case USBFeatureRequest_OTG_A_ALT_HNP_SUPPORT:
TRACE_INFO_WP("OTG_A_ALT_HNP_SUPPORT ");
pDriver->otg_features_supported |=
1<<USBFeatureRequest_OTG_A_ALT_HNP_SUPPORT;
USBD_Write(0, 0, 0, 0, 0);
break;
#endif
default:
TRACE_WARNING(
"USBDDriver_RequestHandler: Unknown feature selector (%d)\n\r",
USBFeatureRequest_GetFeatureSelector(pRequest));
USBD_Stall(0);
}
break;
case USBGenericRequest_SETINTERFACE:
TRACE_INFO_WP("sInterface ");
infnum = USBInterfaceRequest_GetInterface(pRequest);
setting = USBInterfaceRequest_GetAlternateSetting(pRequest);
SetInterface(pDriver, infnum, setting);
break;
case USBGenericRequest_GETINTERFACE:
TRACE_INFO_WP("gInterface ");
infnum = USBInterfaceRequest_GetInterface(pRequest);
GetInterface(pDriver, infnum);
break;
default:
TRACE_WARNING(
"USBDDriver_RequestHandler: Unknown request code (%d)\n\r",
USBGenericRequest_GetRequest(pRequest));
USBD_Stall(0);
}
}
/**
* Test if RemoteWakeUP feature is enabled
* \param pDriver Pointer to an USBDDriver instance.
* \return 1 if remote wake up has been enabled by the host; otherwise, returns
* 0
*/
uint8_t USBDDriver_IsRemoteWakeUpEnabled(const USBDDriver *pDriver)
{
return pDriver->isRemoteWakeUpEnabled;
}
/**
* Return OTG features supported
* \param pDriver Pointer to an USBDDriver instance.
* \return the OTG features
*/
uint8_t USBDDriver_returnOTGFeatures(const USBDDriver *pDriver)
{
return pDriver->otg_features_supported;
}
/**
* Clear OTG features supported
* \param pDriver Pointer to an USBDDriver instance.
* \return none
*/
void USBDDriver_clearOTGFeatures(USBDDriver *pDriver)
{
pDriver->otg_features_supported = 0;
}
/**@}*/

View File

@ -0,0 +1,84 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
*
* 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 disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
* ----------------------------------------------------------------------------
*/
/** \file
*
* \section Purpose
*
* Definition of several callbacks which are triggered by the USB software
* driver after receiving specific requests.
*
* \section Usage
*
* -# Re-implement the USBDDriverCallbacks_ConfigurationChanged
* callback to know when the hosts changes the active configuration of
* the device.
* -# Re-implement the USBDDriverCallbacks_InterfaceSettingChanged
* callback to get notified whenever the active setting of an interface
* is changed by the host.
*
* \addtogroup usbd_interface
*@{
*/
/*------------------------------------------------------------------------------
* Headers
*------------------------------------------------------------------------------*/
#include "USBDDriver.h"
#include <USBLib_Trace.h>
/*------------------------------------------------------------------------------
* Global functions
*------------------------------------------------------------------------------*/
/**
* Indicates that the current configuration of the device has changed.
* \param cfgnum New device configuration index.
*/
WEAK void USBDDriverCallbacks_ConfigurationChanged(uint8_t cfgnum)
{
cfgnum = cfgnum;
TRACE_INFO_WP("cfgChanged%d ", cfgnum);
}
/**
* Notifies of a change in the currently active setting of an interface.
* \param interface Number of the interface whose setting has changed.
* \param setting New interface setting.
*/
WEAK void USBDDriverCallbacks_InterfaceSettingChanged(
uint8_t interface,
uint8_t setting)
{
interface = interface; setting = setting;
TRACE_INFO_WP("ifSettingChanged%d.%d ", interface, setting);
}
/**@}*/

View File

@ -0,0 +1,307 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2010, Atmel Corporation
*
* 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 disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
* ----------------------------------------------------------------------------
*/
/**
* \file
*
* \section Purpose
*
* Definitions and methods for USB composite device implement.
*
*/
#ifndef CDCAUDDDRIVER_H
#define CDCAUDDDRIVER_H
/** \addtogroup usbd_composite_cdcaud
*@{
*/
/*---------------------------------------------------------------------------
* Headers
*---------------------------------------------------------------------------*/
#include <USBRequests.h>
#include <CDCDescriptors.h>
#include <AUDDescriptors.h>
#include "USBD.h"
#include <USBDDriver.h>
/*---------------------------------------------------------------------------
* Definitions
*---------------------------------------------------------------------------*/
/** \addtogroup usbd_cdc_aud_desc USB CDC(Serial) + AUD(Speaker) Definitions
* @{
*/
/** Number of interfaces of the device (5, can be 4 if no mic support */
#define CDCAUDDDriverDescriptors_MaxNumInterfaces 5
/** Number of the CDC interface. */
#define CDCAUDDDriverDescriptors_CDC_INTERFACE 0
/** Number of the Audio interface. */
#define CDCAUDDDriverDescriptors_AUD_INTERFACE 2
/** Number of Audio function channels (M,L,R) */
#define AUDD_NumChannels 3
/** @}*/
/*---------------------------------------------------------------------------
* Types
*---------------------------------------------------------------------------*/
#pragma pack(1)
#if defined ( __CC_ARM ) /* Keil ¦ÌVision 4 */
#elif defined ( __ICCARM__ ) /* IAR Ewarm */
#define __attribute__(...)
#define __packed__ packed
#elif defined ( __GNUC__ ) /* GCC CS3 */
#define __packed__ aligned(1)
#endif
/** Audio header descriptor with 1 interface */
typedef struct _AUDHeaderDescriptor1{
/** Header descriptor.*/
AUDHeaderDescriptor header;
/** Id of the first grouped interface.*/
uint8_t bInterface0;
} __attribute__ ((__packed__)) AUDHeaderDescriptor1;
/** Audio header descriptor with 2 interface */
typedef struct _AUDHeaderDescriptor2 {
/** Header descriptor. */
AUDHeaderDescriptor header;
/** Id of the first grouped interface - Speaker. */
uint8_t bInterface0;
/** Id of the second grouped interface - Speakerphone. */
uint8_t bInterface1;
} __attribute__ ((__packed__)) AUDHeaderDescriptor2; /* GCC */
/**
* Feature unit descriptor with 3 channel controls (master, right, left).
*/
typedef struct _AUDFeatureUnitDescriptor3{
/** Feature unit descriptor.*/
AUDFeatureUnitDescriptor feature;
/** Available controls for each channel.*/
uint8_t bmaControls[AUDD_NumChannels];
/** Index of a string descriptor for the feature unit.*/
uint8_t iFeature;
} __attribute__ ((__packed__)) AUDFeatureUnitDescriptor3;
/**
* List of descriptors for detailling the audio control interface of a
* device using a USB audio speaker function.
*/
typedef struct _AUDDSpeakerAcDescriptors{
/** Header descriptor (with one slave interface).*/
AUDHeaderDescriptor1 header;
/** Input terminal descriptor.*/
AUDInputTerminalDescriptor input;
/** Output terminal descriptor.*/
AUDOutputTerminalDescriptor output;
/** Feature unit descriptor.*/
AUDFeatureUnitDescriptor3 feature;
} __attribute__ ((__packed__)) AUDDSpeakerAcDescriptors;
/**
* List of descriptors for detailling the audio control interface of a
* device using a USB Audio Speakerphoneer function.
*/
typedef struct _AUDDSpeakerPhoneAcDescriptors {
/** Header descriptor (with one slave interface). */
AUDHeaderDescriptor2 header;
/** Input terminal descriptor. */
AUDInputTerminalDescriptor inputSpeakerPhone;
/** Output terminal descriptor. */
AUDOutputTerminalDescriptor outputSpeakerPhone;
/** Feature unit descriptor - SpeakerPhone. */
AUDFeatureUnitDescriptor3 featureSpeakerPhone;
/** Input terminal descriptor. */
AUDInputTerminalDescriptor inputRec;
/** Output terminal descriptor. */
AUDOutputTerminalDescriptor outputRec;
/** Feature unit descriptor - SpeakerPhonephone. */
AUDFeatureUnitDescriptor3 featureRec;
} __attribute__ ((__packed__)) AUDDSpeakerPhoneAcDescriptors;
/**
* Format type I descriptor with one discrete sampling frequency.
*/
typedef struct _AUDFormatTypeOneDescriptor1{
/** Format type I descriptor.*/
AUDFormatTypeOneDescriptor formatType;
/** Sampling frequency in Hz.*/
uint8_t tSamFreq[3];
} __attribute__ ((__packed__)) AUDFormatTypeOneDescriptor1;
/**
* Configuration descriptor list for a device implementing
* CDC(Serial) + Audio(Speaker) composite driver.
*/
typedef struct _CdcAudspkdDriverConfigurationDescriptors {
/** Standard configuration descriptor. */
USBConfigurationDescriptor configuration;
/* --- CDC 0 */
/** IAD 0 */
USBInterfaceAssociationDescriptor cdcIAD0;
/** Communication interface descriptor */
USBInterfaceDescriptor cdcCommunication0;
/** CDC header functional descriptor. */
CDCHeaderDescriptor cdcHeader0;
/** CDC call management functional descriptor. */
CDCCallManagementDescriptor cdcCallManagement0;
/** CDC abstract control management functional descriptor. */
CDCAbstractControlManagementDescriptor cdcAbstractControlManagement0;
/** CDC union functional descriptor (with one slave interface). */
CDCUnionDescriptor cdcUnion0;
/** Notification endpoint descriptor. */
USBEndpointDescriptor cdcNotification0;
/** Data interface descriptor. */
USBInterfaceDescriptor cdcData0;
/** Data OUT endpoint descriptor. */
USBEndpointDescriptor cdcDataOut0;
/** Data IN endpoint descriptor. */
USBEndpointDescriptor cdcDataIn0;
/* --- AUDIO (AC) */
/** IAD 1*/
USBInterfaceAssociationDescriptor audIAD;
/** Audio control interface.*/
USBInterfaceDescriptor audInterface;
/** Descriptors for the audio control interface.*/
AUDDSpeakerAcDescriptors audControl;
/* -- AUDIO out (AS) */
/** Streaming out interface descriptor (with no endpoint, required).*/
USBInterfaceDescriptor audStreamingOutNoIsochronous;
/** Streaming out interface descriptor.*/
USBInterfaceDescriptor audStreamingOut;
/** Audio class descriptor for the streaming out interface.*/
AUDStreamingInterfaceDescriptor audStreamingOutClass;
/** Stream format descriptor.*/
AUDFormatTypeOneDescriptor1 audStreamingOutFormatType;
/** Streaming out endpoint descriptor.*/
AUDEndpointDescriptor audStreamingOutEndpoint;
/** Audio class descriptor for the streaming out endpoint.*/
AUDDataEndpointDescriptor audStreamingOutDataEndpoint;
} __attribute__ ((__packed__)) CdcAudspkdDriverConfigurationDescriptors;
/**
* Configuration descriptor list for a device implementing
* CDC(Serial) + Audio(SpeakerPhone) composite driver.
*/
typedef struct _CdcAuddDriverConfigurationDescriptors {
/** Standard configuration descriptor. */
USBConfigurationDescriptor configuration;
/* --- CDC 0 */
/** IAD 0 */
USBInterfaceAssociationDescriptor cdcIAD0;
/** Communication interface descriptor */
USBInterfaceDescriptor cdcCommunication0;
/** CDC header functional descriptor. */
CDCHeaderDescriptor cdcHeader0;
/** CDC call management functional descriptor. */
CDCCallManagementDescriptor cdcCallManagement0;
/** CDC abstract control management functional descriptor. */
CDCAbstractControlManagementDescriptor cdcAbstractControlManagement0;
/** CDC union functional descriptor (with one slave interface). */
CDCUnionDescriptor cdcUnion0;
/** Notification endpoint descriptor. */
USBEndpointDescriptor cdcNotification0;
/** Data interface descriptor. */
USBInterfaceDescriptor cdcData0;
/** Data OUT endpoint descriptor. */
USBEndpointDescriptor cdcDataOut0;
/** Data IN endpoint descriptor. */
USBEndpointDescriptor cdcDataIn0;
/* --- AUDIO (AC) */
/** IAD 1*/
USBInterfaceAssociationDescriptor audIAD;
/** Audio control interface.*/
USBInterfaceDescriptor audInterface;
/** Descriptors for the audio control interface.*/
AUDDSpeakerPhoneAcDescriptors audControl;
/* -- AUDIO out (AS) */
/** Streaming out interface descriptor (with no endpoint, required).*/
USBInterfaceDescriptor audStreamingOutNoIsochronous;
/** Streaming out interface descriptor.*/
USBInterfaceDescriptor audStreamingOut;
/** Audio class descriptor for the streaming out interface.*/
AUDStreamingInterfaceDescriptor audStreamingOutClass;
/** Stream format descriptor.*/
AUDFormatTypeOneDescriptor1 audStreamingOutFormatType;
/** Streaming out endpoint descriptor.*/
AUDEndpointDescriptor audStreamingOutEndpoint;
/** Audio class descriptor for the streaming out endpoint.*/
AUDDataEndpointDescriptor audStreamingOutDataEndpoint;
/*- AUDIO IN */
/** Streaming in interface descriptor (with no endpoint, required). */
USBInterfaceDescriptor streamingInNoIsochronous;
/** Streaming in interface descriptor. */
USBInterfaceDescriptor streamingIn;
/** Audio class descriptor for the streaming in interface. */
AUDStreamingInterfaceDescriptor streamingInClass;
/** Stream format descriptor. */
AUDFormatTypeOneDescriptor1 streamingInFormatType;
/** Streaming in endpoint descriptor. */
AUDEndpointDescriptor streamingInEndpoint;
/** Audio class descriptor for the streaming in endpoint. */
AUDDataEndpointDescriptor streamingInDataEndpoint;
} __attribute__ ((__packed__)) CdcAuddDriverConfigurationDescriptors;
#pragma pack()
/*---------------------------------------------------------------------------
* Exported functions
*---------------------------------------------------------------------------*/
extern void CDCAUDDDriver_Initialize(const USBDDriverDescriptors * pDescriptors);
extern void CDCAUDDDriver_ConfigurationChangedHandler(uint8_t cfgnum);
extern void CDCAUDDDriver_InterfaceSettingChangedHandler(
uint8_t interface, uint8_t setting);
extern void CDCAUDDDriver_RequestHandler(const USBGenericRequest *request);
/**@}*/
#endif //#ifndef CDCHIDDDRIVER_H

View File

@ -0,0 +1,106 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
*
* 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 disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
* ----------------------------------------------------------------------------
*/
/**
* \file
*
* Single CDC Serial Port Function for USB device & composite driver.
*/
#ifndef CDCDSERIAL_H
#define CDCDSERIAL_H
/** \addtogroup usbd_cdc
*@{
*/
/*------------------------------------------------------------------------------
* Headers
*------------------------------------------------------------------------------*/
/* These headers were introduced in C99
by working group ISO/IEC JTC1/SC22/WG14. */
#include <stdint.h>
#include <USBRequests.h>
#include <USBDDriver.h>
#include <CDCDSerialPort.h>
/*------------------------------------------------------------------------------
* Definitions
*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------
* Types
*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------
* Exported functions
*------------------------------------------------------------------------------*/
extern void CDCDSerial_Initialize(
USBDDriver * pUsbd, uint8_t bInterfaceNb);
extern uint32_t CDCDSerial_RequestHandler(
const USBGenericRequest *request);
extern void CDCDSerial_ConfigureFunction(
USBGenericDescriptor * pDescriptors, uint16_t wLength);
extern uint32_t CDCDSerial_Write(
void *data,
uint32_t size,
TransferCallback callback,
void *argument);
extern uint32_t CDCDSerial_Read(
void *data,
uint32_t size,
TransferCallback callback,
void *argument);
extern void CDCDSerial_GetLineCoding(CDCLineCoding * pLineCoding);
extern uint8_t CDCDSerial_GetControlLineState(void);
extern uint16_t CDCDSerial_GetSerialState(void);
extern void CDCDSerial_SetSerialState(uint16_t serialState);
extern uint8_t CDCDSerial_LineCodingIsToChange(
CDCLineCoding * pLineCoding);
extern void CDCDSerial_ControlLineStateChanged(
uint8_t DTR,uint8_t RTS);
/**@}*/
#endif /*#ifndef CDCSERIAL_H*/

View File

@ -0,0 +1,249 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
*
* 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 disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
* ----------------------------------------------------------------------------
*/
/**
* \file
*
* \section Purpose
*
* Definition of a class for implementing a USB device CDC serial driver.
*
* \section Usage
*
* -# Re-implement the USBDCallbacks_RequestReceived method to pass
* received requests to CDCDSerialDriver_RequestHandler. *This is
* automatically done unless the NOAUTOCALLBACK symbol is defined*.
* -# Initialize the CDC serial and USB drivers using
* CDCDSerialDriver_Initialize.
* -# Logically connect the device to the host using USBD_Connect.
* -# Send serial data to the USB host using CDCDSerialDriver_Write.
* -# Receive serial data from the USB host using CDCDSerialDriver_Read.
*/
#ifndef CDCDSERIALDRIVER_H
#define CDCDSERIALDRIVER_H
/** \addtogroup usbd_cdc
*@{
*/
/*------------------------------------------------------------------------------
* Headers
*------------------------------------------------------------------------------*/
/* These headers were introduced in C99
by working group ISO/IEC JTC1/SC22/WG14. */
#include <stdint.h>
#include <USBRequests.h>
#include <CDCRequests.h>
#include <CDCDescriptors.h>
#include <CDCNotifications.h>
#include <CDCDSerial.h>
/*------------------------------------------------------------------------------
* Definitions
*------------------------------------------------------------------------------*/
/** \addtogroup usbd_cdc_if USB Device CDC Serial Interface IDs
* @{
*/
/** Communication Class Interface ID */
#define CDCDSerialDriver_CC_INTERFACE 0
/** Data Class Interface ID */
#define CDCDSerialDriver_DC_INTERFACE 1
/** @}*/
/*------------------------------------------------------------------------------
* Types
*------------------------------------------------------------------------------*/
#pragma pack(1)
#if defined ( __CC_ARM ) /* Keil ¦ÌVision 4 */
#elif defined ( __ICCARM__ ) /* IAR Ewarm */
#define __attribute__(...)
#define __packed__ packed
#elif defined ( __GNUC__ ) /* GCC CS3 */
#define __packed__ aligned(1)
#endif
/**
* \typedef CDCDSerialDriverConfigurationDescriptors
* \brief Configuration descriptor list for a device implementing a
* CDC serial driver.
*/
typedef struct _CDCDSerialDriverConfigurationDescriptors {
/** Standard configuration descriptor. */
USBConfigurationDescriptor configuration;
/** Communication interface descriptor. */
USBInterfaceDescriptor communication;
/** CDC header functional descriptor. */
CDCHeaderDescriptor header;
/** CDC call management functional descriptor. */
CDCCallManagementDescriptor callManagement;
/** CDC abstract control management functional descriptor. */
CDCAbstractControlManagementDescriptor abstractControlManagement;
/** CDC union functional descriptor (with one slave interface). */
CDCUnionDescriptor union1;
/** Notification endpoint descriptor. */
USBEndpointDescriptor notification;
/** Data interface descriptor. */
USBInterfaceDescriptor data;
/** Data OUT endpoint descriptor. */
USBEndpointDescriptor dataOut;
/** Data IN endpoint descriptor. */
USBEndpointDescriptor dataIn;
} __attribute__ ((__packed__)) CDCDSerialDriverConfigurationDescriptors;
/**
* \typedef CDCDSerialDriverConfigurationDescriptorsOTG
* \brief Configuration descriptor list for a device implementing a
* CDC serial OTG driver.
*/
typedef struct _CDCDSerialDriverConfigurationDescriptorsOTG {
/** Standard configuration descriptor. */
USBConfigurationDescriptor configuration;
/* OTG descriptor */
USBOtgDescriptor otgDescriptor;
/** Communication interface descriptor. */
USBInterfaceDescriptor communication;
/** CDC header functional descriptor. */
CDCHeaderDescriptor header;
/** CDC call management functional descriptor. */
CDCCallManagementDescriptor callManagement;
/** CDC abstract control management functional descriptor. */
CDCAbstractControlManagementDescriptor abstractControlManagement;
/** CDC union functional descriptor (with one slave interface). */
CDCUnionDescriptor union1;
/** Notification endpoint descriptor. */
USBEndpointDescriptor notification;
/** Data interface descriptor. */
USBInterfaceDescriptor data;
/** Data OUT endpoint descriptor. */
USBEndpointDescriptor dataOut;
/** Data IN endpoint descriptor. */
USBEndpointDescriptor dataIn;
} __attribute__ ((__packed__)) CDCDSerialDriverConfigurationDescriptorsOTG;
#pragma pack()
/*------------------------------------------------------------------------------
* Exported functions
*------------------------------------------------------------------------------*/
extern void CDCDSerialDriver_Initialize(
const USBDDriverDescriptors *pDescriptors);
extern void CDCDSerialDriver_ConfigurationChangedHandler(uint8_t cfgnum);
extern void CDCDSerialDriver_RequestHandler(
const USBGenericRequest *request);
/**
* Sends a data buffer through the virtual COM port created by the CDC
* device serial driver. This function behaves exactly like USBD_Write.
* \param data Pointer to the data buffer to send.
* \param size Size of the data buffer in bytes.
* \param callback Optional callback function to invoke when the transfer
* finishes.
* \param argument Optional argument to the callback function.
* \return USBD_STATUS_SUCCESS if the read operation has been started normally;
* otherwise, the corresponding error code.
*/
static inline uint32_t CDCDSerialDriver_Write(
void *data,
uint32_t size,
TransferCallback callback,
void *argument)
{
return CDCDSerial_Write(data, size, callback, argument);
}
/**
* Receives data from the host through the virtual COM port created by
* the CDC device serial driver. This function behaves like USBD_Read.
* \param data Pointer to the data buffer to put received data.
* \param size Size of the data buffer in bytes.
* \param callback Optional callback function to invoke when the transfer
* finishes.
* \param argument Optional argument to the callback function.
* \return USBD_STATUS_SUCCESS if the read operation has been started normally;
* otherwise, the corresponding error code.
*/
static inline uint32_t CDCDSerialDriver_Read(
void *data,
uint32_t size,
TransferCallback callback,
void *argument)
{
return CDCDSerial_Read(data, size, callback, argument);
}
/**
* Copy current line coding settings to pointered space.
* \param pLineCoding Pointer to CDCLineCoding instance.
*/
static inline void CDCDSerialDriver_GetLineCoding(CDCLineCoding * pLineCoding)
{
CDCDSerial_GetLineCoding(pLineCoding);
}
/**
* Returns the current control line state of the RS-232 line.
*/
static inline uint8_t CDCDSerialDriver_GetControlLineState(void)
{
return CDCDSerial_GetControlLineState();
}
/**
* Returns the current status of the RS-232 line.
*/
static inline uint16_t CDCDSerialDriver_GetSerialState(void)
{
return CDCDSerial_GetSerialState();
}
/**
* Sets the current serial state of the device to the given value.
* \param serialState New device state.
*/
static inline void CDCDSerialDriver_SetSerialState(uint16_t serialState)
{
CDCDSerial_SetSerialState(serialState);
}
/**@}*/
#endif /*#ifndef CDCSERIALDRIVER_H*/

View File

@ -0,0 +1,167 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2010, Atmel Corporation
*
* 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 disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
* ----------------------------------------------------------------------------
*/
/** \file
* Definition of a class for implementing a USB device
* CDC serial port function.
*/
#ifndef _CDCDSERIALPORT_H_
#define _CDCDSERIALPORT_H_
/*------------------------------------------------------------------------------
* Headers
*------------------------------------------------------------------------------*/
/* These headers were introduced in C99
by working group ISO/IEC JTC1/SC22/WG14. */
#include <stdint.h>
#include <USBRequests.h>
#include <CDCRequests.h>
#include <CDCNotifications.h>
#include "USBD.h"
#include <USBDDriver.h>
/** \addtogroup usbd_cdc
*@{
*/
/*------------------------------------------------------------------------------
* Defines
*------------------------------------------------------------------------------*/
/** \addtogroup usbd_cdc_serial_desc USB Device Serial Port Descriptor Values
* @{
*/
/** Default CDC interrupt endpoints max packat size (8). */
#define CDCDSerialPort_INTERRUPT_MAXPACKETSIZE 8
/** Default CDC interrupt endpoint polling rate of High Speed (16ms). */
#define CDCDSerialPort_INTERRUPT_INTERVAL_HS 8
/** Default CDC interrupt endpoint polling rate of Full Speed (16ms). */
#define CDCDSerialPort_INTERRUPT_INTERVAL_FS 16
/** Default CDC bulk endpoints max packat size (512, for HS actually). */
#define CDCDSerialPort_BULK_MAXPACKETSIZE_HS 512
/** Default CDC bulk endpoints max packat size (64, for FS actually). */
#define CDCDSerialPort_BULK_MAXPACKETSIZE_FS 64
/** @}*/
/** \addtogroup usbd_cdc_serial_events USB Device Serial Port Events
* @{
*/
/** SetControlLineState event, value is changed */
#define CDCDSerialPortEvent_SETCONTROLLINESTATE 0
/** SetLineCoding event, value is to changed according to return value */
#define CDCDSerialPortEvent_SETLINECODING 1
/** @}*/
/*------------------------------------------------------------------------------
* Types
*------------------------------------------------------------------------------*/
/** Callback function for serial port events */
typedef uint32_t (*CDCDSerialPortEventHandler)(uint32_t dwEvent,
uint32_t dwParam,
void * pArguments);
/**
* Struct for USB CDC virtual COM serial port function.
*/
typedef struct _CDCDSerialPort {
/** USB Driver for the %device */
USBDDriver *pUsbd;
/** Callback for serial port events */
CDCDSerialPortEventHandler fEventHandler;
/** Callback arguments */
void *pArg;
/** USB starting interface index */
uint8_t bInterfaceNdx;
/** USB number of interfaces */
uint8_t bNumInterface;
/** USB interrupt IN endpoint address */
uint8_t bIntInPIPE;
/** USB bulk IN endpoint address */
uint8_t bBulkInPIPE;
/** USB bulk OUT endpoint address */
uint8_t bBulkOutPIPE;
/** Serial port ControlLineState */
uint8_t bControlLineState;
/** Serial port SerialState */
uint16_t wSerialState;
/** Serial port linecoding */
CDCLineCoding lineCoding;
uint8_t bReserved;
} CDCDSerialPort;
/*------------------------------------------------------------------------------
* Functions
*------------------------------------------------------------------------------*/
extern void CDCDSerialPort_Initialize(CDCDSerialPort *pCdcd,
USBDDriver *pUsbd,
CDCDSerialPortEventHandler fCallback,
void *pArg,
uint8_t firstInterface,
uint8_t numInterface);
extern USBGenericDescriptor * CDCDSerialPort_ParseInterfaces(
CDCDSerialPort * pCdcd,
USBGenericDescriptor * pDescriptors, uint32_t dwLength);
extern uint32_t CDCDSerialPort_RequestHandler(
CDCDSerialPort *pCdcd,
const USBGenericRequest *pRequest);
extern uint32_t CDCDSerialPort_Write(
const CDCDSerialPort *pCdcd,
void *pData, uint32_t dwSize,
TransferCallback fCallback, void* pArg);
extern uint32_t CDCDSerialPort_Read(
const CDCDSerialPort *pCdcd,
void *pData, uint32_t dwSize,
TransferCallback fCallback, void* pArg);
extern uint16_t CDCDSerialPort_GetSerialState(
const CDCDSerialPort *pCdcd);
extern void CDCDSerialPort_SetSerialState(
CDCDSerialPort *pCdcd,
uint16_t wSerialState);
extern uint8_t CDCDSerialPort_GetControlLineState(
const CDCDSerialPort * pCdcd);
extern void CDCDSerialPort_GetLineCoding(
const CDCDSerialPort * pCdcd,
CDCLineCoding * pLineCoding);
/**@}*/
#endif /* #ifndef _CDCDSERIALPORT_H_ */

View File

@ -0,0 +1,275 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2010, Atmel Corporation
*
* 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 disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
* ----------------------------------------------------------------------------
*/
/** \file
*
* Definitions and classes for USB CDC class descriptors.
*/
#ifndef _CDCDESCRIPTORS_H_
#define _CDCDESCRIPTORS_H_
/** \addtogroup usb_cdc
*@{
*/
/*----------------------------------------------------------------------------
* Includes
*----------------------------------------------------------------------------*/
#include <stdint.h>
/*----------------------------------------------------------------------------
* Definitions
*----------------------------------------------------------------------------*/
/** \addtogroup usb_cdc_ver USB CDC Specification Release Numbers
* @{
* This section list the CDC Spec. Release Numbers.
* - \ref CDCGenericDescriptor_CDC1_10
*/
/** Identify CDC specification version 1.10. */
#define CDCGenericDescriptor_CDC1_10 0x0110
/** @}*/
/** \addtogroup usb_cdc_desc_type CDC Descriptro Types
* @{
* This section lists CDC descriptor types.
* - \ref CDCGenericDescriptor_INTERFACE
* - \ref CDCGenericDescriptor_ENDPOINT
*/
/**Indicates that a CDC descriptor applies to an interface. */
#define CDCGenericDescriptor_INTERFACE 0x24
/** Indicates that a CDC descriptor applies to an endpoint. */
#define CDCGenericDescriptor_ENDPOINT 0x25
/** @}*/
/** \addtogroup usb_cdc_desc_subtype CDC Descriptor Subtypes
* @{
* This section lists CDC descriptor sub types
* - \ref CDCGenericDescriptor_HEADER
* - \ref CDCGenericDescriptor_CALLMANAGEMENT
* - \ref CDCGenericDescriptor_ABSTRACTCONTROLMANAGEMENT
* - \ref CDCGenericDescriptor_UNION
*/
/** Header functional descriptor subtype. */
#define CDCGenericDescriptor_HEADER 0x00
/** Call management functional descriptor subtype. */
#define CDCGenericDescriptor_CALLMANAGEMENT 0x01
/** Abstract control management descriptor subtype. */
#define CDCGenericDescriptor_ABSTRACTCONTROLMANAGEMENT 0x02
/** Union descriptor subtype. */
#define CDCGenericDescriptor_UNION 0x06
/** @}*/
/** \addtogroup usb_cdc_descriptor USB CDC Device Descriptor Values
* @{
* This section lists the values for CDC Device Descriptor.
* - \ref CDCDeviceDescriptor_CLASS
* - \ref CDCDeviceDescriptor_SUBCLASS
* - \ref CDCDeviceDescriptor_PROTOCOL
*/
/** Device class code when using the CDC class. */
#define CDCDeviceDescriptor_CLASS 0x02
/** Device subclass code when using the CDC class. */
#define CDCDeviceDescriptor_SUBCLASS 0x00
/** Device protocol code when using the CDC class. */
#define CDCDeviceDescriptor_PROTOCOL 0x00
/** @}*/
/** \addtogroup usb_cdc_if_desc USB CDC Communication Interface Descriptor
* @{
* This section lists the values for CDC Communication Interface Descriptor.
* - \ref CDCCommunicationInterfaceDescriptor_CLASS
* - \ref CDCCommunicationInterfaceDescriptor_ABSTRACTCONTROLMODEL
* - \ref CDCCommunicationInterfaceDescriptor_NOPROTOCOL
*/
/** Interface class code for a CDC communication class interface. */
#define CDCCommunicationInterfaceDescriptor_CLASS 0x02
/** Interface subclass code for an Abstract Control Model interface descriptor.
*/
#define CDCCommunicationInterfaceDescriptor_ABSTRACTCONTROLMODEL 0x02
/** Interface protocol code when a CDC communication interface does not
implemenent any particular protocol. */
#define CDCCommunicationInterfaceDescriptor_NOPROTOCOL 0x00
/** @}*/
/** \addtogroup usb_cdc_data_if USB CDC Data Interface Values
* @{
* This section lists the values for CDC Data Interface Descriptor.
* - \ref CDCDataInterfaceDescriptor_CLASS
* - \ref CDCDataInterfaceDescriptor_SUBCLASS
* - \ref CDCDataInterfaceDescriptor_NOPROTOCOL
*/
/** Interface class code for a data class interface. */
#define CDCDataInterfaceDescriptor_CLASS 0x0A
/** Interface subclass code for a data class interface. */
#define CDCDataInterfaceDescriptor_SUBCLASS 0x00
/** Protocol code for a data class interface which does not implement any
particular protocol. */
#define CDCDataInterfaceDescriptor_NOPROTOCOL 0x00
/** @}*/
/** \addtogroup usb_cdc_cb_man_desc USB CDC CallManagement Capabilities
* @{
* This section lists CDC CallManagement Capabilities.
* - \ref CDCCallManagementDescriptor_SELFCALLMANAGEMENT
* - \ref CDCCallManagementDescriptor_DATACALLMANAGEMENT
*/
/** Device handles call management itself. */
#define CDCCallManagementDescriptor_SELFCALLMANAGEMENT (1 << 0)
/** Device can exchange call management information over a Data class interface.
*/
#define CDCCallManagementDescriptor_DATACALLMANAGEMENT (1 << 1)
/** @}*/
/** \addtogroup usb_cdc_acm USB CDC ACM Capabilities
* @{
*
* This section lists the capabilities of the CDC ACM.
* - \ref CDCAbstractControlManagementDescriptor_COMMFEATURE
* - \ref CDCAbstractControlManagementDescriptor_LINE
* - \ref CDCAbstractControlManagementDescriptor_SENDBREAK
* - \ref CDCAbstractControlManagementDescriptor_NETWORKCONNECTION
*/
/** Device supports the request combination of SetCommFeature, ClearCommFeature
and GetCommFeature. */
#define CDCAbstractControlManagementDescriptor_COMMFEATURE (1 << 0)
/** Device supports the request combination of SetLineCoding, GetLineCoding and
SetControlLineState. */
#define CDCAbstractControlManagementDescriptor_LINE (1 << 1)
/** Device supports the SendBreak request. */
#define CDCAbstractControlManagementDescriptor_SENDBREAK (1 << 2)
/** Device supports the NetworkConnection notification. */
#define CDCAbstractControlManagementDescriptor_NETWORKCONNECTION (1 << 3)
/** @}*/
/*----------------------------------------------------------------------------
* Types
*----------------------------------------------------------------------------*/
#pragma pack(1)
#if defined ( __CC_ARM ) /* Keil ¦ÌVision 4 */
#elif defined ( __ICCARM__ ) /* IAR Ewarm */
#define __attribute__(...)
#define __packed__ packed
#elif defined ( __GNUC__ ) /* GCC CS3 */
#define __packed__ aligned(1)
#endif
/**
* \typedef CDCHeaderDescriptor
* \brief Marks the beginning of the concatenated set of functional descriptors
* for the interface.
*/
typedef struct _CDCHeaderDescriptor {
/** Size of this descriptor in bytes. */
uint8_t bFunctionLength;
/** Descriptor type . */
uint8_t bDescriptorType;
/** Descriptor sub-type . */
uint8_t bDescriptorSubtype;
/** USB CDC specification release number. */
uint16_t bcdCDC;
} __attribute__ ((__packed__)) CDCHeaderDescriptor; /* GCC */
/**
* \typedef CDCUnionDescriptor
* \brief Describes the relationship between a group of interfaces that can
* be considered to form a functional unit.
*/
typedef struct _CDCUnionDescriptor {
/** Size of the descriptor in bytes. */
uint8_t bFunctionLength;
/** Descriptor type . */
uint8_t bDescriptorType;
/** Descriptor subtype . */
uint8_t bDescriptorSubtype;
/** Number of the master interface for this union. */
uint8_t bMasterInterface;
/** Number of the first slave interface for this union. */
uint8_t bSlaveInterface0;
} __attribute__ ((__packed__)) CDCUnionDescriptor; /* GCC */
/**
* \typedef CDCCallManagementDescriptor
* \brief Describes the processing of calls for the communication class
* interface.
*/
typedef struct _CDCCallManagementDescriptor {
/** Size of this descriptor in bytes. */
uint8_t bFunctionLength;
/** Descriptor type . */
uint8_t bDescriptorType;
/** Descriptor sub-type . */
uint8_t bDescriptorSubtype;
/** Configuration capabilities
\sa usb_cdc_cb_man_desc CDC CallManagement Capabilities. */
uint8_t bmCapabilities;
/** Interface number of the data class interface used for call management
(optional). */
uint8_t bDataInterface;
} __attribute__ ((__packed__)) CDCCallManagementDescriptor; /* GCC */
/**
* \typedef CDCAbstractControlManagementDescriptor
* \brief Describes the command supported by the communication interface class
* with the Abstract Control Model subclass code.
*/
typedef struct _CDCAbstractControlManagementDescriptor {
/** Size of this descriptor in bytes. */
uint8_t bFunctionLength;
/** Descriptor type . */
uint8_t bDescriptorType;
/** Descriptor subtype . */
uint8_t bDescriptorSubtype;
/** Configuration capabilities.
\sa usb_cdc_acm CDC ACM Capabilities. */
uint8_t bmCapabilities;
} __attribute__ ((__packed__)) CDCAbstractControlManagementDescriptor; /* GCC */
#pragma pack()
/*----------------------------------------------------------------------------
* Functions
*----------------------------------------------------------------------------*/
/**@}*/
#endif /* #ifndef _CDCDESCRIPTORS_H_ */

View File

@ -0,0 +1,152 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
*
* 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 disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
* ----------------------------------------------------------------------------
*/
/**
* \file
*
* \section Purpose
*
* Definitions and methods for USB composite device implement.
*
* \section Usage
*
* -# Initialize USB function specified driver ( for MSD currently )
* - MSDDFunctionDriver_Initialize()
*
* -# Initialize USB composite driver and USB driver
* - CDCHIDDDriver_Initialize()
*
* -# Handle and dispach USB requests
* - CDCHIDDDriver_RequestHandler()
*
* -# Try starting a remote wake-up sequence
* - CDCHIDDDriver_RemoteWakeUp()
*/
#ifndef CDCHIDDDRIVER_H
#define CDCHIDDDRIVER_H
/** \addtogroup usbd_composite_cdchid
*@{
*/
/*---------------------------------------------------------------------------
* Headers
*---------------------------------------------------------------------------*/
#include <USBRequests.h>
#include <CDCDescriptors.h>
#include <HIDDescriptors.h>
#include "USBD.h"
#include <USBDDriver.h>
/*---------------------------------------------------------------------------
* Definitions
*---------------------------------------------------------------------------*/
/** \addtogroup usbd_cdc_hid_desc USB CDC(Serial) + HID(Kbd) Descriptors define
* @{
*/
/** Number of interfaces of the device */
#define CDCHIDDDriverDescriptors_NUMINTERFACE 3
/** Number of the CDC interface. */
#define CDCHIDDDriverDescriptors_CDC_INTERFACE 0
/** Number of the HID interface. */
#define CDCHIDDDriverDescriptors_HID_INTERFACE 2
/** @}*/
/*---------------------------------------------------------------------------
* Types
*---------------------------------------------------------------------------*/
#pragma pack(1)
#if defined ( __CC_ARM ) /* Keil ¦ÌVision 4 */
#elif defined ( __ICCARM__ ) /* IAR Ewarm */
#define __attribute__(...)
#define __packed__ packed
#elif defined ( __GNUC__ ) /* GCC CS3 */
#define __packed__ aligned(1)
#endif
/**
* \typedef CdcHidDriverConfigurationDescriptors
* \brief Configuration descriptor list for a device implementing a
* composite driver.
*/
typedef struct _CdcHidDriverConfigurationDescriptors {
/** Standard configuration descriptor. */
USBConfigurationDescriptor configuration;
/* --- CDC 0 */
/** IAD 0 */
USBInterfaceAssociationDescriptor cdcIAD0;
/** Communication interface descriptor */
USBInterfaceDescriptor cdcCommunication0;
/** CDC header functional descriptor. */
CDCHeaderDescriptor cdcHeader0;
/** CDC call management functional descriptor. */
CDCCallManagementDescriptor cdcCallManagement0;
/** CDC abstract control management functional descriptor. */
CDCAbstractControlManagementDescriptor cdcAbstractControlManagement0;
/** CDC union functional descriptor (with one slave interface). */
CDCUnionDescriptor cdcUnion0;
/** Notification endpoint descriptor. */
USBEndpointDescriptor cdcNotification0;
/** Data interface descriptor. */
USBInterfaceDescriptor cdcData0;
/** Data OUT endpoint descriptor. */
USBEndpointDescriptor cdcDataOut0;
/** Data IN endpoint descriptor. */
USBEndpointDescriptor cdcDataIn0;
/* --- HID */
USBInterfaceDescriptor hidInterface;
HIDDescriptor1 hid;
USBEndpointDescriptor hidInterruptIn;
USBEndpointDescriptor hidInterruptOut;
} __attribute__ ((__packed__)) CdcHidDriverConfigurationDescriptors;
#pragma pack()
/*---------------------------------------------------------------------------
* Exported functions
*---------------------------------------------------------------------------*/
/* -CDCHID */
extern void CDCHIDDDriver_Initialize(
const USBDDriverDescriptors * pDescriptors);
extern void CDCHIDDDriver_ConfigurationChangedHandler(uint8_t cfgnum);
extern void CDCHIDDDriver_RequestHandler(const USBGenericRequest *request);
extern void CDCHIDDDriver_RemoteWakeUp(void);
/**@}*/
#endif //#ifndef CDCHIDDDRIVER_H

View File

@ -0,0 +1,155 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
*
* 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 disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
* ----------------------------------------------------------------------------
*/
/**
* \file
*
* \section Purpose
*
* Definitions and methods for USB CDCMSD device implement.
*
* \section Usage
*
* -# Initialize USB function specified driver ( for MSD currently )
* - MSDDFunctionDriver_Initialize
*
* -# Initialize USB CDCMSD driver and USB driver
* - CDCMSDDDriver_Initialize
*
* -# Handle and dispach USB requests
* - CDCMSDDDriver_RequestHandler
*
* -# Try starting a remote wake-up sequence
* - CDCMSDDDriver_RemoteWakeUp
*/
#ifndef CDCMSDDDRIVER_H
#define CDCMSDDDRIVER_H
/** \addtogroup usbd_composite_cdcmsd
*@{
*/
/*---------------------------------------------------------------------------
* Headers
*---------------------------------------------------------------------------*/
#include <USBRequests.h>
#include <CDCDescriptors.h>
#include <MSDescriptors.h>
#include <MSDLun.h>
#include "USBD.h"
#include <USBDDriver.h>
/*---------------------------------------------------------------------------
* Consts
*---------------------------------------------------------------------------*/
/** \addtogroup usbd_cdc_msd_desc USB CDC(Serial) + MS Descriptors define
* @{
*/
/** Number of interfaces of the device */
#define CDCMSDDriverDescriptors_NUMINTERFACE 3
/** Number of the CDC interface. */
#define CDCMSDDriverDescriptors_CDC_INTERFACE 0
/** Number of the HID interface. */
#define CDCMSDDriverDescriptors_MSD_INTERFACE 2
/** @}*/
/*---------------------------------------------------------------------------
* Types
*---------------------------------------------------------------------------*/
#pragma pack(1)
#if defined ( __CC_ARM ) /* Keil ¦ÌVision 4 */
#elif defined ( __ICCARM__ ) /* IAR Ewarm */
#define __attribute__(...)
#define __packed__ packed
#elif defined ( __GNUC__ ) /* GCC CS3 */
#define __packed__ aligned(1)
#endif
/**
* \typedef CDCMSDDriverConfigurationDescriptors
* \brief Configuration descriptor list for a device implementing
* a CDCMSD driver.
*/
typedef struct _CDCMSDDriverConfigurationDescriptors {
/** Standard configuration descriptor. */
USBConfigurationDescriptor configuration;
/* --- CDC 0 */
/** IAD 0 */
USBInterfaceAssociationDescriptor cdcIAD0;
/** Communication interface descriptor */
USBInterfaceDescriptor cdcCommunication0;
/** CDC header functional descriptor. */
CDCHeaderDescriptor cdcHeader0;
/** CDC call management functional descriptor. */
CDCCallManagementDescriptor cdcCallManagement0;
/** CDC abstract control management functional descriptor. */
CDCAbstractControlManagementDescriptor cdcAbstractControlManagement0;
/** CDC union functional descriptor (with one slave interface). */
CDCUnionDescriptor cdcUnion0;
/** Notification endpoint descriptor. */
USBEndpointDescriptor cdcNotification0;
/** Data interface descriptor. */
USBInterfaceDescriptor cdcData0;
/** Data OUT endpoint descriptor. */
USBEndpointDescriptor cdcDataOut0;
/** Data IN endpoint descriptor. */
USBEndpointDescriptor cdcDataIn0;
/* --- MSD */
/** Mass storage interface descriptor. */
USBInterfaceDescriptor msdInterface;
/** Bulk-out endpoint descriptor. */
USBEndpointDescriptor msdBulkOut;
/** Bulk-in endpoint descriptor. */
USBEndpointDescriptor msdBulkIn;
} __attribute__ ((__packed__)) CDCMSDDriverConfigurationDescriptors;
#pragma pack()
/*---------------------------------------------------------------------------
* Exported functions
*---------------------------------------------------------------------------*/
/* -CDCMSD */
extern void CDCMSDDriver_Initialize(
const USBDDriverDescriptors *pDescriptors,
MSDLun *pLuns, unsigned char numLuns);
extern void CDCMSDDriver_ConfigurationChangedHandler(unsigned char cfgnum);
extern void CDCMSDDriver_RequestHandler(const USBGenericRequest *request);
/**@}*/
#endif /* #ifndef CDCMSDDDRIVER_H */

View File

@ -0,0 +1,111 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2010, Atmel Corporation
*
* 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 disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
* ----------------------------------------------------------------------------
*/
/** \file
* Definitions and methods for USB CDC Notifications.
*/
#ifndef _CDCNOTIFICATIONS_H_
#define _CDCNOTIFICATIONS_H_
/** \addtogroup usb_cdc
*@{
*/
/*----------------------------------------------------------------------------
* Includes
*----------------------------------------------------------------------------*/
#include <stdint.h>
/*----------------------------------------------------------------------------
* Definitions
*----------------------------------------------------------------------------*/
/** \addtogroup cdc_serial_states CDC SerialState bits
* @{
* This page lists the bit map for CDC Serial States.
*
* - \ref CDCSerialState_RXDRIVER
* - \ref CDCSerialState_TXCARRIER
* - \ref CDCSerialState_BREAK
* - \ref CDCSerialState_RINGSIGNAL
* - \ref CDCSerialState_FRAMING
* - \ref CDCSerialState_PARITY
* - \ref CDCSerialState_OVERRUN
*/
/** Indicates the receiver carrier signal is present */
#define CDCSerialState_RXDRIVER (1 << 0)
/** Indicates the transmission carrier signal is present */
#define CDCSerialState_TXCARRIER (1 << 1)
/** Indicates a break has been detected */
#define CDCSerialState_BREAK (1 << 2)
/** Indicates a ring signal has been detected */
#define CDCSerialState_RINGSIGNAL (1 << 3)
/** Indicates a framing error has occured */
#define CDCSerialState_FRAMING (1 << 4)
/** Indicates a parity error has occured */
#define CDCSerialState_PARITY (1 << 5)
/** Indicates a data overrun error has occured */
#define CDCSerialState_OVERRUN (1 << 6)
/** @}*/
/*----------------------------------------------------------------------------
* Types
*----------------------------------------------------------------------------*/
#pragma pack(1)
#if defined ( __CC_ARM ) /* Keil ¦ÌVision 4 */
#elif defined ( __ICCARM__ ) /* IAR Ewarm */
#define __attribute__(...)
#define __packed__ packed
#elif defined ( __GNUC__ ) /* GCC CS3 */
#define __packed__ aligned(1)
#endif
/** USB CDC SerialState struct (bitmap) */
typedef struct _CDCSerialState {
uint16_t bRxCarrier:1, /**< State of receive carrier detection (V2.4 signal
109 and RS-232 signal DCD) */
bTxCarrier:1, /**< State of transmission carrier */
bBreak:1, /**< State of break detection */
bRingSignal:1, /**< State of ring signal */
bFraming:1, /**< Framing error */
bParity:1, /**< Parity error */
bOverRun:1, /**< Received data discarded due to overrun error */
reserved:9; /**< Reserved */
} __attribute__ ((__packed__)) CDCSerialState;
#pragma pack()
/*----------------------------------------------------------------------------
* Functions
*----------------------------------------------------------------------------*/
/**@}*/
#endif /* #ifndef _CDCNOTIFICATIONS_H_ */

View File

@ -0,0 +1,183 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2010, Atmel Corporation
*
* 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 disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
* ----------------------------------------------------------------------------
*/
/** \file
*
* Definitions and classes for USB CDC class requests
* (mostly for ACM).
*
* \section CDCLineCoding
*
* -# Initialize a CDCLineCoding instance using CDCLineCoding_Initialize.
* -# Send a CDCLineCoding object to the host in response to a GetLineCoding
* request.
* -# Receive a CDCLineCoding object from the host after a SetLineCoding
* request.
*
*/
#ifndef _CDCREQUESTS_H_
#define _CDCREQUESTS_H_
/** \addtogroup usb_cdc
*@{
*/
/*----------------------------------------------------------------------------
* Includes
*----------------------------------------------------------------------------*/
#include <stdint.h>
#include <USBRequests.h>
/*----------------------------------------------------------------------------
* Definitions
*----------------------------------------------------------------------------*/
/** \addtogroup usb_cdc_request USB CDC Request Codes
* @{
* This section lists USB CDC Request Codes.
* - \ref CDCGenericRequest_SETLINECODING
* - \ref CDCGenericRequest_GETLINECODING
* - \ref CDCGenericRequest_SETCONTROLLINESTATE
*/
/** SetLineCoding request code. */
#define CDCGenericRequest_SETLINECODING 0x20
/** GetLineCoding request code. */
#define CDCGenericRequest_GETLINECODING 0x21
/** SetControlLineState request code. */
#define CDCGenericRequest_SETCONTROLLINESTATE 0x22
/** @}*/
/** \addtogroup usb_cdc_ctrl_line_state USB CDC ControlLineState bitmap
* @{
* This section lists CDC ControlLineState bitmap.
* - \ref CDCControlLineState_DTR, CDCControlLineState_DTE_PRESENT
* - \ref CDCControlLineState_RTS, CDCControlLineState_CARRIER_ON
*/
/** Indicates to DCE if DTE is present or not. */
#define CDCControlLineState_DTE_PRESENT (1 << 0)
/** RS232 signal DTR: Data Terminal Ready. */
#define CDCControlLineState_DTR (1 << 0)
/** Carrier control for half duplex modems. */
#define CDCControlLineState_CARRIER_ON (1 << 1)
/** RS232 signal RTS: Request to send. */
#define CDCControlLineState_RTS (1 << 1)
/** @}*/
/** \addtogroup usb_cdc_stop USB CDC LineCoding StopBits
* @{
* This section lists Stop Bits for CDC Line Coding.
* - \ref CDCLineCoding_ONESTOPBIT
* - \ref CDCLineCoding_ONE5STOPBIT
* - \ref CDCLineCoding_TWOSTOPBITS
*/
/** The transmission protocol uses one stop bit. */
#define CDCLineCoding_ONESTOPBIT 0
/** The transmission protocol uses 1.5 stop bit. */
#define CDCLineCoding_ONE5STOPBIT 1
/** The transmissin protocol uses two stop bits. */
#define CDCLineCoding_TWOSTOPBITS 2
/** @}*/
/** \addtogroup usb_cdc_parity USB CDC LineCoding ParityCheckings
* @{
* This section lists Parity checkings for CDC Line Coding.
* - \ref CDCLineCoding_NOPARITY
* - \ref CDCLineCoding_ODDPARITY
* - \ref CDCLineCoding_EVENPARITY
* - \ref CDCLineCoding_MARKPARITY
* - \ref CDCLineCoding_SPACEPARITY
*/
/** No parity checking. */
#define CDCLineCoding_NOPARITY 0
/** Odd parity checking. */
#define CDCLineCoding_ODDPARITY 1
/** Even parity checking. */
#define CDCLineCoding_EVENPARITY 2
/** Mark parity checking. */
#define CDCLineCoding_MARKPARITY 3
/** Space parity checking. */
#define CDCLineCoding_SPACEPARITY 4
/** @}*/
/*----------------------------------------------------------------------------
* Types
*----------------------------------------------------------------------------*/
#pragma pack(1)
#if defined ( __CC_ARM ) /* Keil ¦ÌVision 4 */
#elif defined ( __ICCARM__ ) /* IAR Ewarm */
#define __attribute__(...)
#define __packed__ packed
#elif defined ( __GNUC__ ) /* GCC CS3 */
#define __packed__ aligned(1)
#endif
/**
* \typedef CDCLineCoding
* \brief Format of the data returned when a GetLineCoding request is received.
*/
typedef struct _CDCLineCoding {
/** Data terminal rate in bits per second. */
uint32_t dwDTERate;
/** Number of stop bits.
\sa usb_cdc_stop CDC LineCoding StopBits. */
uint8_t bCharFormat;
/** Type of parity checking used.
\sa usb_cdc_parity CDC LineCoding ParityCheckings. */
uint8_t bParityType;
/** Number of data bits (5, 6, 7, 8 or 16). */
uint8_t bDataBits;
} __attribute__ ((__packed__)) CDCLineCoding; /* GCC */
#pragma pack()
/*----------------------------------------------------------------------------
* Functions
*----------------------------------------------------------------------------*/
extern uint8_t CDCSetControlLineStateRequest_IsDtePresent(
const USBGenericRequest *request);
extern uint8_t CDCSetControlLineStateRequest_ActivateCarrier(
const USBGenericRequest *request);
extern void CDCLineCoding_Initialize(CDCLineCoding *lineCoding,
uint32_t bitrate,
uint8_t stopbits,
uint8_t parity,
uint8_t databits);
/**@}*/
#endif /* #define _CDCREQUESTS_H_ */

View File

@ -0,0 +1,157 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
*
* 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 disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
* ----------------------------------------------------------------------------
*/
/**
* \file
*
* \section Purpose
*
* Definitions and methods for USB composite device implement.
*
*/
#ifndef DUALCDCDDRIVER_H
#define DUALCDCDDRIVER_H
/** \addtogroup usbd_composite_cdccdc
*@{
*/
/*---------------------------------------------------------------------------
* Headers
*---------------------------------------------------------------------------*/
#include <USBRequests.h>
#include <CDCDescriptors.h>
#include "USBD.h"
#include <CDCDSerialPort.h>
/*---------------------------------------------------------------------------
* Defines
*---------------------------------------------------------------------------*/
/** \addtogroup usbd_composite_cdccdc_desc
* The driver uses these interface numbers in configuration descriptor.
* @{
*/
/** Number of interfaces of the device */
#define DUALCDCDDriverDescriptors_NUMINTERFACE 4
/** Number of the CDC0 interface. */
#define DUALCDCDDriverDescriptors_INTERFACENUM0 0
/** Number of the CDC1 interface. */
#define DUALCDCDDriverDescriptors_INTERFACENUM1 2
/** @}*/
/*---------------------------------------------------------------------------
* Types
*---------------------------------------------------------------------------*/
#pragma pack(1)
#if defined ( __CC_ARM ) /* Keil ¦ÌVision 4 */
#elif defined ( __ICCARM__ ) /* IAR Ewarm */
#define __attribute__(...)
#define __packed__ packed
#elif defined ( __GNUC__ ) /* GCC CS3 */
#define __packed__ aligned(1)
#endif
/**
* \typedef DualCdcDriverConfigurationDescriptors
* \brief Configuration descriptor list for a device implementing a
* dual CDC serial composite driver.
*/
typedef struct _DualCdcDriverConfigurationDescriptors {
/** Standard configuration descriptor. */
USBConfigurationDescriptor configuration;
/* --- CDC 0 */
/** IAD 0 */
USBInterfaceAssociationDescriptor cdcIAD0;
/** Communication interface descriptor */
USBInterfaceDescriptor cdcCommunication0;
/** CDC header functional descriptor. */
CDCHeaderDescriptor cdcHeader0;
/** CDC call management functional descriptor. */
CDCCallManagementDescriptor cdcCallManagement0;
/** CDC abstract control management functional descriptor. */
CDCAbstractControlManagementDescriptor cdcAbstractControlManagement0;
/** CDC union functional descriptor (with one slave interface). */
CDCUnionDescriptor cdcUnion0;
/** Notification endpoint descriptor. */
USBEndpointDescriptor cdcNotification0;
/** Data interface descriptor. */
USBInterfaceDescriptor cdcData0;
/** Data OUT endpoint descriptor. */
USBEndpointDescriptor cdcDataOut0;
/** Data IN endpoint descriptor. */
USBEndpointDescriptor cdcDataIn0;
/* --- CDC 1 */
/** IAD 1 */
USBInterfaceAssociationDescriptor cdcIAD1;
/** Communication interface descriptor */
USBInterfaceDescriptor cdcCommunication1;
/** CDC header functional descriptor. */
CDCHeaderDescriptor cdcHeader1;
/** CDC call management functional descriptor. */
CDCCallManagementDescriptor cdcCallManagement1;
/** CDC abstract control management functional descriptor. */
CDCAbstractControlManagementDescriptor cdcAbstractControlManagement1;
/** CDC union functional descriptor (with one slave interface). */
CDCUnionDescriptor cdcUnion1;
/** Notification endpoint descriptor. */
USBEndpointDescriptor cdcNotification1;
/** Data interface descriptor. */
USBInterfaceDescriptor cdcData1;
/** Data OUT endpoint descriptor. */
USBEndpointDescriptor cdcDataOut1;
/** Data IN endpoint descriptor. */
USBEndpointDescriptor cdcDataIn1;
} __attribute__ ((__packed__)) DualCdcDriverConfigurationDescriptors;
#pragma pack()
/*---------------------------------------------------------------------------
* Exported functions
*---------------------------------------------------------------------------*/
/* -DUALCDC */
extern void DUALCDCDDriver_Initialize(
const USBDDriverDescriptors* pDescriptors);
extern void DUALCDCDDriver_ConfigurationChangeHandler(uint8_t cfgnum);
extern void DUALCDCDDriver_RequestHandler(const USBGenericRequest *request);
extern CDCDSerialPort* DUALCDCDDriver_GetSerialPort(uint32_t port);
/**@}*/
#endif /* #ifndef DUALCDCDDRIVER_H */

View File

@ -0,0 +1,678 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
*
* 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 disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
* ----------------------------------------------------------------------------
*/
/** \file
* \section Purpose
*
* SCSI definitions.
*
* \section Usage
*
* -# After command block received, Access and decode the SCSI command block
* with SBCCommand structure.
*/
#ifndef SBC_H
#define SBC_H
/** \addtogroup usbd_msd
*@{
*/
/*------------------------------------------------------------------------------
* Definitions
*------------------------------------------------------------------------------*/
/** \addtogroup usbd_sbc_operation_codes SBC Operation Codes
* @{
* This page lists operation codes of commands described in the SBC-3
* standard.
*
* \note That most commands are actually defined in other standards,
* like SPC-4. Optional commands are not included here.
*
* \see sbc3r07.pdf - Section 5.1 - Table 12
* \see spc4r06.pdf
* \see SBCCommand
*
* \section Codes
* - SBC_INQUIRY
* - SBC_READ_10
* - SBC_READ_CAPACITY_10
* - SBC_REQUEST_SENSE
* - SBC_TEST_UNIT_READY
* - SBC_WRITE_10
*
* \section Optional Codes but required by Windows
* - SBC_PREVENT_ALLOW_MEDIUM_REMOVAL
* - SBC_MODE_SENSE_6
* - SBC_VERIFY_10
* - SBC_READ_FORMAT_CAPACITIES
*/
/** Request information regarding parameters of the target and Logical Unit. */
#define SBC_INQUIRY 0x12
/** Request the transfer data to the host. */
#define SBC_READ_10 0x28
/** Request capacities of the currently installed medium. */
#define SBC_READ_CAPACITY_10 0x25
/** Request that the device server transfer sense data. */
#define SBC_REQUEST_SENSE 0x03
/** Check if the LUN is ready */
#define SBC_TEST_UNIT_READY 0x00
/** Request that the device write the data transferred by the host. */
#define SBC_WRITE_10 0x2A
/** Request that the target enable or disable the removal of the medium in */
/** the Logical Unit. */
#define SBC_PREVENT_ALLOW_MEDIUM_REMOVAL 0x1E
/** Report parameters. */
#define SBC_MODE_SENSE_6 0x1A
/** Request that the %device verify the data on the medium. */
#define SBC_VERIFY_10 0x2F
/** Request a list of the possible capacities that can be formatted on medium */
#define SBC_READ_FORMAT_CAPACITIES 0x23
/** @}*/
/** \addtogroup usbd_sbc_periph_quali SBC Periph. Qualifiers
* @{
* This page lists the peripheral qualifier values specified in the INQUIRY
* data
* \see spc4r06.pdf - Section 6.4.2 - Table 83
* \see SBCInquiryData
*
* \section Qualifiers
* - SBC_PERIPHERAL_DEVICE_CONNECTED
* - SBC_PERIPHERAL_DEVICE_NOT_CONNECTED
* - SBC_PERIPHERAL_DEVICE_NOT_SUPPORTED
*/
#define SBC_PERIPHERAL_DEVICE_CONNECTED 0x00
#define SBC_PERIPHERAL_DEVICE_NOT_CONNECTED 0x01
#define SBC_PERIPHERAL_DEVICE_NOT_SUPPORTED 0x03
/** @}*/
/** \addtogroup usbd_sbc_periph_types SBC Periph. Types
* @{
* This page lists peripheral device types specified in the INQUIRY data
* \see spc4r06.pdf - Section 6.4.2 - Table 84
* \see SBCInquiryData
*
* \section Types
* - SBC_DIRECT_ACCESS_BLOCK_DEVICE
* - SBC_SEQUENTIAL_ACCESS_DEVICE
* - SBC_PRINTER_DEVICE
* - SBC_PROCESSOR_DEVICE
* - SBC_WRITE_ONCE_DEVICE
* - SBC_CD_DVD_DEVICE
* - SBC_SCANNER_DEVICE
* - SBC_OPTICAL_MEMORY_DEVICE
* - SBC_MEDIA_CHANGER_DEVICE
* - SBC_COMMUNICATION_DEVICE
* - SBC_STORAGE_ARRAY_CONTROLLER_DEVICE
* - SBC_ENCLOSURE_SERVICES_DEVICE
* - SBC_SIMPLIFIED_DIRECT_ACCESS_DEVICE
* - SBC_OPTICAL_CARD_READER_WRITER_DEVICE
* - SBC_BRIDGE_CONTROLLER_COMMANDS
* - SBC_OBJECT_BASED_STORAGE_DEVICE
*/
#define SBC_DIRECT_ACCESS_BLOCK_DEVICE 0x00
#define SBC_SEQUENTIAL_ACCESS_DEVICE 0x01
#define SBC_PRINTER_DEVICE 0x02
#define SBC_PROCESSOR_DEVICE 0x03
#define SBC_WRITE_ONCE_DEVICE 0x04
#define SBC_CD_DVD_DEVICE 0x05
#define SBC_SCANNER_DEVICE 0x06
#define SBC_OPTICAL_MEMORY_DEVICE 0x07
#define SBC_MEDIA_CHANGER_DEVICE 0x08
#define SBC_COMMUNICATION_DEVICE 0x09
#define SBC_STORAGE_ARRAY_CONTROLLER_DEVICE 0x0C
#define SBC_ENCLOSURE_SERVICES_DEVICE 0x0D
#define SBC_SIMPLIFIED_DIRECT_ACCESS_DEVICE 0x0E
#define SBC_OPTICAL_CARD_READER_WRITER_DEVICE 0x0F
#define SBC_BRIDGE_CONTROLLER_COMMANDS 0x10
#define SBC_OBJECT_BASED_STORAGE_DEVICE 0x11
/** @}*/
/*------------------------------------------------------------------------------ */
/** \brief Version value for the SBC-3 specification */
/** \see spc4r06.pdf - Section 6.4.2 - Table 85 */
#define SBC_SPC_VERSION_4 0x06
/*------------------------------------------------------------------------------ */
/*------------------------------------------------------------------------------ */
/** \brief Values for the TPGS field returned in INQUIRY data */
/** \see spc4r06.pdf - Section 6.4.2 - Table 86 */
#define SBC_TPGS_NONE 0x0
#define SBC_TPGS_ASYMMETRIC 0x1
#define SBC_TPGS_SYMMETRIC 0x2
#define SBC_TPGS_BOTH 0x3
/*------------------------------------------------------------------------------ */
/*------------------------------------------------------------------------------ */
/** \brief Version descriptor value for the SBC-3 specification */
/** \see spc4r06.pdf - Section 6.4.2 - Table 87 */
#define SBC_VERSION_DESCRIPTOR_SBC_3 0x04C0
/*------------------------------------------------------------------------------ */
/** \addtogroup usbd_sbc_secse_codes SBC Sense Response Codes
* @{
* This page lists sense data response codes returned in REQUEST SENSE data
* \see spc4r06.pdf - Section 4.5.1 - Table 12
*
* \section Codes
* - SBC_SENSE_DATA_FIXED_CURRENT
* - SBC_SENSE_DATA_FIXED_DEFERRED
* - SBC_SENSE_DATA_DESCRIPTOR_CURRENT
* - SBC_SENSE_DATA_DESCRIPTOR_DEFERRED
*/
#define SBC_SENSE_DATA_FIXED_CURRENT 0x70
#define SBC_SENSE_DATA_FIXED_DEFERRED 0x71
#define SBC_SENSE_DATA_DESCRIPTOR_CURRENT 0x72
#define SBC_SENSE_DATA_DESCRIPTOR_DEFERRED 0x73
/** @}*/
/** \addtogroup usbd_sbc_sense_keys SBC Sense Keys
* @{
* This page lists sense key values returned in the REQUEST SENSE data
* \see spc4r06.pdf - Section 4.5.6 - Table 27
*
* \section Keys
* - SBC_SENSE_KEY_NO_SENSE
* - SBC_SENSE_KEY_RECOVERED_ERROR
* - SBC_SENSE_KEY_NOT_READY
* - SBC_SENSE_KEY_MEDIUM_ERROR
* - SBC_SENSE_KEY_HARDWARE_ERROR
* - SBC_SENSE_KEY_ILLEGAL_REQUEST
* - SBC_SENSE_KEY_UNIT_ATTENTION
* - SBC_SENSE_KEY_DATA_PROTECT
* - SBC_SENSE_KEY_BLANK_CHECK
* - SBC_SENSE_KEY_VENDOR_SPECIFIC
* - SBC_SENSE_KEY_COPY_ABORTED
* - SBC_SENSE_KEY_ABORTED_COMMAND
* - SBC_SENSE_KEY_VOLUME_OVERFLOW
* - SBC_SENSE_KEY_MISCOMPARE
*/
/** No specific sense key. Successful command. */
#define SBC_SENSE_KEY_NO_SENSE 0x00
/** Command completed succesfully with some recovery action by the %device. */
#define SBC_SENSE_KEY_RECOVERED_ERROR 0x01
/** The device can not be accessed. */
#define SBC_SENSE_KEY_NOT_READY 0x02
/** Command terminated with a error condition that was probably caused by a */
/** flaw in the medium or an error in the recorded data. */
#define SBC_SENSE_KEY_MEDIUM_ERROR 0x03
/** Hardware failure while performing the command or during a self test. */
#define SBC_SENSE_KEY_HARDWARE_ERROR 0x04
/** Illegal parameter found in the command or additional parameters. */
#define SBC_SENSE_KEY_ILLEGAL_REQUEST 0x05
/** Removable medium may have been changed or the %device has been reset. */
#define SBC_SENSE_KEY_UNIT_ATTENTION 0x06
/** Write on a block that is protected. */
#define SBC_SENSE_KEY_DATA_PROTECT 0x07
/** Indicates that a write-once device or a sequential-access device */
/** encountered blank medium or format-defined end-of-data indication while */
/** reading or a write-once device encountered a non-blank medium while writing. */
#define SBC_SENSE_KEY_BLANK_CHECK 0x08
/** Reporting vendor specific conditions. */
#define SBC_SENSE_KEY_VENDOR_SPECIFIC 0x09
/** EXTENDED COPY command was aborted. */
#define SBC_SENSE_KEY_COPY_ABORTED 0x0A
/** Device aborted the command. */
#define SBC_SENSE_KEY_ABORTED_COMMAND 0x0B
/** A buffered peripheral device is overflow. */
#define SBC_SENSE_KEY_VOLUME_OVERFLOW 0x0D
/** The source data did not match the data read from the medium. */
#define SBC_SENSE_KEY_MISCOMPARE 0x0E
/** @}*/
/** \addtogroup usbd_sbc_sense_additionals SBC Sense Additionals
* @{
* This page lists additional sense code values returned in REQUEST SENSE data
* \see spc4r06.pdf - Section 4.5.6 - Table 28
*
* \section Additional Codes
* - SBC_ASC_LOGICAL_UNIT_NOT_READY
* - SBC_ASC_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE
* - SBC_ASC_INVALID_FIELD_IN_CDB
* - SBC_ASC_WRITE_PROTECTED
* - SBC_ASC_FORMAT_CORRUPTED
* - SBC_ASC_INVALID_COMMAND_OPERATION_CODE
* - SBC_ASC_TOO_MUCH_WRITE_DATA
* - SBC_ASC_NOT_READY_TO_READY_CHANGE
* - SBC_ASC_MEDIUM_NOT_PRESENT
*/
#define SBC_ASC_LOGICAL_UNIT_NOT_READY 0x04
#define SBC_ASC_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE 0x21
#define SBC_ASC_INVALID_FIELD_IN_CDB 0x24
#define SBC_ASC_WRITE_PROTECTED 0x27
#define SBC_ASC_FORMAT_CORRUPTED 0x31
#define SBC_ASC_INVALID_COMMAND_OPERATION_CODE 0x20
#define SBC_ASC_TOO_MUCH_WRITE_DATA 0x26
#define SBC_ASC_NOT_READY_TO_READY_CHANGE 0x28
#define SBC_ASC_MEDIUM_NOT_PRESENT 0x3A
/** @}*/
/*------------------------------------------------------------------------------ */
/** \brief MEDIUM TYPE field value for direct-access block devices */
/** \see sbc3r06.pdf - Section 6.3.1 */
#define SBC_MEDIUM_TYPE_DIRECT_ACCESS_BLOCK_DEVICE 0x00
/*------------------------------------------------------------------------------ */
/*------------------------------------------------------------------------------ */
/** \brief MRIE field values */
/** \see sbc3r06.pdf - Section 7.4.11 - Table 286 */
#define SBC_MRIE_NO_REPORTING 0x00
#define SBC_MRIE_ASYNCHRONOUS 0x01
#define SBC_MRIE_GENERATE_UNIT_ATTENTION 0x02
#define SBC_MRIE_COND_GENERATE_RECOVERED_ERROR 0x03
#define SBC_MRIE_UNCOND_GENERATE_RECOVERED_ERROR 0x04
#define SBC_MRIE_GENERATE_NO_SENSE 0x05
#define SBC_MRIE_ON_REQUEST 0x06
/*------------------------------------------------------------------------------ */
/*------------------------------------------------------------------------------ */
/** \brief Supported mode pages */
/** \see sbc3r06.pdf - Section 6.3.1 - Table 115 */
#define SBC_PAGE_READ_WRITE_ERROR_RECOVERY 0x01
#define SBC_PAGE_INFORMATIONAL_EXCEPTIONS_CONTROL 0x1C
#define SBC_PAGE_RETURN_ALL 0x3F
#define SBC_PAGE_VENDOR_SPECIFIC 0x00
/*------------------------------------------------------------------------------ */
/** \addtogroup usbd_msd_endian_macros MSD Endian Macros
* @{
* This page lists the macros for endianness conversion.
*
* \section Macros
* - WORDB
* - DWORDB
* - STORE_DWORDB
* - STORE_WORDB
*/
/** \brief Converts a byte array to a word value using the big endian format */
#define WORDB(bytes) ((unsigned short) ((bytes[0] << 8) | bytes[1]))
/** \brief Converts a byte array to a dword value using the big endian format */
#define DWORDB(bytes) ((unsigned int) ((bytes[0] << 24) | (bytes[1] << 16) \
| (bytes[2] << 8) | bytes[3]))
/** \brief Stores a dword value in a byte array, in big endian format */
#define STORE_DWORDB(dword, bytes) \
bytes[0] = (unsigned char) (((dword) >> 24) & 0xFF); \
bytes[1] = (unsigned char) (((dword) >> 16) & 0xFF); \
bytes[2] = (unsigned char) (((dword) >> 8) & 0xFF); \
bytes[3] = (unsigned char) ((dword) & 0xFF);
/** \brief Stores a word value in a byte array, in big endian format */
#define STORE_WORDB(word, bytes) \
bytes[0] = (unsigned char) (((word) >> 8) & 0xFF); \
bytes[1] = (unsigned char) ((word) & 0xFF);
/** @}*/
/*------------------------------------------------------------------------------
* Structures
*------------------------------------------------------------------------------*/
#pragma pack(1)
#if defined ( __CC_ARM ) /* Keil ¦ÌVision 4 */
#elif defined ( __ICCARM__ ) /* IAR Ewarm */
#define __attribute__(...)
#define __packed__ packed
#elif defined ( __GNUC__ ) /* GCC CS3 */
#define __packed__ aligned(1)
#endif
/**
* \typedef SBCInquiry
* \brief Structure for the INQUIRY command
* \see spc4r06.pdf - Section 6.4.1 - Table 81
*/
typedef struct _SBCInquiry {
unsigned char bOperationCode; /*!< 0x12 : SBC_INQUIRY */
unsigned char isEVPD:1, /*!< Type of requested data */
bReserved1:7; /*!< Reserved bits */
unsigned char bPageCode; /*!< Specifies the VPD to return */
unsigned char pAllocationLength[2]; /*!< Size of host buffer */
unsigned char bControl; /*!< 0x00 */
} __attribute__ ((__packed__)) SBCInquiry; /* GCC */
/**
* \typedef SBCInquiryData
* \brief Standard INQUIRY data format returned by the device
* \see spc4r06.pdf - Section 6.4.2 - Table 82
*/
typedef struct _SBCInquiryData {
unsigned char bPeripheralDeviceType:5, /*!< Peripheral device type */
bPeripheralQualifier :3; /*!< Peripheral qualifier */
unsigned char bReserved1:7, /*!< Reserved bits */
isRMB :1; /*!< Is media removable ? */
unsigned char bVersion; /*!< SPC version used */
unsigned char bResponseDataFormat:4, /*!< Must be 0x2 */
isHIGHSUP :1, /*!< Hierarchical addressing used ? */
isNORMACA :1, /*!< ACA attribute supported ? */
bObsolete1 :2; /*!< Obsolete bits */
unsigned char bAdditionalLength; /*!< Length of remaining INQUIRY data */
unsigned char isSCCS :1, /*!< Embedded SCC ? */
isACC :1, /*!< Access control coordinator ? */
bTPGS :2, /*!< Target port support group */
is3PC :1, /*!< Third-party copy supported ? */
bReserved2:2, /*!< Reserved bits */
isProtect :1; /*!< Protection info supported ? */
unsigned char bObsolete2:1, /*!< Obsolete bit */
isEncServ :1, /*!< Embedded enclosure service comp? */
isVS :1, /*!< ??? */
isMultiP :1, /*!< Multi-port device ? */
bObsolete3:3, /*!< Obsolete bits */
bUnused1 :1; /*!< Unused feature */
unsigned char bUnused2:6, /*!< Unused features */
isCmdQue:1, /*!< Task management model supported ? */
isVS2 :1; /*!< ??? */
unsigned char pVendorID[8]; /*!< T10 vendor identification */
unsigned char pProductID[16]; /*!< Vendor-defined product ID */
unsigned char pProductRevisionLevel[4];/*!< Vendor-defined product revision */
unsigned char pVendorSpecific[20]; /*!< Vendor-specific data */
unsigned char bUnused3; /*!< Unused features */
unsigned char bReserved3; /*!< Reserved bits */
unsigned short pVersionDescriptors[8]; /*!< Standards the device complies to */
unsigned char pReserved4[22]; /*!< Reserved bytes */
} __attribute__ ((__packed__)) SBCInquiryData; /* GCC */
/**
* \typedef SBCRead10
* \brief Data structure for the READ (10) command
* \see sbc3r07.pdf - Section 5.7 - Table 34
*/
typedef struct _SBCRead10 {
unsigned char bOperationCode; /*!< 0x28 : SBC_READ_10 */
unsigned char bObsolete1:1, /*!< Obsolete bit */
isFUA_NV:1, /*!< Cache control bit */
bReserved1:1, /*!< Reserved bit */
isFUA:1, /*!< Cache control bit */
isDPO:1, /*!< Cache control bit */
bRdProtect:3; /*!< Protection information to send */
unsigned char pLogicalBlockAddress[4]; /*!< Index of first block to read */
unsigned char bGroupNumber:5, /*!< Information grouping */
bReserved2:3; /*!< Reserved bits */
unsigned char pTransferLength[2]; /*!< Number of blocks to transmit */
unsigned char bControl; /*!< 0x00 */
} __attribute__ ((__packed__)) SBCRead10; /* GCC */
/**
* \typedef SBCReadCapacity10
* \brief Structure for the READ CAPACITY (10) command
* \see sbc3r07.pdf - Section 5.11.1 - Table 40
*/
typedef struct _SBCReadCapacity10 {
unsigned char bOperationCode; /*!< 0x25 : RBC_READ_CAPACITY */
unsigned char bObsolete1:1, /*!< Obsolete bit */
bReserved1:7; /*!< Reserved bits */
unsigned char pLogicalBlockAddress[4]; /*!< Block to evaluate if PMI is set */
unsigned char pReserved2[2]; /*!< Reserved bytes */
unsigned char isPMI:1, /*!< Partial medium indicator bit */
bReserved3:7; /*!< Reserved bits */
unsigned char bControl; /*!< 0x00 */
} SBCReadCapacity10;
/*------------------------------------------------------------------------------
* \brief Data returned by the device after a READ CAPACITY (10) command
* \see sbc3r07.pdf - Section 5.11.2 - Table 41
*------------------------------------------------------------------------------*/
typedef struct {
unsigned char pLogicalBlockAddress[4]; /*!< Address of last logical block */
unsigned char pLogicalBlockLength[4]; /*!< Length of each logical block */
} SBCReadCapacity10Data;
/*------------------------------------------------------------------------------
* \brief Structure for the REQUEST SENSE command
* \see spc4r06.pdf - Section 6.26 - Table 170
*------------------------------------------------------------------------------*/
typedef struct {
unsigned char bOperationCode; /*!< 0x03 : SBC_REQUEST_SENSE */
unsigned char isDesc :1, /*!< Type of information expected */
bReserved1:7; /*!< Reserved bits */
unsigned char pReserved2[2]; /*!< Reserved bytes */
unsigned char bAllocationLength; /*!< Size of host buffer */
unsigned char bControl; /*!< 0x00 */
} SBCRequestSense;
/*------------------------------------------------------------------------------
* \brief Fixed format sense data returned after a REQUEST SENSE command has
* been received with a DESC bit cleared.
* \see spc4r06.pdf - Section 4.5.3 - Table 26
*------------------------------------------------------------------------------*/
typedef struct {
unsigned char bResponseCode:7, /*!< Sense data format */
isValid :1; /*!< Information field is standard */
unsigned char bObsolete1; /*!< Obsolete byte */
unsigned char bSenseKey :4, /*!< Generic error information */
bReserved1:1, /*!< Reserved bit */
isILI :1, /*!< SSC */
isEOM :1, /*!< SSC */
isFilemark:1; /*!< SSC */
unsigned char pInformation[4]; /*!< Command-specific */
unsigned char bAdditionalSenseLength; /*!< sizeof(SBCRequestSense_data)-8 */
unsigned char pCommandSpecificInformation[4]; /*!< Command-specific */
unsigned char bAdditionalSenseCode; /*!< Additional error information */
unsigned char bAdditionalSenseCodeQualifier; /*!< Further error information */
unsigned char bFieldReplaceableUnitCode; /*!< Specific component code */
unsigned char bSenseKeySpecific:7, /*!< Additional exception info */
isSKSV :1; /*!< Is sense key specific valid? */
unsigned char pSenseKeySpecific[2]; /*!< Additional exception info */
} SBCRequestSenseData;
/**
* \brief SBCTestUnitReady
* Data structure for the TEST UNIT READY command
* \see spc4r06.pdf - Section 6.34 - Table 192
*/
typedef struct _SBCTestUnitReady {
unsigned char bOperationCode; /*!< 0x00 : SBC_TEST_UNIT_READY */
unsigned char pReserved1[4]; /*!< Reserved bits */
unsigned char bControl; /*!< 0x00 */
} __attribute__ ((__packed__)) SBCTestUnitReady; /* GCC */
/**
* \typedef SBCWrite10
* \brief Structure for the WRITE (10) command
* \see sbc3r07.pdf - Section 5.26 - Table 70
*/
typedef struct _SBCWrite10 {
unsigned char bOperationCode; /*!< 0x2A : SBC_WRITE_10 */
unsigned char bObsolete1:1, /*!< Obsolete bit */
isFUA_NV:1, /*!< Cache control bit */
bReserved1:1, /*!< Reserved bit */
isFUA:1, /*!< Cache control bit */
isDPO:1, /*!< Cache control bit */
bWrProtect:3; /*!< Protection information to send */
unsigned char pLogicalBlockAddress[4]; /*!< First block to write */
unsigned char bGroupNumber:5, /*!< Information grouping */
bReserved2:3; /*!< Reserved bits */
unsigned char pTransferLength[2]; /*!< Number of blocks to write */
unsigned char bControl; /*!< 0x00 */
} SBCWrite10;
/**
* \typedef SBCMediumRemoval
* \brief Structure for the PREVENT/ALLOW MEDIUM REMOVAL command
* \see sbc3r07.pdf - Section 5.5 - Table 30
*/
typedef struct _SBCMediumRemoval {
unsigned char bOperationCode; /*!< 0x1E : SBC_PREVENT_ALLOW_MEDIUM_REMOVAL */
unsigned char pReserved1[3]; /*!< Reserved bytes */
unsigned char bPrevent:2, /*!< Accept/prohibit removal */
bReserved2:6; /*!< Reserved bits */
unsigned char bControl; /*!< 0x00 */
} __attribute__ ((__packed__)) SBCMediumRemoval; /* GCC */
/**
* \typedef SBCModeSense6
* \brief Structure for the MODE SENSE (6) command
* \see spc4r06 - Section 6.9.1 - Table 98
*/
typedef struct _SBCModeSense6 {
unsigned char bOperationCode; /*!< 0x1A : SBC_MODE_SENSE_6 */
unsigned char bReserved1:3, /*!< Reserved bits */
isDBD:1, /*!< Disable block descriptors bit */
bReserved2:4; /*!< Reserved bits */
unsigned char bPageCode:6, /*!< Mode page to return */
bPC:2; /*!< Type of parameter values to return */
unsigned char bSubpageCode; /*!< Mode subpage to return */
unsigned char bAllocationLength; /*!< Host buffer allocated size */
unsigned char bControl; /*!< 0x00 */
} __attribute__ ((__packed__)) SBCModeSense6; /* GCC */
/**
* \typedef SBCModeParameterHeader6
* \brief Header for the data returned after a MODE SENSE (6) command
* \see spc4r06.pdf - Section 7.4.3 - Table 268
*/
typedef struct _SBCModeParameterHeader6 {
unsigned char bModeDataLength; /*!< Length of mode data to follow */
unsigned char bMediumType; /*!< Type of medium (SBC_MEDIUM_TYPE_DIRECT_ACCESS_BLOCK_DEVICE) */
unsigned char bReserved1:4, /*!< Reserved bits */
isDPOFUA:1, /*!< DPO/FUA bits supported ? */
bReserved2:2, /*!< Reserved bits */
isWP:1; /*!< Is medium write-protected ? */
unsigned char bBlockDescriptorLength; /*!< Length of all block descriptors */
} __attribute__ ((__packed__)) SBCModeParameterHeader6; /* GCC */
/**
* \typedef SBCInformationalExceptionsControl
* \brief Informational exceptions control mode page
* \see spc4r06.pdf - Section 7.4.11 - Table 285
*/
typedef struct _SBCInformationalExceptionsControl {
unsigned char bPageCode:6, /*!< 0x1C : SBC_PAGE_INFORMATIONAL_EXCEPTIONS_CONTROL */
isSPF:1, /*!< Page or subpage data format */
isPS:1; /*!< Parameters saveable ? */
unsigned char bPageLength; /*!< Length of page data (0x0A) */
unsigned char isLogErr:1, /*!< Should informational exceptions be logged ? */
isEBackErr:1, /*!< Enable background error bit */
isTest:1, /*!< Create a device test failure ? */
isDExcpt:1, /*!< Disable exception control bit */
isEWasc:1, /*!< Report warnings ? */
isEBF:1, /*!< Enable background function bit */
bReserved1:1, /*!< Reserved bit */
isPerf:1; /*!< Delay acceptable when treating exceptions ? */
unsigned char bMRIE:4, /*!< Method of reporting informational exceptions */
bReserved2:4; /*!< Reserved bits */
unsigned char pIntervalTimer[4]; /*!< Error reporting period */
unsigned char pReportCount[4]; /*!< Maximum number of time a report can be issued */
} __attribute__ ((__packed__)) SBCInformationalExceptionsControl; /* GCC */
/**
* \typedef SBCReadWriteErrorRecovery
* \brief Read/write error recovery mode page
* \see sbc3r07.pdf - Section 6.3.5 - Table 122
*/
typedef struct _SBCReadWriteErrorRecovery {
unsigned char bPageCode:6, /*!< 0x01 : SBC_PAGE_READ_WRITE_ERROR_RECOVERY */
isSPF:1, /*!< Page or subpage data format */
isPS:1; /*!< Parameters saveable ? */
unsigned char bPageLength; /*!< Length of page data (0x0A) */
unsigned char isDCR:1, /*!< Disable correction bit */
isDTE:1, /*!< Data terminate on error bit */
isPER:1, /*!< Post error bit */
isEER:1, /*!< Enable early recovery bit */
isRC:1, /*!< Read continuous bit */
isTB:1, /*!< Transfer block bit */
isARRE:1, /*!< Automatic read reallocation enabled bit */
isAWRE:1; /*!< Automatic write reallocation enabled bit */
unsigned char bReadRetryCount; /*!< Number of retries when reading */
unsigned char pObsolete1[3]; /*!< Obsolete bytes */
unsigned char bReserved1; /*!< Reserved byte */
unsigned char bWriteRetryCount; /*!< Number of retries when writing */
unsigned char bReserved2; /*!< Reserved byte */
unsigned char pRecoveryTimeLimit[2]; /*!< Maximum time duration for error recovery */
} __attribute__ ((__packed__)) SBCReadWriteErrorRecovery; /* GCC */
/**
* \typedef SBCCommand
* \brief Generic structure for holding information about SBC commands
* \see SBCInquiry
* \see SBCRead10
* \see SBCReadCapacity10
* \see SBCRequestSense
* \see SBCTestUnitReady
* \see SBCWrite10
* \see SBCMediumRemoval
* \see SBCModeSense6
*/
typedef union _SBCCommand {
unsigned char bOperationCode; /*!< Operation code of the command */
SBCInquiry inquiry; /*!< INQUIRY command */
SBCRead10 read10; /*!< READ (10) command */
SBCReadCapacity10 readCapacity10; /*!< READ CAPACITY (10) command */
SBCRequestSense requestSense; /*!< REQUEST SENSE command */
SBCTestUnitReady testUnitReady; /*!< TEST UNIT READY command */
SBCWrite10 write10; /*!< WRITE (10) command */
SBCMediumRemoval mediumRemoval; /*!< PREVENT/ALLOW MEDIUM REMOVAL command */
SBCModeSense6 modeSense6; /*!< MODE SENSE (6) command */
} SBCCommand;
#pragma pack()
/**@}*/
#endif /*#ifndef SBC_H */

View File

@ -0,0 +1,118 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
*
* 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 disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
* ----------------------------------------------------------------------------
*/
/** \file
* \section Purpose
*
* SCSI commands implementation.
*
* section Usage
*
* -# After a CBW is received from host, use SBC_GetCommandInformation to check
* if the command is supported, and get the command length and type
* information before processing it.
* -# Then SBC_ProcessCommand can be used to handle a valid command, to
* perform the command operations.
* -# SBC_UpdateSenseData is used to update the sense data that will be sent
* to host.
*/
#ifndef SBCMETHODS_H
#define SBCMETHODS_H
/** \addtogroup usbd_msd
*@{
*/
/*------------------------------------------------------------------------------
* Headers
*------------------------------------------------------------------------------*/
#include "SBC.h"
#include "MSDLun.h"
#include "MSDDStateMachine.h"
/*------------------------------------------------------------------------------
* Definitions
*------------------------------------------------------------------------------*/
/** \addtogroup usbd_sbc_command_state SBC Command States
* @{
* This page lists the possible states of a SBC command.
*
* \section States
* - SBC_STATE_READ
* - SBC_STATE_WAIT_READ
* - SBC_STATE_WRITE
* - SBC_STATE_WAIT_WRITE
* - SBC_STATE_NEXT_BLOCK
*/
/** Start of reading bulk data */
#define SBC_STATE_READ 0x01
/** Waiting for the bulk data reading complete */
#define SBC_STATE_WAIT_READ 0x02
/** Read error state */
#define SBC_STATE_READ_ERROR 0x03
/** Start next read block */
#define SBC_STATE_NEXT_READ 0x04
/** Start writing bulk data to host */
#define SBC_STATE_WRITE 0x05
/** Waiting for the bulk data sending complete */
#define SBC_STATE_WAIT_WRITE 0x06
/** Write error state */
#define SBC_STATE_WRITE_ERROR 0x07
/** Start next write block */
#define SBC_STATE_NEXT_WRITE 0x08
/** Start next command block */
#define SBC_STATE_NEXT_BLOCK 0x09
/** @}*/
/*------------------------------------------------------------------------------
* Exported functions
*------------------------------------------------------------------------------*/
void SBC_UpdateSenseData(SBCRequestSenseData *requestSenseData,
unsigned char senseKey,
unsigned char additionalSenseCode,
unsigned char additionalSenseCodeQualifier);
unsigned char SBC_GetCommandInformation(void *command,
unsigned int *length,
unsigned char *type,
MSDLun *lun);
unsigned char SBC_ProcessCommand(MSDLun *lun,
MSDCommandState *commandState);
/**@}*/
#endif /*#ifndef SBCMETHODS_H */

View File

@ -0,0 +1,278 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
*
* 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 disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
* ----------------------------------------------------------------------------
*/
/**
* \file
*
* \section Purpose
*
* Collection of methods for using the USB device controller on AT91
* microcontrollers.
*
* \section Usage
*
* Please refer to the corresponding application note.
* - \ref usbd_framework AT91 USB device framework
* - \ref usbd_api USBD API
*
*/
#ifndef USBD_H
#define USBD_H
/*----------------------------------------------------------------------------
* Headers
*----------------------------------------------------------------------------*/
#include "USBDescriptors.h"
#include "USBRequests.h"
#include "USBLib_Types.h"
#include <stdio.h>
/*------------------------------------------------------------------------------
* Definitions
*------------------------------------------------------------------------------*/
/* Define attribute */
#if defined ( __CC_ARM ) /* Keil ¦ÌVision 4 */
#define WEAK __attribute__ ((weak))
#elif defined ( __ICCARM__ ) /* IAR Ewarm 5.41+ */
#define WEAK __weak
#elif defined ( __GNUC__ ) /* GCC CS3 2009q3-68 */
#define WEAK __attribute__ ((weak))
#endif
/* Define NO_INIT attribute */
#if defined ( __CC_ARM )
#define NO_INIT
#elif defined ( __ICCARM__ )
#define NO_INIT __no_init
#elif defined ( __GNUC__ )
#define NO_INIT
#endif
/** \addtogroup usbd_interface
*@{*/
/**
* \addtogroup usbd_rc USB device API return codes
* @{
* This section lists the return codes for the USB device driver API
* - \ref USBD_STATUS_SUCCESS
* - \ref USBD_STATUS_LOCKED
* - \ref USBD_STATUS_ABORTED
* - \ref USBD_STATUS_RESET
*/
/** Indicates the operation was successful. */
#define USBD_STATUS_SUCCESS USBRC_SUCCESS
/** Endpoint/device is already busy. */
#define USBD_STATUS_LOCKED USBRC_BUSY
/** Operation has been aborted (error or stall). */
#define USBD_STATUS_ABORTED USBRC_ABORTED
/** Operation has been canceled (by user). */
#define USBD_STATUS_CANCELED USBRC_CANCELED
/** Operation has been aborted because the device init/reset/un-configure. */
#define USBD_STATUS_RESET USBRC_RESET
/** Part ot operation successfully done. */
#define USBD_STATUS_PARTIAL_DONE USBRC_PARTIAL_DONE
/** Operation failed because parameter error */
#define USBD_STATUS_INVALID_PARAMETER USBRC_PARAM_ERR
/** Operation failed because in unexpected state */
#define USBD_STATUS_WRONG_STATE USBRC_STATE_ERR
/** Operation failed because SW not supported */
#define USBD_STATUS_SW_NOT_SUPPORTED USBRC_SW_NOT_SUPPORTED
/** Operation failed because HW not supported */
#define USBD_STATUS_HW_NOT_SUPPORTED USBRC_HW_NOT_SUPPORTED
/** @}*/
/** \addtogroup usbd_states USB device states
* @{
* This section lists the device states of the USB device driver.
* - \ref USBD_STATE_SUSPENDED
* - \ref USBD_STATE_ATTACHED
* - \ref USBD_STATE_POWERED
* - \ref USBD_STATE_DEFAULT
* - \ref USBD_STATE_ADDRESS
* - \ref USBD_STATE_CONFIGURED
*/
/** The device is currently suspended. */
#define USBD_STATE_SUSPENDED 0
/** USB cable is plugged into the device. */
#define USBD_STATE_ATTACHED 1
/** Host is providing +5V through the USB cable. */
#define USBD_STATE_POWERED 2
/** Device has been reset. */
#define USBD_STATE_DEFAULT 3
/** The device has been given an address on the bus. */
#define USBD_STATE_ADDRESS 4
/** A valid configuration has been selected. */
#define USBD_STATE_CONFIGURED 5
/** @}*/
/*----------------------------------------------------------------------------
* Types
*----------------------------------------------------------------------------*/
/**
* \brief Buffer struct used for multi-buffer-listed transfer.
*
* The driver can process 255 bytes of buffers or buffer list window.
*/
typedef struct _USBDTransferBuffer {
/** Pointer to frame buffer */
uint8_t * pBuffer;
/** Size of the frame (up to 64K-1) */
uint16_t size;
/** Bytes transferred */
uint16_t transferred;
/** Bytes in FIFO */
uint16_t buffered;
/** Bytes remaining */
uint16_t remaining;
} USBDTransferBuffer;
#pragma pack(1)
#if defined ( __CC_ARM ) /* Keil ¦ÌVision 4 */
#elif defined ( __ICCARM__ ) /* IAR Ewarm 5.41+ */
#define __attribute__(...)
#elif defined ( __GNUC__ ) /* GCC CS3 2009q3-68 */
#endif
/**
* \brief Struct used for USBD DMA Link List Transfer Descriptor, must be 16-bytes
* aligned.
*
* (For USB, DMA transfer is linked to EPs and FIFO address is EP defined)
*/
typedef struct _USBDDmaDescriptor {
/** Pointer to Next Descriptor */
void* pNxtDesc;
/** Pointer to data buffer address */
void* pDataAddr;
/** DMA Control setting register value */
uint32_t ctrlSettings:8, /** Control settings */
reserved:8, /** Not used */
bufferLength:16; /** Length of buffer */
/** Loaded to DMA register, OK to modify */
uint32_t used;
} __attribute__((aligned(16))) USBDDmaDescriptor;
#pragma pack()
/**
* Callback used by transfer functions (USBD_Read & USBD_Write) to notify
* that a transaction is complete.
*/
typedef void (*TransferCallback)(void *pArg,
uint8_t status,
uint32_t transferred,
uint32_t remaining);
/**
* Callback used by MBL transfer functions (USBD_Read & USBD_Write) to notify
* that a transaction is complete.
* \param pArg Pointer to callback arguments.
* \param status USBD status.
*/
typedef void (*MblTransferCallback)(void *pArg,
uint8_t status);
/**@}*/
/*------------------------------------------------------------------------------
* Exported functions
*------------------------------------------------------------------------------*/
//extern void USBD_IrqHandler(void);
extern void USBD_Init(void);
extern void USBD_ConfigureSpeed(uint8_t forceFS);
extern void USBD_Connect(void);
extern void USBD_Disconnect(void);
extern uint8_t USBD_Write(
uint8_t bEndpoint,
const void *pData,
uint32_t size,
TransferCallback callback,
void *pArg);
extern uint8_t USBD_Read(
uint8_t bEndpoint,
void *pData,
uint32_t dLength,
TransferCallback fCallback,
void *pArg);
extern uint8_t USBD_Stall(uint8_t bEndpoint);
extern void USBD_Halt(uint8_t bEndpoint);
extern void USBD_Unhalt(uint8_t bEndpoint);
extern void USBD_ConfigureEndpoint(const USBEndpointDescriptor *pDescriptor);
extern uint8_t USBD_IsHalted(uint8_t bEndpoint);
extern void USBD_RemoteWakeUp(void);
extern void USBD_SetAddress(uint8_t address);
extern void USBD_SetConfiguration(uint8_t cfgnum);
extern uint8_t USBD_GetState(void);
extern uint8_t USBD_IsHighSpeed(void);
extern void USBD_Test(uint8_t bIndex);
extern void USBD_SuspendHandler(void);
extern void USBD_ResumeHandler(void);
extern void USBD_ResetHandler(void);
extern void USBD_RequestHandler(uint8_t bEndpoint,
const USBGenericRequest * pRequest);
extern void USBDCallbacks_Initialized(void);
extern void USBDCallbacks_Reset(void);
extern void USBDCallbacks_Suspended(void);
extern void USBDCallbacks_Resumed(void);
extern void USBDCallbacks_RequestReceived(const USBGenericRequest *request);
#endif /*#ifndef USBD_H*/

View File

@ -0,0 +1,149 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
*
* 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 disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
* ----------------------------------------------------------------------------
*/
/**
* \file
*
* \section Purpose
*
* USB Device Driver class definition.
*
* \section Usage
*
* -# Instanciate a USBDDriver object and initialize it using
* USBDDriver_Initialize.
* -# When a USB SETUP request is received, forward it to the standard
* driver using USBDDriver_RequestHandler.
* -# Check the Remote Wakeup setting via USBDDriver_IsRemoteWakeUpEnabled.
*/
#ifndef USBDDRIVER_H
#define USBDDRIVER_H
/** \addtogroup usbd_interface
*@{
*/
/*------------------------------------------------------------------------------
* Headers
*------------------------------------------------------------------------------*/
/* These headers were introduced in C99 by working group
* ISO/IEC JTC1/SC22/WG14.
*/
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <USBRequests.h>
#include <USBDescriptors.h>
#include <USBLib_Types.h>
/*------------------------------------------------------------------------------
* Types
*------------------------------------------------------------------------------*/
/**
* \typedef USBDDriverDescriptors
* \brief List of all descriptors used by a USB device driver. Each descriptor
* can be provided in two versions: full-speed and high-speed. Devices
* which are not high-speed capable do not need to provided high-speed
* descriptors and the full-speed qualifier & other speed descriptors.
*/
typedef struct _USBDDriverDescriptors {
/** Pointer to the full-speed device descriptor */
const USBDeviceDescriptor *pFsDevice;
/** Pointer to the full-speed configuration descriptor */
const USBConfigurationDescriptor *pFsConfiguration;
/** Pointer to the full-speed qualifier descriptor */
const USBDeviceQualifierDescriptor *pFsQualifier;
/** Pointer to the full-speed other speed configuration descriptor */
const USBConfigurationDescriptor *pFsOtherSpeed;
/** Pointer to the high-speed device descriptor */
const USBDeviceDescriptor *pHsDevice;
/** Pointer to the high-speed configuration descriptor */
const USBConfigurationDescriptor *pHsConfiguration;
/** Pointer to the high-speed qualifier descriptor */
const USBDeviceQualifierDescriptor *pHsQualifier;
/** Pointer to the high-speed other speed configuration descriptor */
const USBConfigurationDescriptor *pHsOtherSpeed;
/** Pointer to the list of string descriptors */
const uint8_t **pStrings;
/** Number of string descriptors in list */
uint8_t numStrings;
} USBDDriverDescriptors;
/**
* \typedef USBDDriver
* \brief USB device driver structure, holding a list of descriptors identifying
* the device as well as the driver current state.
*/
typedef struct _USBDDriver {
/** List of descriptors used by the device. */
const USBDDriverDescriptors *pDescriptors;
/** Current setting for each interface. */
uint8_t *pInterfaces;
/** Current configuration number (0 -> device is not configured). */
uint8_t cfgnum;
/** Indicates if remote wake up has been enabled by the host. */
uint8_t isRemoteWakeUpEnabled;
/** Features supported by OTG */
uint8_t otg_features_supported;
} USBDDriver;
/*------------------------------------------------------------------------------
* Exported functions
*------------------------------------------------------------------------------*/
extern USBDDriver *USBD_GetDriver(void);
extern void USBDDriver_Initialize(
USBDDriver *pDriver,
const USBDDriverDescriptors *pDescriptors,
uint8_t *pInterfaces);
extern USBConfigurationDescriptor* USBDDriver_GetCfgDescriptors(
USBDDriver * pDriver,
uint8_t cfgNum);
extern void USBDDriver_RequestHandler(
USBDDriver *pDriver,
const USBGenericRequest *pRequest);
extern uint8_t USBDDriver_IsRemoteWakeUpEnabled(const USBDDriver *pDriver);
extern uint8_t USBDDriver_returnOTGFeatures(const USBDDriver *pDriver);
extern void USBDDriver_clearOTGFeatures(USBDDriver *pDriver);
extern void USBDDriverCallbacks_ConfigurationChanged(uint8_t cfgnum);
extern void USBDDriverCallbacks_InterfaceSettingChanged(uint8_t interface,
uint8_t setting);
/**@}*/
#endif /*#ifndef USBDDRIVER_H*/

View File

@ -0,0 +1,111 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2009, Atmel Corporation
*
* 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 disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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 USBD_HAL_H
#define USBD_HAL_H
/**
* \file
*
* This file defines functions for USB Device Hardware Access Level.
*/
/** \addtogroup usbd_hal
*@{*/
/*----------------------------------------------------------------------------
* Headers
*----------------------------------------------------------------------------*/
/* Introduced in C99 by working group ISO/IEC JTC1/SC22/WG14. */
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "USBD.h"
#include <USBDescriptors.h>
#include <USBRequests.h>
/*----------------------------------------------------------------------------
* Consts
*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------
* Macros
*----------------------------------------------------------------------------*/
/** Get bitmap for an endpoint */
#define bmEP(bEP) (1 << (bEP))
/*----------------------------------------------------------------------------
* Types
*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------
* Exported functoins
*----------------------------------------------------------------------------*/
extern void USBD_HAL_Init(void);
extern void USBD_HAL_Connect(void);
extern void USBD_HAL_Disconnect(void);
extern void USBD_HAL_RemoteWakeUp(void);
extern void USBD_HAL_SetConfiguration(uint8_t cfgnum);
extern void USBD_HAL_SetAddress(uint8_t address);
extern uint8_t USBD_HAL_IsHighSpeed(void);
extern void USBD_HAL_Suspend(void);
extern void USBD_HAL_Activate(void);
extern void USBD_HAL_ResetEPs(uint32_t bmEPs,uint8_t bStatus, uint8_t bKeepCfg);
extern void USBD_HAL_CancelIo(uint32_t bmEPs);
extern uint8_t USBD_HAL_ConfigureEP(const USBEndpointDescriptor * pDescriptor);
extern uint8_t USBD_HAL_SetTransferCallback(uint8_t bEP,
TransferCallback fCallback,
void * pCbData);
extern uint8_t USBD_HAL_SetupMblTransfer(uint8_t bEndpoint,
USBDTransferBuffer * pMbList,
uint16_t mblSize,
uint16_t startOffset);
extern uint8_t USBD_HAL_Write(uint8_t bEndpoint,
const void * pData,
uint32_t dLength);
extern uint8_t USBD_HAL_WrWithHdr(uint8_t bEndpoint,
const void * pHdr, uint8_t bHdrLen,
const void * pData, uint32_t dLength);
extern uint8_t USBD_HAL_Read(uint8_t bEndpoint,
void * pData,
uint32_t dLength);
extern uint8_t USBD_HAL_Stall(uint8_t bEP);
extern uint8_t USBD_HAL_Halt(uint8_t bEndpoint,uint8_t ctl);
extern void USBD_HAL_Test(uint8_t bIndex);
/**@}*/
#endif // #define USBD_HAL_H

View File

@ -0,0 +1,549 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2010, Atmel Corporation
*
* 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 disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
* ----------------------------------------------------------------------------
*/
/** \file
* \section Purpose
*
* Definitions and methods for USB descriptor structures described by the
* USB specification.
*
* \section Usage
*
*/
#ifndef _USBDESCRIPTORS_H_
#define _USBDESCRIPTORS_H_
/** \addtogroup usb_general
* @{
* \addtogroup usb_descriptor USB Descriptors
* @{
*/
/*---------------------------------------------------------------------------
* Headers
*---------------------------------------------------------------------------*/
/* These headers were introduced in C99 by working group
* ISO/IEC JTC1/SC22/WG14.
*/
#include <stdint.h>
/*---------------------------------------------------------------------------
* Definitions
*---------------------------------------------------------------------------*/
/*--------- Generic Descriptors --------*/
/** \addtogroup usb_desc_type USB Descriptor types
* @{
* This section lists the codes of the usb descriptor types
* - \ref USBGenericDescriptor_DEVICE
* - \ref USBGenericDescriptor_CONFIGURATION
* - \ref USBGenericDescriptor_STRING
* - \ref USBGenericDescriptor_INTERFACE
* - \ref USBGenericDescriptor_ENDPOINT
* - \ref USBGenericDescriptor_DEVICEQUALIFIER
* - \ref USBGenericDescriptor_OTHERSPEEDCONFIGURATION
* - \ref USBGenericDescriptor_INTERFACEPOWER
* - \ref USBGenericDescriptor_OTG
* - \ref USBGenericDescriptor_DEBUG
* - \ref USBGenericDescriptor_INTERFACEASSOCIATION
*/
/** Device descriptor type. */
#define USBGenericDescriptor_DEVICE 1
/** Configuration descriptor type. */
#define USBGenericDescriptor_CONFIGURATION 2
/** String descriptor type. */
#define USBGenericDescriptor_STRING 3
/** Interface descriptor type. */
#define USBGenericDescriptor_INTERFACE 4
/** Endpoint descriptor type. */
#define USBGenericDescriptor_ENDPOINT 5
/** Device qualifier descriptor type. */
#define USBGenericDescriptor_DEVICEQUALIFIER 6
/** Other speed configuration descriptor type. */
#define USBGenericDescriptor_OTHERSPEEDCONFIGURATION 7
/** Interface power descriptor type. */
#define USBGenericDescriptor_INTERFACEPOWER 8
/** On-The-Go descriptor type. */
#define USBGenericDescriptor_OTG 9
/** Debug descriptor type. */
#define USBGenericDescriptor_DEBUG 10
/** Interface association descriptor type. */
#define USBGenericDescriptor_INTERFACEASSOCIATION 11
/** @}*/
/*--------- Device Descriptors --------*/
/** \addtogroup usb_release_number USB release numbers
* @{
* This section lists the codes of USB release numbers.
* - \ref USBDeviceDescriptor_USB2_00
*/
/** The device supports USB 2.00. */
#define USBDeviceDescriptor_USB2_00 0x0200
/** @}*/
/*--------- Configuration Descriptors --------*/
/** \addtogroup usb_attributes USB Device Attributes
* @{
* This section lists the codes of the usb attributes.
* - \ref USBConfigurationDescriptor_BUSPOWERED_NORWAKEUP
* - \ref USBConfigurationDescriptor_SELFPOWERED_NORWAKEUP
* - \ref USBConfigurationDescriptor_BUSPOWERED_RWAKEUP
* - \ref USBConfigurationDescriptor_SELFPOWERED_RWAKEUP
* - \ref USBConfigurationDescriptor_POWER
*/
/** Device is bus-powered and not support remote wake-up. */
#define USBConfigurationDescriptor_BUSPOWERED_NORWAKEUP 0x80
/** Device is self-powered and not support remote wake-up. */
#define USBConfigurationDescriptor_SELFPOWERED_NORWAKEUP 0xC0
/** Device is bus-powered and supports remote wake-up. */
#define USBConfigurationDescriptor_BUSPOWERED_RWAKEUP 0xA0
/** Device is self-powered and supports remote wake-up. */
#define USBConfigurationDescriptor_SELFPOWERED_RWAKEUP 0xE0
/** Calculates the value of the power consumption field given the value in mA.
* \param power The power consumption value in mA
* \return The value that should be set to the field in descriptor
*/
#define USBConfigurationDescriptor_POWER(power) (power / 2)
/** @}*/
/*--------- Endpoint Descriptors --------*/
/** \addtogroup usb_ep_define USB Endpoint definitions
* @{
* This section lists definitions and macro for endpoint descriptors.
* - \ref usb_ep_dir USB Endpoint directions
* - \ref USBEndpointDescriptor_OUT
* - \ref USBEndpointDescriptor_IN
*
* - \ref usb_ep_type USB Endpoint types
* - \ref USBEndpointDescriptor_CONTROL
* - \ref USBEndpointDescriptor_ISOCHRONOUS
* - \ref USBEndpointDescriptor_BULK
* - \ref USBEndpointDescriptor_INTERRUPT
*
* - \ref usb_ep_size USB Endpoint maximun sizes
* - \ref USBEndpointDescriptor_MAXCTRLSIZE_FS
* - \ref USBEndpointDescriptor_MAXCTRLSIZE_HS
* - \ref USBEndpointDescriptor_MAXBULKSIZE_FS
* - \ref USBEndpointDescriptor_MAXBULKSIZE_HS
* - \ref USBEndpointDescriptor_MAXINTERRUPTSIZE_FS
* - \ref USBEndpointDescriptor_MAXINTERRUPTSIZE_HS
* - \ref USBEndpointDescriptor_MAXISOCHRONOUSSIZE_FS
* - \ref USBEndpointDescriptor_MAXISOCHRONOUSSIZE_HS
*
* - \ref usb_ep_addr USB Endpoint address define
* - \ref USBEndpointDescriptor_ADDRESS
*/
/** \addtogroup usb_ep_dir USB Endpoint directions
* @{
* This section lists definitions of USB endpoint directions.
* - USBEndpointDescriptor_OUT
* - USBEndpointDescriptor_IN
*/
/** Endpoint receives data from the host. */
#define USBEndpointDescriptor_OUT 0
/** Endpoint sends data to the host. */
#define USBEndpointDescriptor_IN 1
/** @}*/
/** \addtogroup usb_ep_type USB Endpoint types
* @{
* This section lists definitions of USB endpoint types.
* - \ref USBEndpointDescriptor_CONTROL
* - \ref USBEndpointDescriptor_ISOCHRONOUS
* - \ref USBEndpointDescriptor_BULK
* - \ref USBEndpointDescriptor_INTERRUPT
*/
/** Control endpoint type. */
#define USBEndpointDescriptor_CONTROL 0
/** Isochronous endpoint type. */
#define USBEndpointDescriptor_ISOCHRONOUS 1
/** Bulk endpoint type. */
#define USBEndpointDescriptor_BULK 2
/** Interrupt endpoint type. */
#define USBEndpointDescriptor_INTERRUPT 3
/** @}*/
/** \addtogroup usb_ep_size USB Endpoint maximun sizes
* @{
* This section lists definitions of USB endpoint maximun sizes.
* - \ref USBEndpointDescriptor_MAXCTRLSIZE_FS
* - \ref USBEndpointDescriptor_MAXCTRLSIZE_HS
* - \ref USBEndpointDescriptor_MAXBULKSIZE_FS
* - \ref USBEndpointDescriptor_MAXBULKSIZE_HS
* - \ref USBEndpointDescriptor_MAXINTERRUPTSIZE_FS
* - \ref USBEndpointDescriptor_MAXINTERRUPTSIZE_HS
* - \ref USBEndpointDescriptor_MAXISOCHRONOUSSIZE_FS
* - \ref USBEndpointDescriptor_MAXISOCHRONOUSSIZE_HS
*/
/** Maximum size for a full-speed control endpoint. */
#define USBEndpointDescriptor_MAXCTRLSIZE_FS 64
/** Maximum size for a high-speed control endpoint. */
#define USBEndpointDescriptor_MAXCTRLSIZE_HS 64
/** Maximum size for a full-speed bulk endpoint. */
#define USBEndpointDescriptor_MAXBULKSIZE_FS 64
/** Maximum size for a high-speed bulk endpoint. */
#define USBEndpointDescriptor_MAXBULKSIZE_HS 512
/** Maximum size for a full-speed interrupt endpoint. */
#define USBEndpointDescriptor_MAXINTERRUPTSIZE_FS 64
/** Maximum size for a high-speed interrupt endpoint. */
#define USBEndpointDescriptor_MAXINTERRUPTSIZE_HS 1024
/** Maximum size for a full-speed isochronous endpoint. */
#define USBEndpointDescriptor_MAXISOCHRONOUSSIZE_FS 1023
/** Maximum size for a high-speed isochronous endpoint. */
#define USBEndpointDescriptor_MAXISOCHRONOUSSIZE_HS 1024
/** @}*/
/** \addtogroup usb_ep_addr USB Endpoint address define
* @{
* This section lists macro for USB endpoint address definition.
* - \ref USBEndpointDescriptor_ADDRESS
*/
/**
* Calculates the address of an endpoint given its number and direction
* \param direction USB endpoint direction definition
* \param number USB endpoint number
* \return The value used to set the endpoint descriptor based on input number
* and direction
*/
#define USBEndpointDescriptor_ADDRESS(direction, number) \
(((direction & 0x01) << 7) | (number & 0xF))
/** @}*/
/** @}*/
/*--------- Generic Descriptors --------*/
/** \addtogroup usb_string_descriptor USB String Descriptor Definitions
* @{
* This section lists the codes and macros for USB string descriptor definition.
*
* \par Language IDs
* - USBStringDescriptor_ENGLISH_US
*
* \par String Descriptor Length
* - USBStringDescriptor_LENGTH
*
* \par ASCII to UNICODE convertion
* - USBStringDescriptor_UNICODE
*/
/** Language ID for US english. */
#define USBStringDescriptor_ENGLISH_US 0x09, 0x04
/**
* Calculates the length of a string descriptor given the number of ascii
* characters/language IDs in it.
* \param length The ascii format string length.
* \return The actual data length in bytes.
*/
#define USBStringDescriptor_LENGTH(length) ((length) * 2 + 2)
/**
* Converts an ascii character to its unicode representation.
* \param ascii The ASCII character to convert
* \return A 2-byte-array for the UNICODE based on given ASCII
*/
#define USBStringDescriptor_UNICODE(ascii) (ascii), 0
/** @}*/
/*---------------------------------------------------------------------------
* Types
*---------------------------------------------------------------------------*/
/*
* Function types
*/
typedef uint32_t (*USBDescriptorParseFunction)(void *descriptor, void *parseArg);
/*
* Descriptor structs types
*/
#pragma pack(1)
#if defined ( __CC_ARM ) /* Keil ¦ÌVision 4 */
#elif defined ( __ICCARM__ ) /* IAR Ewarm */
#define __attribute__(...)
#define __packed__ packed
#elif defined ( __GNUC__ ) /* GCC CS3 */
#define __packed__ aligned(1)
#endif
/**
\typedef USBGenericDescriptor
\brief Holds the few fields shared by all USB descriptors.
*/
typedef struct _USBGenericDescriptor {
/** Length of the descriptor in bytes. */
uint8_t bLength;
/** Descriptor type. */
uint8_t bDescriptorType;
} __attribute__ ((__packed__)) USBGenericDescriptor; /* GCC */
/**
* \typedef USBDeviceDescriptor
* \brief USB standard device descriptor structure.
*/
typedef struct _USBDeviceDescriptor {
/** Size of this descriptor in bytes. */
uint8_t bLength;
/** Descriptor type (USBGenericDescriptor_DEVICE). */
uint8_t bDescriptorType;
/** USB specification release number in BCD format. */
uint16_t bcdUSB;
/** Device class code. */
uint8_t bDeviceClass;
/** Device subclass code. */
uint8_t bDeviceSubClass;
/** Device protocol code. */
uint8_t bDeviceProtocol;
/** Maximum packet size of endpoint 0 (in bytes). */
uint8_t bMaxPacketSize0;
/** Vendor ID. */
uint16_t idVendor;
/** Product ID. */
uint16_t idProduct;
/** Device release number in BCD format. */
uint16_t bcdDevice;
/** Index of the manufacturer string descriptor. */
uint8_t iManufacturer;
/** Index of the product string descriptor. */
uint8_t iProduct;
/** Index of the serial number string descriptor. */
uint8_t iSerialNumber;
/** Number of possible configurations for the device. */
uint8_t bNumConfigurations;
} __attribute__ ((__packed__)) USBDeviceDescriptor; /* GCC */
/**
* \typedef USBOtgDescriptor
* \brief USB On-The-Go descriptor struct.
*/
typedef struct _USBOtgDescriptor {
/** Size of this descriptor in bytes. */
uint8_t bLength;
/** Descriptor type (USBGenericDescriptor_OTG). */
uint8_t bDescriptorType;
/** Attribute Fields D7?: Reserved D1: HNP support D0: SRP support */
uint8_t bmAttributes;
} __attribute__ ((__packed__)) USBOtgDescriptor; /* GCC */
/**
* \typedef USBDeviceQualifierDescriptor
* \brief Alternate device descriptor indicating the capabilities of the device
* in full-speed, if currently in high-speed; or in high-speed, if it is
* currently in full-speed. Only relevant for devices supporting the
* high-speed mode.
*/
typedef struct _USBDeviceQualifierDescriptor {
/** Size of the descriptor in bytes. */
uint8_t bLength;
/** Descriptor type (USBDESC_DEVICE_QUALIFIER or "USB device types"). */
uint8_t bDescriptorType;
/** USB specification release number (in BCD format). */
uint16_t bcdUSB;
/** Device class code. */
uint8_t bDeviceClass;
/** Device subclass code. */
uint8_t bDeviceSubClass;
/** Device protocol code. */
uint8_t bDeviceProtocol;
/** Maximum packet size of endpoint 0. */
uint8_t bMaxPacketSize0;
/** Number of possible configurations for the device. */
uint8_t bNumConfigurations;
/** Reserved. */
uint8_t bReserved;
} __attribute__ ((__packed__)) USBDeviceQualifierDescriptor; /* GCC */
/**
* \typedef USBConfigurationDescriptor
* \brief USB standard configuration descriptor structure.
*/
typedef struct _USBConfigurationDescriptor {
/** Size of the descriptor in bytes. */
uint8_t bLength;
/** Descriptor type
(USBDESC_CONFIGURATION of \ref usb_desc_type USB Descriptor types). */
uint8_t bDescriptorType;
/** Length of all descriptors returned along with this configuration
descriptor. */
uint16_t wTotalLength;
/** Number of interfaces in this configuration. */
uint8_t bNumInterfaces;
/** Value for selecting this configuration. */
uint8_t bConfigurationValue;
/** Index of the configuration string descriptor. */
uint8_t iConfiguration;
/** Configuration characteristics. */
uint8_t bmAttributes;
/** Maximum power consumption of the device when in this configuration. */
uint8_t bMaxPower;
} __attribute__ ((__packed__)) USBConfigurationDescriptor; /* GCC*/
/**
* \typedef USBInterfaceAssociationDescriptor
* \brief
*/
typedef struct _USBInterfaceAssociationDescriptor {
unsigned char bLength;
unsigned char bDescriptorType;
unsigned char bFirstInterface;
unsigned char bInterfaceCount;
unsigned char bFunctionClass;
unsigned char bFunctionSubClass;
unsigned char bFunctionProtocol;
unsigned char iFunction;
} __attribute__ ((__packed__)) USBInterfaceAssociationDescriptor; /* GCC*/
/**
* \typedef USBInterfaceDescriptor
* \brief USB standard interface descriptor structure.
*/
typedef struct _USBInterfaceDescriptor {
/** Size of the descriptor in bytes. */
uint8_t bLength;
/** Descriptor type (USBGenericDescriptor_INTERFACE). */
uint8_t bDescriptorType;
/** Number of the interface in its configuration. */
uint8_t bInterfaceNumber;
/** Value to select this alternate interface setting. */
uint8_t bAlternateSetting;
/** Number of endpoints used by the inteface (excluding endpoint 0). */
uint8_t bNumEndpoints;
/** Interface class code. */
uint8_t bInterfaceClass;
/** Interface subclass code. */
uint8_t bInterfaceSubClass;
/** Interface protocol code. */
uint8_t bInterfaceProtocol;
/** Index of the interface string descriptor. */
uint8_t iInterface;
} __attribute__ ((__packed__)) USBInterfaceDescriptor; /* GCC */
/**
* \typedef USBEndpointDescriptor
* \brief USB standard endpoint descriptor structure.
*/
typedef struct _USBEndpointDescriptor {
/** Size of the descriptor in bytes. */
uint8_t bLength;
/** Descriptor type (\ref USBGenericDescriptor_ENDPOINT). */
uint8_t bDescriptorType;
/** Address and direction of the endpoint. */
uint8_t bEndpointAddress;
/** Endpoint type and additional characteristics
(for isochronous endpoints). */
uint8_t bmAttributes;
/** Maximum packet size (in bytes) of the endpoint. */
uint16_t wMaxPacketSize;
/** Polling rate of the endpoint. */
uint8_t bInterval;
} __attribute__ ((__packed__)) USBEndpointDescriptor; /* GCC*/
#pragma pack()
/*---------------------------------------------------------------------------
* Exported Functions
*---------------------------------------------------------------------------*/
extern uint32_t USBGenericDescriptor_GetLength(
const USBGenericDescriptor *descriptor);
extern uint8_t USBGenericDescriptor_GetType(
const USBGenericDescriptor *descriptor);
extern USBGenericDescriptor *USBGenericDescriptor_GetNextDescriptor(
const USBGenericDescriptor *descriptor);
extern USBGenericDescriptor *USBGenericDescriptor_Parse(
const USBGenericDescriptor * descriptor,
uint32_t totalLength,
USBDescriptorParseFunction parseFunction,
void * parseArg);
extern uint32_t USBConfigurationDescriptor_GetTotalLength(
const USBConfigurationDescriptor *configuration);
extern uint8_t USBConfigurationDescriptor_GetNumInterfaces(
const USBConfigurationDescriptor *configuration);
extern uint8_t USBConfigurationDescriptor_IsSelfPowered(
const USBConfigurationDescriptor *configuration);
extern void USBConfigurationDescriptor_Parse(
const USBConfigurationDescriptor *configuration,
USBInterfaceDescriptor **interfaces,
USBEndpointDescriptor **endpoints,
USBGenericDescriptor **others);
extern uint8_t USBEndpointDescriptor_GetNumber(
const USBEndpointDescriptor *endpoint);
extern uint8_t USBEndpointDescriptor_GetDirection(
const USBEndpointDescriptor *endpoint);
extern uint8_t USBEndpointDescriptor_GetType(
const USBEndpointDescriptor *endpoint);
extern uint16_t USBEndpointDescriptor_GetMaxPacketSize(
const USBEndpointDescriptor *endpoint);
extern uint8_t USBEndpointDescriptor_GetInterval(
const USBEndpointDescriptor *endpoint);
/** @}*/
/**@}*/
#endif /* #ifndef _USBDESCRIPTORS_H_ */

View File

@ -0,0 +1,209 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
*
* 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 disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
* ----------------------------------------------------------------------------
*/
/**
* \file
*
* \par Purpose
*
* Standard output methods for reporting debug information, warnings and
* errors, which can be easily be turned on/off.
*
* \par Usage
* -# Initialize the debug message port in application, for stdio printf().
* -# Uses the TRACE_DEBUG(), TRACE_INFO(), TRACE_WARNING(), TRACE_ERROR()
* TRACE_FATAL() macros to output traces throughout the program.
* -# Each type of trace has a level : Debug 5, Info 4, Warning 3, Error 2
* and Fatal 1. Disable a group of traces by changing the value of
* TRACE_LEVEL during compilation; traces with a level bigger than TRACE_LEVEL
* are not generated. To generate no trace, use the reserved value 0.
* -# Trace disabling can be static or dynamic. If dynamic disabling is selected
* the trace level can be modified in runtime. If static disabling is selected
* the disabled traces are not compiled.
*
* \par traceLevels Trace level description
* -# TRACE_DEBUG (5): Traces whose only purpose is for debugging the program,
* and which do not produce meaningful information otherwise.
* -# TRACE_INFO (4): Informational trace about the program execution. Should
* enable the user to see the execution flow.
* -# TRACE_WARNING (3): Indicates that a minor error has happened. In most case
* it can be discarded safely; it may even be expected.
* -# TRACE_ERROR (2): Indicates an error which may not stop the program execution,
* but which indicates there is a problem with the code.
* -# TRACE_FATAL (1): Indicates a major error which prevents the program from going
* any further.
*/
#ifndef _USBLIB_TRACE_H
#define _USBLIB_TRACE_H
/*
* Headers
*/
#include <stdio.h>
/*
* Global Definitions
*/
/** Softpack Version */
#define USBLIB_VERSION "0.1"
#define TRACE_LEVEL_DEBUG 5
#define TRACE_LEVEL_INFO 4
#define TRACE_LEVEL_WARNING 3
#define TRACE_LEVEL_ERROR 2
#define TRACE_LEVEL_FATAL 1
#define TRACE_LEVEL_NO_TRACE 0
/* By default, all traces are output except the debug one. */
#if !defined(TRACE_LEVEL)
#define TRACE_LEVEL TRACE_LEVEL_INFO
#endif
/* By default, trace level is static (not dynamic) */
#if !defined(DYN_TRACES)
#define DYN_TRACES 0
#endif
#if defined(NOTRACE)
#error "Error: NOTRACE has to be not defined !"
#endif
#undef NOTRACE
#if (DYN_TRACES==0)
#if (TRACE_LEVEL == TRACE_LEVEL_NO_TRACE)
#define NOTRACE
#endif
#endif
/* ------------------------------------------------------------------------------
* Global Macros
* ------------------------------------------------------------------------------
*/
#ifndef DYNTRACE
#define DYNTRACE 0
#endif
/**
* Outputs a formatted string using 'printf' if the log level is high
* enough. Can be disabled by defining TRACE_LEVEL=0 during compilation.
* \param ... Additional parameters depending on formatted string.
*/
#if defined(NOTRACE)
/* Empty macro */
#define TRACE_DEBUG(...) { }
#define TRACE_INFO(...) { }
#define TRACE_WARNING(...) { }
#define TRACE_ERROR(...) { }
#define TRACE_FATAL(...) { while(1); }
#define TRACE_DEBUG_WP(...) { }
#define TRACE_INFO_WP(...) { }
#define TRACE_WARNING_WP(...) { }
#define TRACE_ERROR_WP(...) { }
#define TRACE_FATAL_WP(...) { while(1); }
#elif (DYN_TRACES == 1)
/* Trace output depends on dwTraceLevel value */
#define TRACE_DEBUG(...) { if (dwTraceLevel >= TRACE_LEVEL_DEBUG) { printf("-D- " __VA_ARGS__); } }
#define TRACE_INFO(...) { if (dwTraceLevel >= TRACE_LEVEL_INFO) { printf("-I- " __VA_ARGS__); } }
#define TRACE_WARNING(...) { if (dwTraceLevel >= TRACE_LEVEL_WARNING) { printf("-W- " __VA_ARGS__); } }
#define TRACE_ERROR(...) { if (dwTraceLevel >= TRACE_LEVEL_ERROR) { printf("-E- " __VA_ARGS__); } }
#define TRACE_FATAL(...) { if (dwTraceLevel >= TRACE_LEVEL_FATAL) { printf("-F- " __VA_ARGS__); while(1); } }
#define TRACE_DEBUG_WP(...) { if (dwTraceLevel >= TRACE_LEVEL_DEBUG) { printf(__VA_ARGS__); } }
#define TRACE_INFO_WP(...) { if (dwTraceLevel >= TRACE_LEVEL_INFO) { printf(__VA_ARGS__); } }
#define TRACE_WARNING_WP(...) { if (dwTraceLevel >= TRACE_LEVEL_WARNING) { printf(__VA_ARGS__); } }
#define TRACE_ERROR_WP(...) { if (dwTraceLevel >= TRACE_LEVEL_ERROR) { printf(__VA_ARGS__); } }
#define TRACE_FATAL_WP(...) { if (dwTraceLevel >= TRACE_LEVEL_FATAL) { printf(__VA_ARGS__); while(1); } }
#else
/* Trace compilation depends on TRACE_LEVEL value */
#if (TRACE_LEVEL >= TRACE_LEVEL_DEBUG)
#define TRACE_DEBUG(...) { printf("-D- " __VA_ARGS__); }
#define TRACE_DEBUG_WP(...) { printf(__VA_ARGS__); }
#else
#define TRACE_DEBUG(...) { }
#define TRACE_DEBUG_WP(...) { }
#endif
#if (TRACE_LEVEL >= TRACE_LEVEL_INFO)
#define TRACE_INFO(...) { printf("-I- " __VA_ARGS__); }
#define TRACE_INFO_WP(...) { printf(__VA_ARGS__); }
#else
#define TRACE_INFO(...) { }
#define TRACE_INFO_WP(...) { }
#endif
#if (TRACE_LEVEL >= TRACE_LEVEL_WARNING)
#define TRACE_WARNING(...) { printf("-W- " __VA_ARGS__); }
#define TRACE_WARNING_WP(...) { printf(__VA_ARGS__); }
#else
#define TRACE_WARNING(...) { }
#define TRACE_WARNING_WP(...) { }
#endif
#if (TRACE_LEVEL >= TRACE_LEVEL_ERROR)
#define TRACE_ERROR(...) { printf("-E- " __VA_ARGS__); }
#define TRACE_ERROR_WP(...) { printf(__VA_ARGS__); }
#else
#define TRACE_ERROR(...) { }
#define TRACE_ERROR_WP(...) { }
#endif
#if (TRACE_LEVEL >= TRACE_LEVEL_FATAL)
#define TRACE_FATAL(...) { printf("-F- " __VA_ARGS__); while(1); }
#define TRACE_FATAL_WP(...) { printf(__VA_ARGS__); while(1); }
#else
#define TRACE_FATAL(...) { while(1); }
#define TRACE_FATAL_WP(...) { while(1); }
#endif
#endif
/**
* Exported variables
*/
/** Depending on DYN_TRACES, dwTraceLevel is a modifable runtime variable or a define */
#if !defined(NOTRACE) && (DYN_TRACES == 1)
extern uint32_t dwTraceLevel ;
#endif
#endif /* #ifndef _USBLIB_TRACE_H */

View File

@ -0,0 +1,81 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2010, Atmel Corporation
*
* 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 disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
* ----------------------------------------------------------------------------
*/
/** \file
* Definitions for USB Lib compiling.
*/
#ifndef USBLIB_TYPES_H
#define USBLIB_TYPES_H
/*----------------------------------------------------------------------------
* Includes
*----------------------------------------------------------------------------*/
#include <stdint.h>
/*----------------------------------------------------------------------------
* Defines
*----------------------------------------------------------------------------*/
/* Define WEAK attribute */
#ifndef WEAK
#if defined ( __CC_ARM )
#define WEAK __attribute__ ((weak))
#elif defined ( __ICCARM__ )
#define WEAK __weak
#elif defined ( __GNUC__ )
#define WEAK __attribute__ ((weak))
#endif
#endif
/** USB status ReturnCode */
typedef enum _USBRC {
USBRC_OK = 0, /**< Operation was successful */
USBRC_SUCCESS = 0, /**< Operation was successful */
/* Bool codes */
USBRC_FALSE = 0, /**< As boolean TRUE */
USBRC_TRUE = 1, /**< As boolean FALSE */
/* Error codes */
USBRC_BUSY, /**< EP/Device is already busy */
USBRC_ABORTED, /**< Operation aborted due to error or stall */
USBRC_CANCELED, /**< Operation canceled by user */
USBRC_RESET, /**< Operation aborted due to init/reset/un-configure */
USBRC_PARTIAL_DONE,/**< Part of operation successfully done */
USBRC_FINISHED, /**< All operation successfully done and terminate */
USBRC_PARAM_ERR, /**< Failed due to parameter error */
USBRC_STATE_ERR, /**< Failed due to state error */
USBRC_ERROR, /**< General error */
USBRC_SW_NOT_SUPPORTED = 0xFD, /**< Failed due to SW not supported */
USBRC_HW_NOT_SUPPORTED = 0xFE /**< Failed due to HW not supported */
} USBRC;
#endif /* #define USBLIB_TYPES_H */

View File

@ -0,0 +1,354 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2010, Atmel Corporation
*
* 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 disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
* ----------------------------------------------------------------------------
*/
/** \file
* \section Purpose
*
* Definitions and methods for USB request structures described by the
* USB specification.
*
* \section Usage
*
*/
#ifndef _USBREQUESTS_H_
#define _USBREQUESTS_H_
/** \addtogroup usb_general
* @{
* \addtogroup usb_request USB Requests
* @{
*/
/*---------------------------------------------------------------------------
* Headers
*---------------------------------------------------------------------------*/
/* These headers were introduced in C99 by working group
* ISO/IEC JTC1/SC22/WG14.
*/
#include <stdint.h>
/*---------------------------------------------------------------------------
* Definitions
*---------------------------------------------------------------------------*/
/*----------- Generic Request ------------*/
/** \addtogroup usb_request_define USB Generic Request definitions
* @{
* This section lists the codes of USB generic request.
*
* - \ref usb_request_code USB Request codes
* - \ref USBGenericRequest_GETSTATUS
* - \ref USBGenericRequest_CLEARFEATURE
* - \ref USBGenericRequest_SETFEATURE
* - \ref USBGenericRequest_SETADDRESS
* - \ref USBGenericRequest_GETDESCRIPTOR
* - \ref USBGenericRequest_SETDESCRIPTOR
* - \ref USBGenericRequest_GETCONFIGURATION
* - \ref USBGenericRequest_SETCONFIGURATION
* - \ref USBGenericRequest_GETINTERFACE
* - \ref USBGenericRequest_SETINTERFACE
* - \ref USBGenericRequest_SYNCHFRAME
*
* - \ref usb_request_recipient USB Request Recipients
* - \ref USBGenericRequest_DEVICE
* - \ref USBGenericRequest_INTERFACE
* - \ref USBGenericRequest_ENDPOINT
* - \ref USBGenericRequest_OTHER
*
* - \ref usb_request_type USB Request Types
* - \ref USBGenericRequest_STANDARD
* - \ref USBGenericRequest_CLASS
* - \ref USBGenericRequest_VENDOR
*
* - \ref usb_request_dir USB Request Directions
* - \ref USBGenericRequest_IN
* - \ref USBGenericRequest_OUT
*/
/** \addtogroup usb_request_code USB Request codes
* @{
* This section lists the USB generic request codes.
* - \ref USBGenericRequest_GETSTATUS
* - \ref USBGenericRequest_CLEARFEATURE
* - \ref USBGenericRequest_SETFEATURE
* - \ref USBGenericRequest_SETADDRESS
* - \ref USBGenericRequest_GETDESCRIPTOR
* - \ref USBGenericRequest_SETDESCRIPTOR
* - \ref USBGenericRequest_GETCONFIGURATION
* - \ref USBGenericRequest_SETCONFIGURATION
* - \ref USBGenericRequest_GETINTERFACE
* - \ref USBGenericRequest_SETINTERFACE
* - \ref USBGenericRequest_SYNCHFRAME
*/
/** GET_STATUS request code. */
#define USBGenericRequest_GETSTATUS 0
/** CLEAR_FEATURE request code. */
#define USBGenericRequest_CLEARFEATURE 1
/** SET_FEATURE request code. */
#define USBGenericRequest_SETFEATURE 3
/** SET_ADDRESS request code. */
#define USBGenericRequest_SETADDRESS 5
/** GET_DESCRIPTOR request code. */
#define USBGenericRequest_GETDESCRIPTOR 6
/** SET_DESCRIPTOR request code. */
#define USBGenericRequest_SETDESCRIPTOR 7
/** GET_CONFIGURATION request code. */
#define USBGenericRequest_GETCONFIGURATION 8
/** SET_CONFIGURATION request code. */
#define USBGenericRequest_SETCONFIGURATION 9
/** GET_INTERFACE request code. */
#define USBGenericRequest_GETINTERFACE 10
/** SET_INTERFACE request code. */
#define USBGenericRequest_SETINTERFACE 11
/** SYNCH_FRAME request code. */
#define USBGenericRequest_SYNCHFRAME 12
/** @}*/
/** \addtogroup usb_request_recipient USB Request Recipients
* @{
* This section lists codes of USB request recipients.
* - \ref USBGenericRequest_DEVICE
* - \ref USBGenericRequest_INTERFACE
* - \ref USBGenericRequest_ENDPOINT
* - \ref USBGenericRequest_OTHER
*/
/** Recipient is the whole device. */
#define USBGenericRequest_DEVICE 0
/** Recipient is an interface. */
#define USBGenericRequest_INTERFACE 1
/** Recipient is an endpoint. */
#define USBGenericRequest_ENDPOINT 2
/** Recipient is another entity. */
#define USBGenericRequest_OTHER 3
/** @}*/
/** \addtogroup usb_request_type USB Request Types
* @{
* This section lists codes of USB request types.
* - \ref USBGenericRequest_STANDARD
* - \ref USBGenericRequest_CLASS
* - \ref USBGenericRequest_VENDOR
*/
/** Request is standard. */
#define USBGenericRequest_STANDARD 0
/** Request is class-specific. */
#define USBGenericRequest_CLASS 1
/** Request is vendor-specific. */
#define USBGenericRequest_VENDOR 2
/** @}*/
/** \addtogroup usb_request_dir USB Request Directions
* @{
* This section lists codes of USB request directions.
* - \ref USBGenericRequest_IN
* - \ref USBGenericRequest_OUT
*/
/** Transfer occurs from device to the host. */
#define USBGenericRequest_OUT 0
/** Transfer occurs from the host to the device. */
#define USBGenericRequest_IN 1
/** @}*/
/** @}*/
/*----------- Feature Request ------------*/
/** \addtogroup usb_feature_def USB Feature Request Definitions
* @{
* This section lists codes of USB Feature Request
*
* - \ref usb_feature_sel USB Feature selectors
* - \ref USBFeatureRequest_ENDPOINTHALT
* - \ref USBFeatureRequest_DEVICEREMOTEWAKEUP
* - \ref USBFeatureRequest_TESTMODE
*
* - \ref usb_test_sel USB Test mode selectors
* - \ref USBFeatureRequest_TESTJ
* - \ref USBFeatureRequest_TESTK
* - \ref USBFeatureRequest_TESTSE0NAK
* - \ref USBFeatureRequest_TESTPACKET
* - \ref USBFeatureRequest_TESTFORCEENABLE
* - \ref USBFeatureRequest_TESTSENDZLP
*/
/** \addtogroup usb_feature_sel USB Feature selectors
* @{
* This section lists codes of USB feature selectors.
* - \ref USBFeatureRequest_ENDPOINTHALT
* - \ref USBFeatureRequest_DEVICEREMOTEWAKEUP
* - \ref USBFeatureRequest_TESTMODE
*/
/** Halt feature of an endpoint. */
#define USBFeatureRequest_ENDPOINTHALT 0
/** Remote wake-up feature of the device. */
#define USBFeatureRequest_DEVICEREMOTEWAKEUP 1
/** Test mode of the device. */
#define USBFeatureRequest_TESTMODE 2
/** OTG set feature */
#define USBFeatureRequest_OTG 0x0B
/** OTG b_hnp_enable */
#define USBFeatureRequest_OTG_B_HNP_ENABLE 3
/** OTG a_hnp_support */
#define USBFeatureRequest_OTG_A_HNP_SUPPORT 4
/** OTG a_alt_hnp_support */
#define USBFeatureRequest_OTG_A_ALT_HNP_SUPPORT 5
/** @}*/
/** \addtogroup usb_test_sel USB Test mode selectors
* @{
* This section lists codes of USB high speed test mode selectors.
* - \ref USBFeatureRequest_TESTJ
* - \ref USBFeatureRequest_TESTK
* - \ref USBFeatureRequest_TESTSE0NAK
* - \ref USBFeatureRequest_TESTPACKET
* - \ref USBFeatureRequest_TESTFORCEENABLE
* - \ref USBFeatureRequest_TESTSENDZLP
*/
/** Tests the high-output drive level on the D+ line. */
#define USBFeatureRequest_TESTJ 1
/** Tests the high-output drive level on the D- line. */
#define USBFeatureRequest_TESTK 2
/** Tests the output impedance, low-level output voltage and loading
characteristics. */
#define USBFeatureRequest_TESTSE0NAK 3
/** Tests rise and fall times, eye patterns and jitter. */
#define USBFeatureRequest_TESTPACKET 4
/** Tests the hub disconnect detection. */
#define USBFeatureRequest_TESTFORCEENABLE 5
/** Send a ZLP in Test Mode. */
#define USBFeatureRequest_TESTSENDZLP 6
/** @}*/
/** @}*/
/*---------------------------------------------------------------------------
* Types
*---------------------------------------------------------------------------*/
/*
* Function types
*/
/*
* Descriptor structs types
*/
#pragma pack(1)
#if defined ( __CC_ARM ) /* Keil ¦ÌVision 4 */
#elif defined ( __ICCARM__ ) /* IAR Ewarm 5.41+ */
#define __attribute__(...)
#elif defined ( __GNUC__ ) /* GCC CS3 2009q3-68 */
#endif
/**
* Generic USB SETUP request sent over Control endpoints.
*/
typedef struct {
/** Type of request
* \sa usb_request_recipient "USB Request Recipients"
* \sa usb_request_type "USB Request Types"
* \sa usb_request_dir "USB Request Directions" */
uint8_t bmRequestType:8;
/** Request code
* \sa usb_request_code "USB Request Codes" */
uint8_t bRequest:8;
/** Request-specific value parameter. */
uint16_t wValue:16;
/** Request-specific index parameter. */
uint16_t wIndex:16;
/** Expected length (in bytes) of the data phase. */
uint16_t wLength:16;
} USBGenericRequest;
#pragma pack()
/*---------------------------------------------------------------------------
* Exported Functions
*---------------------------------------------------------------------------*/
extern uint8_t USBGenericRequest_GetType(
const USBGenericRequest *request);
extern uint8_t USBGenericRequest_GetRequest(
const USBGenericRequest *request);
extern uint16_t USBGenericRequest_GetValue(
const USBGenericRequest *request);
extern uint16_t USBGenericRequest_GetIndex(
const USBGenericRequest *request);
extern uint16_t USBGenericRequest_GetLength(
const USBGenericRequest *request);
extern uint8_t USBGenericRequest_GetEndpointNumber(
const USBGenericRequest *request);
extern uint8_t USBGenericRequest_GetRecipient(
const USBGenericRequest *request);
extern uint8_t USBGenericRequest_GetDirection(
const USBGenericRequest *request);
extern uint8_t USBGetDescriptorRequest_GetDescriptorType(
const USBGenericRequest *request);
extern uint8_t USBGetDescriptorRequest_GetDescriptorIndex(
const USBGenericRequest *request);
extern uint8_t USBSetAddressRequest_GetAddress(
const USBGenericRequest *request);
extern uint8_t USBSetConfigurationRequest_GetConfiguration(
const USBGenericRequest *request);
extern uint8_t USBInterfaceRequest_GetInterface(
const USBGenericRequest *request);
extern uint8_t USBInterfaceRequest_GetAlternateSetting(
const USBGenericRequest *request);
extern uint8_t USBFeatureRequest_GetFeatureSelector(
const USBGenericRequest *request);
extern uint8_t USBFeatureRequest_GetTestSelector(
const USBGenericRequest *request);
/** @}*/
/**@}*/
#endif /* #ifndef _USBREQUESTS_H_ */

View File

@ -0,0 +1,100 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2010, Atmel Corporation
*
* 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 disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
* ----------------------------------------------------------------------------
*/
/**
* \file usb.h
*
* Definition of SAM9XX5-EK usb library
*
*/
#ifndef _usb_
#define _usb_
/*----------------------------------------------------------------------------
* Headers
*----------------------------------------------------------------------------*/
#include "board.h"
#include "include/USBD.h"
#include "include/USBD_HAL.h"
#include "include/USBDescriptors.h"
#include "include/USBDDriver.h"
#include "include/AUDDescriptors.h"
#include "include/AUDDFunction.h"
#include "include/AUDDSpeakerDriver.h"
#include "include/AUDDSpeakerPhone.h"
#include "include/AUDDSpeakerPhoneDriver.h"
#include "include/AUDDStream.h"
#include "include/AUDRequests.h"
#include "include/CDCAUDDDriver.h"
#include "include/CDCDescriptors.h"
#include "include/CDCDSerial.h"
#include "include/CDCDSerialDriver.h"
#include "include/CDCDSerialPort.h"
#include "include/CDCHIDDDriver.h"
#include "include/CDCMSDDriver.h"
#include "include/CDCNotifications.h"
#include "include/CDCRequests.h"
#include "include/DUALCDCDDriver.h"
#include "include/HIDAUDDDriver.h"
#include "include/HIDDescriptors.h"
#include "include/HIDDFunction.h"
#include "include/HIDDKeyboard.h"
#include "include/HIDDKeyboardDriver.h"
#include "include/HIDDMouseDriver.h"
#include "include/HIDDTransferDriver.h"
#include "include/HIDMSDDriver.h"
#include "include/HIDReports.h"
#include "include/HIDRequests.h"
#include "include/HIDUsages.h"
#include "include/MSD.h"
#include "include/MSDDriver.h"
#include "include/MSDDStateMachine.h"
#include "include/MSDescriptors.h"
#include "include/MSDFunction.h"
#include "include/MSDIOFifo.h"
#include "include/MSDLun.h"
#include "include/SBC.h"
#include "include/SBCMethods.h"
#include "include/USBVideo.h"
#include "include/USBLib_Types.h"
#include "include/USBRequests.h"
#endif /* #ifndef _usb_ */

View File

@ -113,7 +113,7 @@ static void prvCDCInit( void );
* Handler installed on the VBUS pin to detect connect() and disconnect()
* events.
*/
static void prvVBusISRHandler( const Pin *pxPin );
static void prvVBusISRHandler( void );
/*
* USB handler defined by the driver, installed after the CDC driver has been
@ -387,14 +387,12 @@ const TickType_t xTransferCompleteDelay = pdMS_TO_TICKS( 750UL );
}
/*-----------------------------------------------------------*/
static void prvVBusISRHandler( const Pin *pxPin )
static void prvVBusISRHandler( void )
{
/* NOTE: As this was written for the XPlained board, which is powered
through the USB and cannot be on without the USB connected, this function
has not been exercised. */
const Pin xVBusPin = PIN_USB_VBUS;
/* Check current level on VBus to detect a connect/disconnect. */
if( PIO_Get( pxPin ) != 0 )
if( PIO_Get( &xVBusPin ) != 0 )
{
USBD_Connect();
}
@ -454,16 +452,29 @@ BaseType_t xHigherPriorityTaskWoken = pdFALSE;
static void prvConfigureVBus( void )
{
const Pin xVBusPin = PIN_USB_VBUS;
const uint32_t ulPriority = 7; /* Highest. */
/* Configure PIO to generate an interrupt on status change. */
PIO_Configure( &xVBusPin, 1 );
PIO_ConfigureIt( &xVBusPin, prvVBusISRHandler );
PIO_Configure( &xVBusPin, 1 );
PIO_ConfigureIt( &xVBusPin );
/* Ensure interrupt is disabled before setting the mode and installing the
handler. The priority of the tick interrupt should always be set to the
lowest possible. */
AIC->AIC_SSR = ID_PIOE;
AIC->AIC_IDCR = AIC_IDCR_INTD;
AIC->AIC_SMR = AIC_SMR_SRCTYPE_EXT_POSITIVE_EDGE | ulPriority;
AIC->AIC_SVR = ( uint32_t ) prvVBusISRHandler;
/* Start with the interrupt clear. */
AIC->AIC_ICCR = AIC_ICCR_INTCLR;
PIO_EnableIt( &xVBusPin );
AIC_EnableIT( ID_PIOE );
/* Check current level on VBus */
if( PIO_Get( &xVBusPin ) != pdFALSE )
{
/* if VBUS present, force the connect */
/* If VBUS present, force the connect */
USBD_Connect();
}
else
@ -479,8 +490,7 @@ void USBDCallbacks_Initialized( void )
the USB driver has been initialised. By default, configures the UDP/UDPHS
interrupt. The interrupt priority is set to the highest to ensure the
interrupt nesting tests interfer as little as possible with the USB. */
IRQ_ConfigureIT( ID_UDPHS, 7, USBD_IrqHandler );
IRQ_EnableIT( ID_UDPHS );
AIC_EnableIT( ID_UDPHS );
}
/*-----------------------------------------------------------*/

View File

@ -86,8 +86,8 @@
#define configUSE_IDLE_HOOK 1
#define configUSE_TICK_HOOK 1
#define configMAX_PRIORITIES ( 5 )
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 100 )
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 42 * 1024 ) )
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 120 )
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 38 * 1024 ) )
#define configMAX_TASK_NAME_LEN ( 10 )
#define configUSE_TRACE_FACILITY 1
#define configUSE_16_BIT_TICKS 0
@ -129,9 +129,9 @@ readable ASCII form. See the notes in the implementation of vTaskList() within
FreeRTOS/Source/tasks.c for limitations. */
#define configUSE_STATS_FORMATTING_FUNCTIONS 1
/* Cortex-A specific setting: FPU has 16 (rather than 32) d registers. See:
/* Cortex-A specific setting: FPU has 32 (rather than 16) d registers. See:
http://www.FreeRTOS.org/Using-FreeRTOS-on-Cortex-A-MPUs-without-a-GIC.html */
#define configFPU_D32 0
#define configFPU_D32 1
/* Cortex-A specific setting: The address of the register within the interrupt
controller from which the address of the current interrupt's handling function
@ -159,10 +159,10 @@ used. */
the need to use a separate timer for that purpose. The 20KHz timer
increments ulHighFrequencyTimerCounts, which is used as the time base.
Therefore the following macro is not implemented. */
#define configGENERATE_RUN_TIME_STATS 0
//_RB_ extern volatile uint32_t ulHighFrequencyTimerCounts;
//_RB_ #define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS()
//_RB_ #define portGET_RUN_TIME_COUNTER_VALUE() ulHighFrequencyTimerCounts
#define configGENERATE_RUN_TIME_STATS 1
extern volatile uint32_t ulHighFrequencyTimerCounts;
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS()
#define portGET_RUN_TIME_COUNTER_VALUE() ulHighFrequencyTimerCounts
/* The size of the global output buffer that is available for use when there
are multiple command interpreters running at once (for example, one on a UART

View File

@ -99,31 +99,6 @@ static void System_Handler( void )
* in FreeRTOSConfig.h to call the function. This file contains a function
* that is suitable for use on the Atmel SAMA5.
*/
/*_RB_*/
uint32_t IRQ_ConfigureIT(uint32_t source,
uint32_t mode,
void( *handler )( void ));
uint32_t IRQ_ConfigureIT(uint32_t source,
uint32_t mode,
void( *handler )( void ))
{
uint32_t prevHandler;
PMC->PMC_PCER1 = (1 << ( ID_IRQ - 32));
AIC->AIC_SSR = source;
prevHandler = AIC->AIC_SVR;
/* Disable the interrupt first */
AIC->AIC_IDCR = AIC_IDCR_INTD;
/* Configure mode and handler */
AIC->AIC_SMR = mode;
AIC->AIC_SVR = (uint32_t) handler;
/* Clear interrupt */
AIC->AIC_ICCR = AIC_ICCR_INTCLR;
return prevHandler;
}
void vConfigureTickInterrupt( void )
{
/* NOTE: The PIT interrupt is cleared by the configCLEAR_TICK_INTERRUPT()
@ -135,18 +110,25 @@ void vConfigureTickInterrupt( void )
/* Initialize the PIT to the desired frequency - specified in uS. */
PIT_Init( 1000000UL / configTICK_RATE_HZ, ( BOARD_MCK / 2 ) / 1000000 );
/* Configure interrupt on PIT. Note this is on the system interrupt, which
is shared with other system peripherals, so System_Handler() must be
installed in place of FreeRTOS_Tick_Handler() if other system handlers are
required. The tick must be given the lowest priority (0 in the SAMA5 AIC) */
IRQ_ConfigureIT( ID_PIT, 0, FreeRTOS_Tick_Handler );
/* See commend directly above IRQ_ConfigureIT( ID_PIT, 0, System_Handler ); */
//_RB_ IRQ_EnableIT( ID_PIT );
AIC_EnableIT( ID_PIT );
/* Enable IRQ / select PIT interrupt. */
PMC->PMC_PCER1 = ( 1 << ( ID_IRQ - 32 ) );
AIC->AIC_SSR = ID_PIT;
/* Ensure interrupt is disabled before setting the mode and installing the
handler. The priority of the tick interrupt should always be set to the
lowest possible. */
AIC->AIC_IDCR = AIC_IDCR_INTD;
AIC->AIC_SMR = AIC_SMR_SRCTYPE_EXT_POSITIVE_EDGE;
AIC->AIC_SVR = ( uint32_t ) FreeRTOS_Tick_Handler;
/* Start with the interrupt clear. */
AIC->AIC_ICCR = AIC_ICCR_INTCLR;
/* Enable the interrupt in the AIC and peripheral. */
AIC_EnableIT( ID_PIT );
PIT_EnableIT();
/* Enable the pit. */
/* Enable the peripheral. */
PIT_Enable();
/* Prevent compiler warnings in the case where System_Handler() is not used

View File

@ -111,7 +111,7 @@ code. */
/* The high frequency interrupt given the highest priority or all. The priority
of the lower frequency timers must still be above the tick interrupt priority. */
#define tmrLOWER_PRIORITY 1
#define tmrLOWER_PRIORITY 3
#define tmrHIGHER_PRIORITY 5
/*-----------------------------------------------------------*/
@ -136,32 +136,48 @@ void vInitialiseTimerForIntQueueTest( void )
const uint32_t ulDivider = 128UL, ulTCCLKS = 3UL;
/* Enable the TC clocks. */
PMC->PMC_PCER0 = 1 << ID_TC0;
PMC->PMC_PCER0 = 1 << ID_TC1;
PMC_EnablePeripheral( ID_TC0 );
PMC_EnablePeripheral( ID_TC1 );
/* Configure TC0 channel 0 for a tmrTIMER_0_FREQUENCY frequency and trigger
on RC compare. */
on RC compare. This is part of the IntQTimer test. */
TC_Configure( TC0, tmrTC0_CHANNEL_0, ulTCCLKS | TC_CMR_CPCTRG );
TC0->TC_CHANNEL[ tmrTC0_CHANNEL_0 ].TC_RC = BOARD_MCK / ( tmrTIMER_0_FREQUENCY * ulDivider );
TC0->TC_CHANNEL[ tmrTC0_CHANNEL_0 ].TC_RC = ( BOARD_MCK / 2 ) / ( tmrTIMER_0_FREQUENCY * ulDivider );
TC0->TC_CHANNEL[ tmrTC0_CHANNEL_0 ].TC_IER = TC_IER_CPCS;
/* Configure TC0 channel 1 for a tmrTIMER_1_FREQUENCY frequency and trigger
on RC compare. */
on RC compare. This is part of the IntQTimer test. */
TC_Configure( TC0, tmrTC0_CHANNEL_1, ulTCCLKS | TC_CMR_CPCTRG );
TC0->TC_CHANNEL[ tmrTC0_CHANNEL_1 ].TC_RC = BOARD_MCK / ( tmrTIMER_1_FREQUENCY * ulDivider );
TC0->TC_CHANNEL[ tmrTC0_CHANNEL_1 ].TC_RC = ( BOARD_MCK / 2 ) / ( tmrTIMER_1_FREQUENCY * ulDivider );
TC0->TC_CHANNEL[ tmrTC0_CHANNEL_1 ].TC_IER = TC_IER_CPCS;
/* Configure TC1 channel 0 tmrTIMER_2_FREQUENCY frequency and trigger on
RC compare. */
RC compare. This is the very high frequency timer. */
TC_Configure( TC1, tmrTC1_CHANNEL_0, ulTCCLKS | TC_CMR_CPCTRG );
TC1->TC_CHANNEL[ tmrTC1_CHANNEL_0 ].TC_RC = BOARD_MCK / ( tmrTIMER_2_FREQUENCY * ulDivider );
TC1->TC_CHANNEL[ tmrTC1_CHANNEL_0 ].TC_IER = TC_IER_CPCS;
/* Enable interrupts and start the timers. */
IRQ_ConfigureIT( ID_TC0, tmrLOWER_PRIORITY, prvTC0_Handler );
IRQ_ConfigureIT( ID_TC1, tmrHIGHER_PRIORITY, prvTC1_Handler );
IRQ_EnableIT( ID_TC0 );
IRQ_EnableIT( ID_TC1 );
/* First setup TC0 interrupt, in which two channels are used. */
AIC->AIC_SSR = ID_TC0;
/* Ensure the interrupt is disabled before setting mode and handler. */
AIC->AIC_IDCR = AIC_IDCR_INTD;
AIC->AIC_SMR = AIC_SMR_SRCTYPE_EXT_POSITIVE_EDGE | tmrLOWER_PRIORITY;
AIC->AIC_SVR = ( uint32_t ) prvTC0_Handler;
/* Start with the interrupt clear. */
AIC->AIC_ICCR = AIC_ICCR_INTCLR;
/* Do the same for TC1 - which is the high frequency timer. */
AIC->AIC_SSR = ID_TC1;
AIC->AIC_IDCR = AIC_IDCR_INTD;
AIC->AIC_SMR = AIC_SMR_SRCTYPE_EXT_POSITIVE_EDGE | tmrHIGHER_PRIORITY;
AIC->AIC_SVR = ( uint32_t ) prvTC1_Handler;
AIC->AIC_ICCR = AIC_ICCR_INTCLR;
/* Finally enable the interrupts and start the timers. */
AIC_EnableIT( ID_TC0 );
AIC_EnableIT( ID_TC1 );
TC_Start( TC0, tmrTC0_CHANNEL_0 );
TC_Start( TC0, tmrTC0_CHANNEL_1 );
TC_Start( TC1, tmrTC1_CHANNEL_0 );
@ -170,16 +186,28 @@ const uint32_t ulDivider = 128UL, ulTCCLKS = 3UL;
static void prvTC0_Handler( void )
{
/* Read will clear the status bit. */
if( ( TC0->TC_CHANNEL[ tmrTC0_CHANNEL_0 ].TC_SR & tmrRC_COMPARE ) != 0 )
{
portYIELD_FROM_ISR( xFirstTimerHandler() );
}
uint32_t ulDidSomething;
if( ( TC0->TC_CHANNEL[ tmrTC0_CHANNEL_1 ].TC_SR & tmrRC_COMPARE ) != 0 )
do
{
portYIELD_FROM_ISR( xSecondTimerHandler() );
}
ulDidSomething = pdFALSE;
/* Read will clear the status bit. */
if( ( TC0->TC_CHANNEL[ tmrTC0_CHANNEL_0 ].TC_SR & tmrRC_COMPARE ) != 0 )
{
/* Call the IntQ test function for this channel. */
portYIELD_FROM_ISR( xFirstTimerHandler() );
ulDidSomething = pdTRUE;
}
if( ( TC0->TC_CHANNEL[ tmrTC0_CHANNEL_1 ].TC_SR & tmrRC_COMPARE ) != 0 )
{
/* Call the IntQ test function for this channel. */
portYIELD_FROM_ISR( xSecondTimerHandler() );
ulDidSomething = pdTRUE;
}
} while( ulDidSomething == pdTRUE );
}
/*-----------------------------------------------------------*/

View File

@ -86,7 +86,7 @@
*
* "FreeRTOS+CLI command console" - The command console is access using the USB
* CDC driver provided by Atmel. It is accessed through the USB connector
* marked J6 SAMA5D3 Xplained board. Type "help" to see a list of registered
* marked J1 SAMA5D4 Xplained board. Type "help" to see a list of registered
* commands. The FreeRTOS+CLI license is different to the FreeRTOS license, see
* http://www.FreeRTOS.org/cli for license and usage details. The default baud
* rate is 115200.

View File

@ -72,6 +72,8 @@
; mission critical applications that require provable dependability.
;*/
#include "FreeRTOSConfig.h"
EXPORT vRegTest1Implementation
EXPORT vRegTest2Implementation
@ -123,6 +125,23 @@ vRegTest1Implementation
vmov d14, r4, r5
vmov d15, r6, r7
vmov d16, r0, r1
vmov d17, r2, r3
vmov d18, r4, r5
vmov d19, r6, r7
vmov d20, r8, r9
vmov d21, r10, r11
vmov d22, r0, r1
vmov d23, r2, r3
vmov d24, r4, r5
vmov d25, r6, r7
vmov d26, r8, r9
vmov d27, r10, r11
vmov d28, r0, r1
vmov d29, r2, r3
vmov d30, r4, r5
vmov d31, r6, r7
; Loop, checking each itteration that each register still contains the
; expected value.
reg1_loop
@ -214,6 +233,87 @@ reg1_loop
cmp r1, #0x77
bne reg1_error_loopf
vmov r0, r1, d16
cmp r0, #0xFF
bne reg1_error_loopf
cmp r1, #0x11
bne reg1_error_loopf
vmov r0, r1, d17
cmp r0, #0x22
bne reg1_error_loopf
cmp r1, #0x33
bne reg1_error_loopf
vmov r0, r1, d18
cmp r0, #0x44
bne reg1_error_loopf
cmp r1, #0x55
bne reg1_error_loopf
vmov r0, r1, d19
cmp r0, #0x66
bne reg1_error_loopf
cmp r1, #0x77
bne reg1_error_loopf
vmov r0, r1, d20
cmp r0, #0x88
bne reg1_error_loopf
cmp r1, #0x99
bne reg1_error_loopf
vmov r0, r1, d21
cmp r0, #0xAA
bne reg1_error_loopf
cmp r1, #0xBB
bne reg1_error_loopf
vmov r0, r1, d22
cmp r0, #0xFF
bne reg1_error_loopf
cmp r1, #0x11
bne reg1_error_loopf
vmov r0, r1, d23
cmp r0, #0x22
bne reg1_error_loopf
cmp r1, #0x33
bne reg1_error_loopf
vmov r0, r1, d24
cmp r0, #0x44
bne reg1_error_loopf
cmp r1, #0x55
bne reg1_error_loopf
vmov r0, r1, d25
cmp r0, #0x66
bne reg1_error_loopf
cmp r1, #0x77
bne reg1_error_loopf
vmov r0, r1, d26
cmp r0, #0x88
bne reg1_error_loopf
cmp r1, #0x99
bne reg1_error_loopf
vmov r0, r1, d27
cmp r0, #0xAA
bne reg1_error_loopf
cmp r1, #0xBB
bne reg1_error_loopf
vmov r0, r1, d28
cmp r0, #0xFF
bne reg1_error_loopf
cmp r1, #0x11
bne reg1_error_loopf
vmov r0, r1, d29
cmp r0, #0x22
bne reg1_error_loopf
cmp r1, #0x33
bne reg1_error_loopf
vmov r0, r1, d30
cmp r0, #0x44
bne reg1_error_loopf
cmp r1, #0x55
bne reg1_error_loopf
vmov r0, r1, d31
cmp r0, #0x66
bne reg1_error_loopf
cmp r1, #0x77
bne reg1_error_loopf
; Restore the registers that were clobbered by the test.
pop {r0-r1}
@ -317,6 +417,23 @@ vRegTest2Implementation
vmov d14, r4, r5
vmov d15, r6, r7
vmov d16, r0, r1
vmov d17, r2, r3
vmov d18, r4, r5
vmov d19, r6, r7
vmov d20, r8, r9
vmov d21, r10, r11
vmov d22, r0, r1
vmov d23, r2, r3
vmov d24, r4, r5
vmov d25, r6, r7
vmov d26, r8, r9
vmov d27, r10, r11
vmov d28, r0, r1
vmov d29, r2, r3
vmov d30, r4, r5
vmov d31, r6, r7
; Loop, checking each itteration that each register still contains the
; expected value.
reg2_loop
@ -405,6 +522,87 @@ reg2_loop
cmp r1, #0x77000000
bne reg2_error_loopf
vmov r0, r1, d16
cmp r0, #0xFF000000
bne reg2_error_loopf
cmp r1, #0x11000000
bne reg2_error_loopf
vmov r0, r1, d17
cmp r0, #0x22000000
bne reg2_error_loopf
cmp r1, #0x33000000
bne reg2_error_loopf
vmov r0, r1, d18
cmp r0, #0x44000000
bne reg2_error_loopf
cmp r1, #0x55000000
bne reg2_error_loopf
vmov r0, r1, d19
cmp r0, #0x66000000
bne reg2_error_loopf
cmp r1, #0x77000000
bne reg2_error_loopf
vmov r0, r1, d20
cmp r0, #0x88000000
bne reg2_error_loopf
cmp r1, #0x99000000
bne reg2_error_loopf
vmov r0, r1, d21
cmp r0, #0xAA000000
bne reg2_error_loopf
cmp r1, #0xBB000000
bne reg2_error_loopf
vmov r0, r1, d22
cmp r0, #0xFF000000
bne reg2_error_loopf
cmp r1, #0x11000000
bne reg2_error_loopf
vmov r0, r1, d23
cmp r0, #0x22000000
bne reg2_error_loopf
cmp r1, #0x33000000
bne reg2_error_loopf
vmov r0, r1, d24
cmp r0, #0x44000000
bne reg2_error_loopf
cmp r1, #0x55000000
bne reg2_error_loopf
vmov r0, r1, d25
cmp r0, #0x66000000
bne reg2_error_loopf
cmp r1, #0x77000000
bne reg2_error_loopf
vmov r0, r1, d26
cmp r0, #0x88000000
bne reg2_error_loopf
cmp r1, #0x99000000
bne reg2_error_loopf
vmov r0, r1, d27
cmp r0, #0xAA000000
bne reg2_error_loopf
cmp r1, #0xBB000000
bne reg2_error_loopf
vmov r0, r1, d28
cmp r0, #0xFF000000
bne reg2_error_loopf
cmp r1, #0x11000000
bne reg2_error_loopf
vmov r0, r1, d29
cmp r0, #0x22000000
bne reg2_error_loopf
cmp r1, #0x33000000
bne reg2_error_loopf
vmov r0, r1, d30
cmp r0, #0x44000000
bne reg2_error_loopf
cmp r1, #0x55000000
bne reg2_error_loopf
vmov r0, r1, d31
cmp r0, #0x66000000
bne reg2_error_loopf
cmp r1, #0x77000000
bne reg2_error_loopf
; Restore the registers that were clobbered by the test.
pop {r0-r1}
@ -464,5 +662,4 @@ reg2_error_loop
b reg2_error_loop
nop
END

View File

@ -53,7 +53,7 @@
</option>
<option>
<name>RunToEnable</name>
<state>1</state>
<state>0</state>
</option>
<option>
<name>RunToName</name>
@ -1362,7 +1362,7 @@
<debug>1</debug>
<option>
<name>FlashLoadersV3</name>
<state></state>
<state>$TOOLKIT_DIR$\config\flashloader\</state>
</option>
<option>
<name>CInput</name>
@ -1386,7 +1386,7 @@
</option>
<option>
<name>MacFile</name>
<state>$PROJ_DIR$\..\..\..\..\libraries\libboard_sama5d4x-ek\resources\ewarm\sama5d4x-ek-ddram.mac</state>
<state>$PROJ_DIR$\AtmelFiles\libboard_sama5d4x-ek\resources\ewarm\sama5d4x-ek-ddram.mac</state>
</option>
<option>
<name>MemOverride</name>
@ -1394,11 +1394,11 @@
</option>
<option>
<name>MemFile</name>
<state>$TOOLKIT_DIR$\CONFIG\debugger\Atmel\iosama5d4x.ddf</state>
<state></state>
</option>
<option>
<name>RunToEnable</name>
<state>0</state>
<state>1</state>
</option>
<option>
<name>RunToName</name>
@ -1438,7 +1438,7 @@
</option>
<option>
<name>OCLastSavedByProductVersion</name>
<state>6.30.1.53141</state>
<state>7.20.2.7418</state>
</option>
<option>
<name>OCDownloadAttachToProgram</name>

View File

@ -214,7 +214,7 @@
</option>
<option>
<name>CCDiagSuppress</name>
<state></state>
<state>Pa131, Pa039</state>
</option>
<option>
<name>CCDiagRemark</name>
@ -235,7 +235,7 @@
<option>
<name>CCAllowList</name>
<version>1</version>
<state>00000000</state>
<state>11111110</state>
</option>
<option>
<name>CCDebugInfo</name>
@ -306,11 +306,14 @@
<state>$PROJ_DIR$/AtmelFiles/libboard_sama5d4x-ek</state>
<state>$PROJ_DIR$/AtmelFiles/libchip_sama5d4x</state>
<state>$PROJ_DIR$/AtmelFiles/libchip_sama5d4x/include</state>
<state>$PROJ_DIR$\AtmelFiles\usb\device</state>
<state>$PROJ_DIR$\AtmelFiles\usb\include</state>
<state>$PROJ_DIR$/.</state>
<state>$PROJ_DIR$\..\..\Source\include</state>
<state>$PROJ_DIR$\..\..\Source\portable\IAR\ARM_CA5_No_GIC</state>
<state>$PROJ_DIR$\..\Common\include</state>
<state>$PROJ_DIR$\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-CLI</state>
<state>$PROJ_DIR$\Full_Demo</state>
</option>
<option>
<name>CCStdIncCheck</name>
@ -330,7 +333,7 @@
</option>
<option>
<name>CCOptLevel</name>
<state>0</state>
<state>3</state>
</option>
<option>
<name>CCOptStrategy</name>
@ -339,7 +342,7 @@
</option>
<option>
<name>CCOptLevelSlave</name>
<state>0</state>
<state>3</state>
</option>
<option>
<name>CompilerMisraRules98</name>
@ -474,7 +477,6 @@
<name>ADefines</name>
<state>sama5d4x</state>
<state>sram</state>
<state>__ASSEMBLY__</state>
</option>
<option>
<name>AList</name>
@ -970,7 +972,7 @@
<option>
<name>Variant</name>
<version>20</version>
<state>0</state>
<state>48</state>
</option>
<option>
<name>ExePath</name>
@ -1013,11 +1015,11 @@
<option>
<name>FPU</name>
<version>2</version>
<state>5</state>
<state>6</state>
</option>
<option>
<name>OGCoreOrChip</name>
<state>1</state>
<state>0</state>
</option>
<option>
<name>GRuntimeLibSelect</name>
@ -1039,7 +1041,7 @@
</option>
<option>
<name>OGLastSavedByProductVersion</name>
<state>6.30.1.53141</state>
<state>7.20.2.7418</state>
</option>
<option>
<name>GeneralEnableMisra</name>
@ -1051,7 +1053,7 @@
</option>
<option>
<name>OGChipSelectEditMenu</name>
<state>sama5d4x Atmel sama5d4x</state>
<state>Default None</state>
</option>
<option>
<name>GenLowLevelInterface</name>
@ -1090,12 +1092,12 @@
<option>
<name>GFPUCoreSlave</name>
<version>20</version>
<state>47</state>
<state>48</state>
</option>
<option>
<name>GBECoreSlave</name>
<version>20</version>
<state>47</state>
<state>48</state>
</option>
<option>
<name>OGUseCmsis</name>
@ -1166,7 +1168,7 @@
</option>
<option>
<name>CCDiagSuppress</name>
<state></state>
<state>Pa131, Pa039</state>
</option>
<option>
<name>CCDiagRemark</name>
@ -1187,7 +1189,7 @@
<option>
<name>CCAllowList</name>
<version>1</version>
<state>11111110</state>
<state>00000000</state>
</option>
<option>
<name>CCDebugInfo</name>
@ -1255,9 +1257,17 @@
</option>
<option>
<name>CCIncludePath2</name>
<state>$PROJ_DIR$/../../../../libraries</state>
<state>$PROJ_DIR$/../../../../libraries/libboard_sama5d4x-ek</state>
<state>$PROJ_DIR$/../../../../libraries/libchip_sama5d4x</state>
<state>$PROJ_DIR$/AtmelFiles/libboard_sama5d4x-ek</state>
<state>$PROJ_DIR$/AtmelFiles/libchip_sama5d4x</state>
<state>$PROJ_DIR$/AtmelFiles/libchip_sama5d4x/include</state>
<state>$PROJ_DIR$\AtmelFiles\usb\device</state>
<state>$PROJ_DIR$\AtmelFiles\usb\include</state>
<state>$PROJ_DIR$/.</state>
<state>$PROJ_DIR$\..\..\Source\include</state>
<state>$PROJ_DIR$\..\..\Source\portable\IAR\ARM_CA5_No_GIC</state>
<state>$PROJ_DIR$\..\Common\include</state>
<state>$PROJ_DIR$\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-CLI</state>
<state>$PROJ_DIR$\Full_Demo</state>
</option>
<option>
<name>CCStdIncCheck</name>
@ -1277,7 +1287,7 @@
</option>
<option>
<name>CCOptLevel</name>
<state>3</state>
<state>0</state>
</option>
<option>
<name>CCOptStrategy</name>
@ -1286,7 +1296,7 @@
</option>
<option>
<name>CCOptLevelSlave</name>
<state>3</state>
<state>0</state>
</option>
<option>
<name>CompilerMisraRules98</name>
@ -1421,7 +1431,6 @@
<name>ADefines</name>
<state>sama5d4x</state>
<state>ddram</state>
<state>__ASSEMBLY__</state>
</option>
<option>
<name>AList</name>
@ -1518,6 +1527,7 @@
<option>
<name>AUserIncludes</name>
<state>$PROJ_DIR$\..\..\..\libraries</state>
<state>$PROJ_DIR$/.</state>
</option>
<option>
<name>AExtraOptionsCheckV2</name>
@ -1669,7 +1679,7 @@
</option>
<option>
<name>IlinkIcfFile</name>
<state>$PROJ_DIR$/../../../../libraries/libboard_sama5d4x-ek/resources/ewarm/sama5d4x/ddram.icf</state>
<state>$PROJ_DIR$/AtmelFiles\libboard_sama5d4x-ek\resources\ewarm\sama5d4x\ddram.icf</state>
</option>
<option>
<name>IlinkIcfFileSlave</name>
@ -1909,6 +1919,7 @@
<name>$PROJ_DIR$\AtmelFiles\libboard_sama5d4x-ek\source\board_cstartup_iar.s</name>
<excluded>
<configuration>sram</configuration>
<configuration>ddram</configuration>
</excluded>
</file>
<file>
@ -1932,9 +1943,15 @@
<file>
<name>$PROJ_DIR$\AtmelFiles\libchip_sama5d4x\source\aic.c</name>
</file>
<file>
<name>$PROJ_DIR$\AtmelFiles\libchip_sama5d4x\cp15\cp15.c</name>
</file>
<file>
<name>$PROJ_DIR$\AtmelFiles\libchip_sama5d4x\cp15\cp15_asm_iar.s</name>
</file>
<file>
<name>$PROJ_DIR$\AtmelFiles\libchip_sama5d4x\source\mmu.c</name>
</file>
<file>
<name>$PROJ_DIR$\AtmelFiles\libchip_sama5d4x\source\pio.c</name>
</file>
@ -1950,10 +1967,73 @@
<file>
<name>$PROJ_DIR$\AtmelFiles\libchip_sama5d4x\source\tc.c</name>
</file>
<file>
<name>$PROJ_DIR$\AtmelFiles\libchip_sama5d4x\source\USBD_HAL.c</name>
</file>
<file>
<name>$PROJ_DIR$\AtmelFiles\libchip_sama5d4x\source\wdt.c</name>
</file>
</group>
<group>
<name>USB</name>
<group>
<name>common</name>
<group>
<name>cdc</name>
<file>
<name>$PROJ_DIR$\AtmelFiles\usb\common\cdc\CDCLineCoding.c</name>
</file>
<file>
<name>$PROJ_DIR$\AtmelFiles\usb\common\cdc\CDCSetControlLineStateRequest.c</name>
</file>
</group>
<group>
<name>core</name>
<file>
<name>$PROJ_DIR$\AtmelFiles\usb\common\core\USBDescriptors.c</name>
</file>
<file>
<name>$PROJ_DIR$\AtmelFiles\usb\common\core\USBRequests.c</name>
</file>
</group>
</group>
<group>
<name>device</name>
<group>
<name>cdc-serial</name>
<file>
<name>$PROJ_DIR$\AtmelFiles\usb\device\cdc-serial\CDCDSerial.c</name>
</file>
<file>
<name>$PROJ_DIR$\AtmelFiles\usb\device\cdc-serial\CDCDSerial_Callbacks.c</name>
</file>
<file>
<name>$PROJ_DIR$\AtmelFiles\usb\device\cdc-serial\CDCDSerialDriver.c</name>
</file>
<file>
<name>$PROJ_DIR$\AtmelFiles\usb\device\cdc-serial\CDCDSerialPort.c</name>
</file>
</group>
<group>
<name>core</name>
<file>
<name>$PROJ_DIR$\AtmelFiles\usb\device\core\USBD.c</name>
</file>
<file>
<name>$PROJ_DIR$\AtmelFiles\usb\device\core\USBDCallbacks.c</name>
</file>
<file>
<name>$PROJ_DIR$\AtmelFiles\usb\device\core\USBDDriver.c</name>
</file>
<file>
<name>$PROJ_DIR$\AtmelFiles\usb\device\core\USBDDriverCallbacks.c</name>
</file>
</group>
</group>
<file>
<name>$PROJ_DIR$\AtmelFiles\usb\USBDDriverDescriptors.c</name>
</file>
</group>
</group>
<group>
<name>Blinky Demo</name>
@ -2030,9 +2110,6 @@
</file>
<file>
<name>$PROJ_DIR$\..\Common\Minimal\IntQueue.c</name>
<excluded>
<configuration>sram</configuration>
</excluded>
</file>
<file>
<name>$PROJ_DIR$\..\Common\Minimal\QueueOverwrite.c</name>
@ -2049,15 +2126,9 @@
</group>
<file>
<name>$PROJ_DIR$\CDCCommandConsole.c</name>
<excluded>
<configuration>sram</configuration>
</excluded>
</file>
<file>
<name>$PROJ_DIR$\Full_Demo\IntQueueTimer.c</name>
<excluded>
<configuration>sram</configuration>
</excluded>
</file>
<file>
<name>$PROJ_DIR$\Full_Demo\main_full.c</name>
@ -2069,9 +2140,6 @@
<name>$PROJ_DIR$\..\..\..\FreeRTOS-Plus\Demo\Common\FreeRTOS_Plus_CLI_Demos\Sample-CLI-commands.c</name>
</file>
</group>
<file>
<name>$PROJ_DIR$\atmel_main.c</name>
</file>
<file>
<name>$PROJ_DIR$\cstartup_with_FreeRTOS_vectors.s</name>
</file>

View File

@ -44,7 +44,6 @@
// Headers
//------------------------------------------------------------------------------
#define __ASSEMBLY__
//------------------------------------------------------------------------------
// Definitions
@ -82,7 +81,6 @@ MODE_MSK DEFINE 0x1F ; Bit mask for mode bits in CPSR
SECTION .vectors:CODE:NOROOT(2)
PUBLIC resetVector
PUBLIC IRQ_Handler
EXTERN FreeRTOS_IRQ_Handler
EXTERN Undefined_C_Handler
EXTERN FreeRTOS_SWI_Handler
@ -113,50 +111,7 @@ Undefined_Addr: DCD Undefined_C_Handler
SWI_Addr: DCD FreeRTOS_SWI_Handler
Abort_Addr: DCD Abort_C_Handler
Prefetch_Addr: DCD Prefetch_C_Handler
;IRQ_Addr: DCD IRQ_Handler
FIQ_Addr: DCD FIQ_Handler
/*
Handles incoming interrupt requests by branching to the corresponding
handler, as defined in the AIC. Supports interrupt nesting.
*/
IRQ_Handler:
/* Save interrupt context on the stack to allow nesting */
SUB lr, lr, #4
STMFD sp!, {lr}
MRS lr, SPSR
STMFD sp!, {r0, lr}
/* Write in the IVR to support Protect Mode */
LDR lr, =AIC
LDR r0, [r14, #AIC_IVR]
STR lr, [r14, #AIC_IVR]
/* Branch to interrupt handler in Supervisor mode */
MSR CPSR_c, #ARM_MODE_SVC
STMFD sp!, {r1-r3, r4, r12, lr}
/* Check for 8-byte alignment and save lr plus a */
/* word to indicate the stack adjustment used (0 or 4) */
AND r1, sp, #4
SUB sp, sp, r1
STMFD sp!, {r1, lr}
BLX r0
LDMIA sp!, {r1, lr}
ADD sp, sp, r1
LDMIA sp!, {r1-r3, r4, r12, lr}
MSR CPSR_c, #ARM_MODE_IRQ | I_BIT | F_BIT
/* Acknowledge interrupt */
LDR lr, =AIC
STR lr, [r14, #AIC_EOICR]
/* Restore interrupt context and branch back to calling code */
LDMIA sp!, {r0, lr}
MSR SPSR_cxsf, lr
LDMIA sp!, {pc}^
/*

View File

@ -124,19 +124,13 @@ void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
void vApplicationTickHook( void );
/* Prototype for the IRQ handler called by the generic Cortex-A5 RTOS port
layer. The address of the ISR is passed into this function as a parameter.
Note this level of indirection could be removed by creating a SAMA5 specific
port layer that calls the IRQ directly from the port layer rather than via this
application callback. */
void vApplicationIRQHandler( uint32_t ulInterruptVectorAddress );
layer. */
void vApplicationIRQHandler( void );
/*-----------------------------------------------------------*/
int main( void )
{
//extern int atmel_main( void );
//atmel_main();
/* Configure the hardware ready to run the demo. */
prvSetupHardware();
@ -161,13 +155,21 @@ static void prvSetupHardware( void )
/* Disable watchdog */
WDT_Disable( WDT );
/* Set protect mode in the AIC for easier debugging. */
// AIC->AIC_DCR |= AIC_DCR_PROT;
/* Set protect mode in the AIC for easier debugging. THIS IS COMMENTED OUT
AS IT RESULTS IN SPURIOUS INTERRUPTS.
AIC->AIC_DCR |= AIC_DCR_PROT; */
/* Configure ports used by LEDs. */
vParTestInitialise();
//_RB_ CP15_EnableIcache();
#if defined (ddram)
{
MMU_Initialize( ( uint32_t * ) 0x20C000 );
CP15_EnableMMU();
CP15_EnableDcache();
CP15_EnableIcache();
}
#endif
}
/*-----------------------------------------------------------*/
@ -178,8 +180,9 @@ void vApplicationMallocFailedHook( void )
internally by FreeRTOS API functions that create tasks, queues, software
timers, and semaphores. The size of the FreeRTOS heap is set by the
configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
taskDISABLE_INTERRUPTS();
for( ;; );
/* Force an assert. */
configASSERT( ( volatile void * ) NULL );
}
/*-----------------------------------------------------------*/
@ -191,8 +194,9 @@ void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
/* Run time stack overflow checking is performed if
configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
function is called if a stack overflow is detected. */
taskDISABLE_INTERRUPTS();
for( ;; );
/* Force an assert. */
configASSERT( ( volatile void * ) NULL );
}
/*-----------------------------------------------------------*/
@ -254,19 +258,19 @@ void vApplicationTickHook( void )
/* The function called by the RTOS port layer after it has managed interrupt
entry. */
void vApplicationIRQHandler( uint32_t ulInterruptVectorAddress )
void vApplicationIRQHandler( void )
{
typedef void (*ISRFunction_t)( void );
ISRFunction_t pxISRFunction;
volatile uint32_t * pulAIC_IVR = ( uint32_t * ) configINTERRUPT_VECTOR_ADDRESS;
/* On the SAMA5 the parameter is a pointer to the ISR handling function. */
pxISRFunction = ( ISRFunction_t ) ulInterruptVectorAddress;
/* Obtain the address of the interrupt handler from the AIR. */
pxISRFunction = ( ISRFunction_t ) *pulAIC_IVR;
/* Write back to the SAMA5's interrupt controller's IVR register in case the
CPU is in protect mode. If the interrupt controller is not in protect mode
then this write is not necessary. */
*pulAIC_IVR = 0;
*pulAIC_IVR = ( uint32_t ) pxISRFunction;
/* Ensure the write takes before re-enabling interrupts. */
__DSB();
@ -277,4 +281,3 @@ volatile uint32_t * pulAIC_IVR = ( uint32_t * ) configINTERRUPT_VECTOR_ADDRESS;
pxISRFunction();
}

View File

@ -8,11 +8,11 @@
<ColumnWidth0>20</ColumnWidth0><ColumnWidth1>1622</ColumnWidth1></Debug-Log>
<Build>
<ColumnWidth0>20</ColumnWidth0>
<ColumnWidth1>1216</ColumnWidth1>
<ColumnWidth2>324</ColumnWidth2>
<ColumnWidth3>81</ColumnWidth3>
</Build>
<ColumnWidth0>20</ColumnWidth0><ColumnWidth1>1216</ColumnWidth1><ColumnWidth2>324</ColumnWidth2><ColumnWidth3>81</ColumnWidth3></Build>
<Workspace>
<ColumnWidths>
@ -34,7 +34,7 @@
<PreferedWindows><Position>2</Position><ScreenPosX>0</ScreenPosX><ScreenPosY>0</ScreenPosY><Windows/></PreferedWindows><ShowCodeCoverage>1</ShowCodeCoverage><ShowInstrProfiling>1</ShowInstrProfiling></Disassembly>
<Breakpoints><PreferedWindows><Position>3</Position><ScreenPosX>0</ScreenPosX><ScreenPosY>0</ScreenPosY><Windows/></PreferedWindows><col-names><item>Breakpoint</item><item>_I0</item></col-names><col-widths><item>500</item><item>35</item></col-widths></Breakpoints><STACK_1><PreferedWindows><Position>1</Position><ScreenPosX>0</ScreenPosX><ScreenPosY>0</ScreenPosY><Windows/></PreferedWindows><stack>CSTACK</stack><width>4</width><vars>1</vars><offset>0</offset><col-names><item>Data</item><item>Frame</item><item>Location</item><item>Type</item><item>Value</item><item>Variable</item></col-names><col-widths><item>100</item><item>100</item><item>100</item><item>100</item><item>100</item><item>100</item></col-widths></STACK_1><CallStack><PreferedWindows><Position>1</Position><ScreenPosX>0</ScreenPosX><ScreenPosY>0</ScreenPosY><Windows/></PreferedWindows><col-names><item>Frame</item><item>_I0</item></col-names><col-widths><item>400</item><item>20</item></col-widths></CallStack><WATCH_1><expressions><item>ulx</item><item></item></expressions><col-names><item>Expression</item><item>Location</item><item>Type</item><item>Value</item></col-names><col-widths><item>100</item><item>150</item><item>100</item><item>100</item></col-widths></WATCH_1><Register><PreferedWindows><Position>2</Position><ScreenPosX>0</ScreenPosX><ScreenPosY>0</ScreenPosY><Windows/></PreferedWindows></Register></Static>
<Breakpoints><PreferedWindows><Position>3</Position><ScreenPosX>0</ScreenPosX><ScreenPosY>0</ScreenPosY><Windows/></PreferedWindows><col-names><item>Breakpoint</item><item>_I0</item></col-names><col-widths><item>500</item><item>35</item></col-widths></Breakpoints><STACK_1><PreferedWindows><Position>1</Position><ScreenPosX>0</ScreenPosX><ScreenPosY>0</ScreenPosY><Windows/></PreferedWindows><stack>CSTACK</stack><width>4</width><vars>1</vars><offset>0</offset><col-names><item>Data</item><item>Frame</item><item>Location</item><item>Type</item><item>Value</item><item>Variable</item></col-names><col-widths><item>100</item><item>100</item><item>100</item><item>100</item><item>100</item><item>100</item></col-widths></STACK_1><CallStack><PreferedWindows><Position>1</Position><ScreenPosX>0</ScreenPosX><ScreenPosY>0</ScreenPosY><Windows/></PreferedWindows><col-names><item>Frame</item><item>_I0</item></col-names><col-widths><item>400</item><item>20</item></col-widths></CallStack><WATCH_1><expressions><item>xTickCount</item><item/></expressions><col-names><item>Expression</item><item>Location</item><item>Type</item><item>Value</item></col-names><col-widths><item>100</item><item>150</item><item>100</item><item>100</item></col-widths><PreferedWindows><Position>2</Position><ScreenPosX>0</ScreenPosX><ScreenPosY>0</ScreenPosY><Windows/></PreferedWindows></WATCH_1><Register><PreferedWindows><Position>2</Position><ScreenPosX>0</ScreenPosX><ScreenPosY>0</ScreenPosY><Windows/></PreferedWindows></Register><Locals><col-names><item>Location</item><item>Type</item><item>Value</item><item>Variable</item></col-names><col-widths><item>150</item><item>100</item><item>100</item><item>185</item></col-widths><PreferedWindows><Position>2</Position><ScreenPosX>0</ScreenPosX><ScreenPosY>0</ScreenPosY><Windows/></PreferedWindows></Locals></Static>
<Windows>
@ -63,24 +63,24 @@
<Factory>Workspace</Factory>
<Session>
<NodeDict><ExpandedNode>RTOSDemo</ExpandedNode><ExpandedNode>RTOSDemo/Atmel Files</ExpandedNode><ExpandedNode>RTOSDemo/FreeRTOS Source</ExpandedNode><ExpandedNode>RTOSDemo/FreeRTOS Source/portable</ExpandedNode><ExpandedNode>RTOSDemo/FreeRTOS Source/portable/MemMang</ExpandedNode><ExpandedNode>RTOSDemo/Output</ExpandedNode></NodeDict></Session>
<NodeDict><ExpandedNode>RTOSDemo</ExpandedNode><ExpandedNode>RTOSDemo/FreeRTOS Source</ExpandedNode><ExpandedNode>RTOSDemo/FreeRTOS Source/portable</ExpandedNode><ExpandedNode>RTOSDemo/FreeRTOS Source/portable/MemMang</ExpandedNode><ExpandedNode>RTOSDemo/Full Demo</ExpandedNode><ExpandedNode>RTOSDemo/Output</ExpandedNode></NodeDict></Session>
</Tab>
</Tabs>
<SelectedTab>0</SelectedTab></Wnd2><Wnd6><Tabs><Tab><Identity>TabID-19127-2470</Identity><TabName>Watch 1</TabName><Factory>WATCH_1</Factory></Tab></Tabs><SelectedTab>0</SelectedTab></Wnd6><Wnd7><Tabs><Tab><Identity>TabID-26530-4583</Identity><TabName>Disassembly</TabName><Factory>Disassembly</Factory><Session/></Tab></Tabs><SelectedTab>0</SelectedTab></Wnd7></Windows>
<SelectedTab>0</SelectedTab></Wnd2><Wnd5><Tabs><Tab><Identity>TabID-4869-5115</Identity><TabName>Register</TabName><Factory>Register</Factory><Session><REG1>0</REG1><REG2>0</REG2><Group>0</Group><States>0</States></Session></Tab></Tabs><SelectedTab>0</SelectedTab></Wnd5></Windows>
<Editor>
<Pane><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\AtmelFiles\libchip_sama5d4x\source\pio_it.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>161</YPos2><SelStart2>7114</SelStart2><SelEnd2>7114</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\cstartup_with_FreeRTOS_vectors.s</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>96</YPos2><SelStart2>4249</SelStart2><SelEnd2>4249</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\LEDs.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>65</YPos2><SelStart2>4250</SelStart2><SelEnd2>4250</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\Blinky_Demo\main_blinky.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>190</YPos2><SelStart2>7316</SelStart2><SelEnd2>7316</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\AtmelFiles\libboard_sama5d4x-ek\source\board_lowlevel.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>165</YPos2><SelStart2>8844</SelStart2><SelEnd2>8844</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\FreeRTOS_tick_config.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>96</YPos2><SelStart2>5865</SelStart2><SelEnd2>5891</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\..\..\Source\portable\IAR\ARM_CA5_No_GIC\portASM.s</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>112</YPos2><SelStart2>5364</SelStart2><SelEnd2>5381</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\FreeRTOSConfig.h</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>137</YPos2><SelStart2>8285</SelStart2><SelEnd2>8285</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\AtmelFiles\libboard_sama5d4x-ek\board.h</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>195</YPos2><SelStart2>6643</SelStart2><SelEnd2>6643</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\atmel_main.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>191</YPos2><SelStart2>7564</SelStart2><SelEnd2>7564</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\main.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>114</YPos2><SelStart2>6411</SelStart2><SelEnd2>6411</SelEnd2></Tab><ActiveTab>10</ActiveTab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\..\..\Source\portable\IAR\ARM_CA5_No_GIC\port.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>280</YPos2><SelStart2>12414</SelStart2><SelEnd2>12440</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\AtmelFiles\libchip_sama5d4x\include\SAMA5D4.h</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>82</YPos2><SelStart2>7569</SelStart2><SelEnd2>7569</SelEnd2></Tab></Pane><ActivePane>0</ActivePane><Sizes><Pane><X>1000000</X><Y>1000000</Y></Pane></Sizes><SplitMode>1</SplitMode></Editor>
<Pane><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\main.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>111</YPos2><SelStart2>6131</SelStart2><SelEnd2>6131</SelEnd2></Tab><ActiveTab>0</ActiveTab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\Blinky_Demo\main_blinky.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>63</YPos2><SelStart2>0</SelStart2><SelEnd2>0</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\Full_Demo\main_full.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>63</YPos2><SelStart2>756</SelStart2><SelEnd2>756</SelEnd2></Tab></Pane><ActivePane>0</ActivePane><Sizes><Pane><X>1000000</X><Y>1000000</Y></Pane></Sizes><SplitMode>1</SplitMode></Editor>
<Positions>
<Top><Row0><Sizes><Toolbar-00BB53D0><key>iaridepm.enu1</key></Toolbar-00BB53D0></Sizes></Row0><Row1><Sizes><Toolbar-08E1E7B8><key>debuggergui.enu1</key></Toolbar-08E1E7B8></Sizes></Row1></Top><Left><Row0><Sizes><Wnd2><Rect><Top>-2</Top><Left>-2</Left><Bottom>718</Bottom><Right>288</Right><x>-2</x><y>-2</y><xscreen>200</xscreen><yscreen>200</yscreen><sizeHorzCX>119048</sizeHorzCX><sizeHorzCY>203252</sizeHorzCY><sizeVertCX>172619</sizeVertCX><sizeVertCY>731707</sizeVertCY></Rect></Wnd2></Sizes></Row0></Left><Right><Row0><Sizes><Wnd6><Rect><Top>-2</Top><Left>-2</Left><Bottom>718</Bottom><Right>198</Right><x>-2</x><y>-2</y><xscreen>200</xscreen><yscreen>200</yscreen><sizeHorzCX>119048</sizeHorzCX><sizeHorzCY>203252</sizeHorzCY><sizeVertCX>119048</sizeVertCX><sizeVertCY>731707</sizeVertCY></Rect></Wnd6></Sizes></Row0><Row1><Sizes><Wnd7><Rect><Top>-2</Top><Left>196</Left><Bottom>718</Bottom><Right>684</Right><x>196</x><y>-2</y><xscreen>200</xscreen><yscreen>200</yscreen><sizeHorzCX>119048</sizeHorzCX><sizeHorzCY>203252</sizeHorzCY><sizeVertCX>290476</sizeVertCX><sizeVertCY>731707</sizeVertCY></Rect></Wnd7></Sizes></Row1></Right><Bottom><Row0><Sizes><Wnd1><Rect><Top>-2</Top><Left>-2</Left><Bottom>198</Bottom><Right>1682</Right><x>-2</x><y>-2</y><xscreen>1684</xscreen><yscreen>200</yscreen><sizeHorzCX>1002381</sizeHorzCX><sizeHorzCY>203252</sizeHorzCY><sizeVertCX>119048</sizeVertCX><sizeVertCY>203252</sizeVertCY></Rect></Wnd1></Sizes></Row0></Bottom><Float><Sizes/></Float></Positions>
<Top><Row0><Sizes><Toolbar-007053D8><key>iaridepm.enu1</key></Toolbar-007053D8></Sizes></Row0><Row1><Sizes><Toolbar-0F40B070><key>debuggergui.enu1</key></Toolbar-0F40B070></Sizes></Row1></Top><Left><Row0><Sizes><Wnd2><Rect><Top>-2</Top><Left>-2</Left><Bottom>718</Bottom><Right>288</Right><x>-2</x><y>-2</y><xscreen>200</xscreen><yscreen>200</yscreen><sizeHorzCX>119048</sizeHorzCX><sizeHorzCY>203252</sizeHorzCY><sizeVertCX>172619</sizeVertCX><sizeVertCY>731707</sizeVertCY></Rect></Wnd2></Sizes></Row0></Left><Right><Row0><Sizes><Wnd5><Rect><Top>-2</Top><Left>-2</Left><Bottom>718</Bottom><Right>198</Right><x>-2</x><y>-2</y><xscreen>200</xscreen><yscreen>200</yscreen><sizeHorzCX>119048</sizeHorzCX><sizeHorzCY>203252</sizeHorzCY><sizeVertCX>119048</sizeVertCX><sizeVertCY>731707</sizeVertCY></Rect></Wnd5></Sizes></Row0></Right><Bottom><Row0><Sizes><Wnd1><Rect><Top>-2</Top><Left>-2</Left><Bottom>198</Bottom><Right>1682</Right><x>-2</x><y>-2</y><xscreen>1684</xscreen><yscreen>200</yscreen><sizeHorzCX>1002381</sizeHorzCX><sizeHorzCY>203252</sizeHorzCY><sizeVertCX>119048</sizeVertCX><sizeVertCY>203252</sizeVertCY></Rect></Wnd1></Sizes></Row0></Bottom><Float><Sizes/></Float></Positions>
</Desktop>
</Project>

View File

@ -14,7 +14,7 @@ Watch0=_ 0 "" 0 "" 0 "" 0 "" 0 0 0 0
Watch1=_ 0 "" 0 "" 0 "" 0 "" 0 0 0 0
CStepIntDis=_ 0
[DebugChecksum]
Checksum=-1721229099
Checksum=591356453
[Exceptions]
StopOnUncaught=_ 0
StopOnThrow=_ 0
@ -22,6 +22,8 @@ StopOnThrow=_ 0
ShowArgs=0
[Disassembly]
MixedMode=1
[watch_formats]
Fmt0={W}1:ulAPSR 4 0
[Log file]
LoggingEnabled=_ 0
LogFile=_ ""
@ -40,8 +42,8 @@ Exclusions=
[Disassemble mode]
mode=0
[Breakpoints2]
Bp0=_ 1 "EMUL_CODE" "{$PROJ_DIR$\AtmelFiles\libboard_sama5d4x-ek\source\board_lowlevel.c}.293.3" 0 0 1 "" 0 "" 0
Bp1=_ 1 "EMUL_CODE" "{$PROJ_DIR$\AtmelFiles\libboard_sama5d4x-ek\source\board_lowlevel.c}.302.3" 0 0 1 "" 0 "" 0
Bp0=_ 1 "EMUL_CODE" "{$PROJ_DIR$\main.c}.228.2" 0 0 1 "" 0 "" 0
Bp1=_ 1 "EMUL_CODE" "{$PROJ_DIR$\AtmelFiles\libboard_sama5d4x-ek\source\board_lowlevel.c}.297.2" 0 0 1 "" 0 "" 0
Count=2
[Aliases]
Count=0

View File

@ -3,7 +3,7 @@
<Workspace>
<ConfigDictionary>
<CurrentConfigs><Project>RTOSDemo/sram</Project></CurrentConfigs></ConfigDictionary>
<CurrentConfigs><Project>RTOSDemo/ddram</Project></CurrentConfigs></ConfigDictionary>
<Desktop>
<Static>
<Workspace>
@ -20,11 +20,11 @@
<ColumnWidth0>20</ColumnWidth0><ColumnWidth1>1216</ColumnWidth1><ColumnWidth2>324</ColumnWidth2><ColumnWidth3>81</ColumnWidth3></Build>
<Find-in-Files><ColumnWidth0>497</ColumnWidth0><ColumnWidth1>82</ColumnWidth1><ColumnWidth2>746</ColumnWidth2><ColumnWidth3>331</ColumnWidth3></Find-in-Files><TerminalIO/><Debug-Log><ColumnWidth0>19</ColumnWidth0><ColumnWidth1>1623</ColumnWidth1></Debug-Log></Static>
<Find-in-Files><ColumnWidth0>497</ColumnWidth0><ColumnWidth1>82</ColumnWidth1><ColumnWidth2>746</ColumnWidth2><ColumnWidth3>331</ColumnWidth3></Find-in-Files><TerminalIO/><Debug-Log><ColumnWidth0>19</ColumnWidth0><ColumnWidth1>1623</ColumnWidth1></Debug-Log><Select-Ambiguous-Definitions><ColumnWidth0>875</ColumnWidth0><ColumnWidth1>82</ColumnWidth1><ColumnWidth2>994</ColumnWidth2></Select-Ambiguous-Definitions><Breakpoints><PreferedWindows><Position>3</Position><ScreenPosX>0</ScreenPosX><ScreenPosY>0</ScreenPosY><Windows/></PreferedWindows><col-names><item>Breakpoint</item><item>_I0</item></col-names><col-widths><item>500</item><item>35</item></col-widths></Breakpoints></Static>
<Windows>
<Wnd0>
<Wnd2>
<Tabs>
<Tab>
<Identity>TabID-423-28504</Identity>
@ -32,11 +32,11 @@
<Factory>Workspace</Factory>
<Session>
<NodeDict><ExpandedNode>RTOSDemo</ExpandedNode><ExpandedNode>RTOSDemo/FreeRTOS Source</ExpandedNode><ExpandedNode>RTOSDemo/FreeRTOS Source/portable</ExpandedNode><ExpandedNode>RTOSDemo/documentation</ExpandedNode><ExpandedNode>RTOSDemo/libraries</ExpandedNode><ExpandedNode>RTOSDemo/resources</ExpandedNode></NodeDict></Session>
<NodeDict><ExpandedNode>RTOSDemo</ExpandedNode><ExpandedNode>RTOSDemo/documentation</ExpandedNode><ExpandedNode>RTOSDemo/libraries</ExpandedNode><ExpandedNode>RTOSDemo/resources</ExpandedNode></NodeDict></Session>
</Tab>
</Tabs>
<SelectedTab>0</SelectedTab></Wnd0><Wnd1>
<SelectedTab>0</SelectedTab></Wnd2><Wnd3>
<Tabs>
<Tab>
<Identity>TabID-6281-15071</Identity>
@ -44,22 +44,22 @@
<Factory>Build</Factory>
<Session/>
</Tab>
<Tab><Identity>TabID-13526-15205</Identity><TabName>Find in Files</TabName><Factory>Find-in-Files</Factory><Session/></Tab><Tab><Identity>TabID-32406-174</Identity><TabName>Debug Log</TabName><Factory>Debug-Log</Factory><Session/></Tab></Tabs>
<Tab><Identity>TabID-13526-15205</Identity><TabName>Find in Files</TabName><Factory>Find-in-Files</Factory><Session/></Tab><Tab><Identity>TabID-32406-174</Identity><TabName>Debug Log</TabName><Factory>Debug-Log</Factory><Session/></Tab><Tab><Identity>TabID-186-5853</Identity><TabName>Ambiguous Definitions</TabName><Factory>Select-Ambiguous-Definitions</Factory><Session/></Tab></Tabs>
<SelectedTab>0</SelectedTab></Wnd1></Windows>
<SelectedTab>0</SelectedTab></Wnd3></Windows>
<Editor>
<Pane><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\AtmelFiles\libchip_sama5d4x\source\pio_it.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>161</YPos2><SelStart2>7114</SelStart2><SelEnd2>7114</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\cstartup_with_FreeRTOS_vectors.s</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>96</YPos2><SelStart2>4249</SelStart2><SelEnd2>4249</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\LEDs.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>65</YPos2><SelStart2>4250</SelStart2><SelEnd2>4250</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\Blinky_Demo\main_blinky.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>190</YPos2><SelStart2>7316</SelStart2><SelEnd2>7316</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\AtmelFiles\libboard_sama5d4x-ek\source\board_lowlevel.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>165</YPos2><SelStart2>8844</SelStart2><SelEnd2>8844</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\FreeRTOS_tick_config.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>96</YPos2><SelStart2>5865</SelStart2><SelEnd2>5891</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\..\..\Source\portable\IAR\ARM_CA5_No_GIC\portASM.s</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>112</YPos2><SelStart2>5364</SelStart2><SelEnd2>5381</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\FreeRTOSConfig.h</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>137</YPos2><SelStart2>8285</SelStart2><SelEnd2>8285</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\AtmelFiles\libboard_sama5d4x-ek\board.h</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>195</YPos2><SelStart2>6643</SelStart2><SelEnd2>6643</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\atmel_main.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>191</YPos2><SelStart2>7564</SelStart2><SelEnd2>7564</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\main.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>114</YPos2><SelStart2>6411</SelStart2><SelEnd2>6411</SelEnd2></Tab><ActiveTab>10</ActiveTab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\..\..\Source\portable\IAR\ARM_CA5_No_GIC\port.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>280</YPos2><SelStart2>12414</SelStart2><SelEnd2>12440</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\AtmelFiles\libchip_sama5d4x\include\SAMA5D4.h</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>82</YPos2><SelStart2>7569</SelStart2><SelEnd2>7569</SelEnd2></Tab></Pane><ActivePane>0</ActivePane><Sizes><Pane><X>1000000</X><Y>1000000</Y></Pane></Sizes><SplitMode>1</SplitMode></Editor>
<Pane><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\main.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>63</YPos2><SelStart2>5806</SelStart2><SelEnd2>5806</SelEnd2></Tab><ActiveTab>0</ActiveTab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\Blinky_Demo\main_blinky.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>63</YPos2><SelStart2>0</SelStart2><SelEnd2>0</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\Full_Demo\main_full.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>63</YPos2><SelStart2>756</SelStart2><SelEnd2>756</SelEnd2></Tab></Pane><ActivePane>0</ActivePane><Sizes><Pane><X>1000000</X><Y>1000000</Y></Pane></Sizes><SplitMode>1</SplitMode></Editor>
<Positions>
<Top><Row0><Sizes><Toolbar-00BB53D0><key>iaridepm.enu1</key></Toolbar-00BB53D0></Sizes></Row0><Row1><Sizes/></Row1></Top><Left><Row0><Sizes><Wnd0><Rect><Top>-2</Top><Left>-2</Left><Bottom>653</Bottom><Right>321</Right><x>-2</x><y>-2</y><xscreen>200</xscreen><yscreen>200</yscreen><sizeHorzCX>119048</sizeHorzCX><sizeHorzCY>203252</sizeHorzCY><sizeVertCX>192262</sizeVertCX><sizeVertCY>665650</sizeVertCY></Rect></Wnd0></Sizes></Row0></Left><Right><Row0><Sizes/></Row0></Right><Bottom><Row0><Sizes><Wnd1><Rect><Top>-2</Top><Left>-2</Left><Bottom>287</Bottom><Right>1682</Right><x>-2</x><y>-2</y><xscreen>1684</xscreen><yscreen>289</yscreen><sizeHorzCX>1002381</sizeHorzCX><sizeHorzCY>293699</sizeHorzCY><sizeVertCX>119048</sizeVertCX><sizeVertCY>203252</sizeVertCY></Rect></Wnd1></Sizes></Row0></Bottom><Float><Sizes/></Float></Positions>
<Top><Row0><Sizes><Toolbar-007053D8><key>iaridepm.enu1</key></Toolbar-007053D8></Sizes></Row0><Row1><Sizes/></Row1></Top><Left><Row0><Sizes><Wnd2><Rect><Top>-2</Top><Left>-2</Left><Bottom>767</Bottom><Right>321</Right><x>-2</x><y>-2</y><xscreen>200</xscreen><yscreen>200</yscreen><sizeHorzCX>119048</sizeHorzCX><sizeHorzCY>203252</sizeHorzCY><sizeVertCX>192262</sizeVertCX><sizeVertCY>781504</sizeVertCY></Rect></Wnd2></Sizes></Row0></Left><Right><Row0><Sizes/></Row0></Right><Bottom><Row0><Sizes><Wnd3><Rect><Top>-2</Top><Left>-2</Left><Bottom>173</Bottom><Right>1682</Right><x>-2</x><y>-2</y><xscreen>1684</xscreen><yscreen>175</yscreen><sizeHorzCX>1002381</sizeHorzCX><sizeHorzCY>177846</sizeHorzCY><sizeVertCX>119048</sizeVertCX><sizeVertCY>203252</sizeVertCY></Rect></Wnd3></Sizes></Row0></Bottom><Float><Sizes/></Float></Positions>
</Desktop>
</Workspace>

View File

@ -68,7 +68,7 @@
* style project, a more comprehensive test and demo application, and an
* lwIP example. The mainSELECTED_APPLICATION setting in main.c is used to
* select between the three. See the notes on using mainSELECTED_APPLICATION
* in main.c. This file implements the simply blinky style version.
* in main.c. This file implements the comprehensive version.
*
* NOTE 2: This file only contains the source code that is specific to the
* full demo. Generic functions, such FreeRTOS hook functions, and functions

View File

@ -74,7 +74,7 @@
/*lint -e537 This headers are only multiply included if the application code
happens to also be including task.h. */
#include "task.h"
/*lint +e956 */
/*lint +e537 */
#ifdef __cplusplus
extern "C" {

View File

@ -63,9 +63,6 @@
1 tab == 4 spaces!
*/
/* Standard includes. */
#include <stdlib.h>
/* IAR includes. */
#include <intrinsics.h>
@ -80,6 +77,14 @@
#endif
#endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */
#ifndef configSETUP_TICK_INTERRUPT
#error configSETUP_TICK_INTERRUPT() must be defined in FreeRTOSConfig.h to call the function that sets up the tick interrupt. A default that uses the PIT is provided in the official demo application.
#endif
#ifndef configCLEAR_TICK_INTERRUPT
#error configCLEAR_TICK_INTERRUPT must be defined in FreeRTOSConfig.h to clear which ever interrupt was used to generate the tick interrupt. A default that uses the PIT is provided in the official demo application.
#endif
/* A critical section is exited when the critical section nesting count reaches
this value. */
#define portNO_CRITICAL_NESTING ( ( uint32_t ) 0 )
@ -242,7 +247,6 @@ uint32_t ulAPSR;
{
/* Start the timer that generates the tick ISR. */
configSETUP_TICK_INTERRUPT();
__enable_irq();
vPortRestoreTaskContext();
}

View File

@ -132,26 +132,24 @@ FreeRTOS_IRQ_Handler
AND r2, r2, #4
SUB sp, sp, r2
; Obtain the address of the interrupt handler, then pass it into the ISR
; callback.
PUSH {r0-r3, lr}
LDR r1, =configINTERRUPT_VECTOR_ADDRESS
LDR r0, [r1]
LDR r1, =vApplicationIRQHandler
BLX r1
; Call the port part specific handler.
LDR r0, =vApplicationIRQHandler
BLX r0
POP {r0-r3, lr}
ADD sp, sp, r2
CPSID i
; Write to the EOI register
; Write to the EOI register.
LDR r4, =configEOI_ADDRESS
STR r0, [r4]
; Restore the old nesting count
STR r1, [r3]
; A context switch is never performed if the nesting count is not 0
; A context switch is never performed if the nesting count is not 0.
CMP r1, #0
BNE exit_without_switch
@ -198,7 +196,6 @@ switch_before_exit
; Restore the context of, and branch to, the task selected to execute next.
portRESTORE_CONTEXT
END

View File

@ -178,7 +178,7 @@ TIMECAPS xTimeCaps;
/* Just to prevent compiler warnings. */
( void ) lpParameter;
for(;;)
for( ;; )
{
/* Wait until the timer expires and we can access the simulated interrupt
variables. *NOTE* this is not a 'real time' way of generating tick

View File

@ -84,6 +84,8 @@ header files above, but not in this file, in order to generate the correct
privileged Vs unprivileged linkage and placement. */
#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e961 !e750. */
/* Set configUSE_STATS_FORMATTING_FUNCTIONS to 2 to include the stats formatting
functions but without including stdio.h here. */
#if ( configUSE_STATS_FORMATTING_FUNCTIONS == 1 )
/* At the bottom of this file are two optional functions that can be used
to generate human readable text from the raw data generated by the
@ -3414,7 +3416,7 @@ TCB_t *pxTCB;
#endif /* portCRITICAL_NESTING_IN_TCB */
/*-----------------------------------------------------------*/
#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS == 1 ) )
#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) )
void vTaskList( char * pcWriteBuffer )
{
@ -3498,10 +3500,10 @@ TCB_t *pxTCB;
}
}
#endif /* ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS == 1 ) ) */
#endif /* ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) ) */
/*----------------------------------------------------------*/
#if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS == 1 ) )
#if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) )
void vTaskGetRunTimeStats( char *pcWriteBuffer )
{
@ -3617,7 +3619,7 @@ TCB_t *pxTCB;
}
}
#endif /* ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS == 1 ) ) */
#endif /* ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) ) */
/*-----------------------------------------------------------*/
TickType_t uxTaskResetEventItemValue( void )