Subversion Repositories NaviCtrl

Rev

Rev 1 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 ingob 1
/******************** (C) COPYRIGHT 2006 STMicroelectronics ********************
2
* File Name          : usb_mem.c
3
* Author             : MCD Application Team
4
* Date First Issued  : 10/27/2003 : V1.0
5
* Description        : Utility functions for memory transfers to/from PMA
6
********************************************************************************
7
* History:
8
* 09/18/2006 : V3.0
9
* 09/01/2006 : V2.0
10
* 10/27/2003 : V1.0
11
********************************************************************************
12
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
13
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
14
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
15
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
16
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
17
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18
*******************************************************************************/
19
 
20
/* Includes ------------------------------------------------------------------*/
21
#include "usb_lib.h"
22
#include "usb_mem.h"
23
#include "usb_conf.h"
24
/* Private typedef -----------------------------------------------------------*/
25
/* Private define ------------------------------------------------------------*/
26
/* Private macro -------------------------------------------------------------*/
27
/* Private variables ---------------------------------------------------------*/
28
/* Extern variables ----------------------------------------------------------*/
29
/* Private function prototypes -----------------------------------------------*/
30
/* Private functions ---------------------------------------------------------*/
31
 
32
 
33
 
34
/*******************************************************************************
35
* Function Name  : UserToPMABufferCopy
36
* Description    : Copy a buffer from user memory area to packet memory area (PMA)
37
* Input 1        : pbUsrBuf    = pointer to user memory area
38
* Input 2        : wPMABufAddr = address into PMA
39
* Input 3        : wNBytes     = no. of bytes to be copied
40
* Output         : None
41
* Return         : None
42
*******************************************************************************/
43
void UserToPMABufferCopy(u8 *pbUsrBuf,u16 wPMABufAddr, u16 wNBytes)
44
{
45
 #ifdef STR7xx             /* STR7xx family    */
46
  u32 n= (wNBytes+1)>>1;   /* n=(wNBytes+1)/2  */
47
  u32 i,temp1,temp2;
48
  u16 *pdwVal;
49
  pdwVal = (u16 *)(wPMABufAddr*2 + PMAAddr);
50
  for (i = n; i!= 0; i--)
51
  {
52
     temp1 = (u16)*pbUsrBuf;
53
     pbUsrBuf++;
54
     temp2 = temp1 | (u16)*pbUsrBuf<<8;
55
     *pdwVal++ = temp2;
56
     pdwVal++;
57
     pbUsrBuf++;
58
  }
59
  #endif                  /* End of STR7xx family*/
60
 
61
  #ifdef STR91x           /*STR91x family*/
62
 
63
    u32 n= (wNBytes+3)>>2;  /*n=(wNBytes+1)/4*/
64
    u32 i,temp1,temp2,temp3,temp4;
65
    u32 *pdwVal;
66
    pdwVal = (u32 *)(PMAAddr+(u32)((wPMABufAddr)));
67
    for (i=n; i!=0; i--)
68
    {
69
      temp1 = (u32)*pbUsrBuf;
70
      temp2 = temp1 | (u32)*(pbUsrBuf+1)<<8;
71
      temp3 = temp2 | (u32)*(pbUsrBuf+2)<<16;
72
      temp4 = temp3 | (u32)*(pbUsrBuf+3)<<24;
73
      pbUsrBuf+=4;
74
      *pdwVal = temp4;
75
 
76
      pdwVal++;
77
    }
78
  #endif /* End of STR91x family*/
79
}
80
/*******************************************************************************
81
* Function Name  : PMAToUserBufferCopy
82
* Description    : Copy a buffer from user memory area to packet memory area (PMA)
83
* Input 1        : pbUsrBuf    = pointer to user memory area
84
* Input 2        : wPMABufAddr = address into PMA
85
* Input 3        : wNBytes     = no. of bytes to be copied
86
* Output         : pbUsrBuf    = pointer to user memory area with correct data
87
* Return         : None
88
*******************************************************************************/
89
void PMAToUserBufferCopy(u8 *pbUsrBuf,u16 wPMABufAddr, u16 wNBytes)
90
{
91
 #ifdef STR7xx /*STR7xx family*/
92
    u32 n= (wNBytes+1)>>1;/* /2*/
93
    u32 i;
94
    u32 *pdwVal;
95
    pdwVal = (u32 *)(wPMABufAddr*2 + PMAAddr);
96
    for (i = n; i!= 0; i--)
97
    {
98
      *(u16*)pbUsrBuf++ = *pdwVal++;
99
      pbUsrBuf++;
100
    }
101
  #endif /* End of STR7xx family*/
102
 
103
  #ifdef STR91x  /*STR91x family*/
104
    u8 *pbVal;
105
    u16 wNTrasf=wNBytes;
106
    if((wNBytes) == 0) return;
107
    pbVal = (u8 *)(PMAAddr + wPMABufAddr);
108
    while(1)
109
    {
110
      *pbUsrBuf++ = *pbVal++;
111
      if((--wNTrasf) == 0) return;
112
      *pbUsrBuf++ = *pbVal++;
113
      if((--wNTrasf) == 0) return;
114
    }
115
  #endif /* End of STR91x family*/
116
}
117
/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/
118