S3C6410的GPIO流驱动(WINCE600)
Topic:S3C6410的GPIO流驱动(作者:Sturtle)
//----------------------------------------------------------------------------------------------------------------------------
// 作者:Sturtle
// 平台:友坚UT-S3C6410开发板+WINCE6.0 OS
// 注意事项:未经作者同意,商业网站不能转载,更不得在转载的时候擅自修改、删除**的任何部分
//------------------------------------------------------------------------------------------------------------------------------
写前:控制GPIO通常是用PHYSICAL_ADDRESS和MmMapIoSpace,通俗的说就是通过VirtualAlloc和VirtualCopy进行虚拟地址映射,然后操作相应GPIO寄存器做自己要的动作;据说CE5可以直接内存映射,CE6必须写GPIO驱动,鄙人更赞成写成流驱动的形式,后续维护移植都方便;闲话少说,言归正卷
1、VirtualAlloc()/VirtualCopy()
view plaincopy to clipboardprint?
PVOID TSP_RegAlloc(PVOID addr, INT sz)
{
PVOID reg;
reg = (PVOID)VirtualAlloc(0, sz, MEM_RESERVE, PAGE_NOACCESS);
if (reg)
{
if (!VirtualCopy(reg, (PVOID)((UINT32)addr >> 8), sz, PAGE_PHYSICAL | PAGE_READWRITE | PAGE_NOCACHE ))
{
//VirtualFree(reg, sz, MEM_RELEASE);
VirtualFree(reg, 0, MEM_RELEASE);
reg = NULL;
}
}
return reg;
}
PVOID TSP_RegAlloc(PVOID addr, INT sz)
{
PVOID reg;
reg = (PVOID)VirtualAlloc(0, sz, MEM_RESERVE, PAGE_NOACCESS);
if (reg)
{
if (!VirtualCopy(reg, (PVOID)((UINT32)addr >> 8), sz, PAGE_PHYSICAL | PAGE_READWRITE | PAGE_NOCACHE ))
{
//VirtualFree(reg, sz, MEM_RELEASE);
VirtualFree(reg, 0, MEM_RELEASE);
reg = NULL;
}
}
return reg;
}
2、初始化
view plaincopy to clipboardprint?
DWORD GIO_Init(LPCTSTR pContext,LPVOID lpvBusContext)
{
UINT32 i;
RETAILMSG(sturtle_gpio, (TEXT("GIO_Init... \r\n") ) );
g_pIOPregs = (volatile S3C6410_GPIO_REG*)TSP_RegAlloc((PVOID)S3C6410_BASE_REG_PA_GPIO, sizeof(S3C6410_GPIO_REG));
if (g_pIOPregs == NULL)
{
RETAILMSG(1,(TEXT("GIO_Init -> g_pIOPregs: VirtualAlloc failed!\r\n")));
}
...
}
DWORD GIO_Init(LPCTSTR pContext,LPVOID lpvBusContext)
{
UINT32 i;
RETAILMSG(sturtle_gpio, (TEXT("GIO_Init... \r\n") ) );
g_pIOPregs = (volatile S3C6410_GPIO_REG*)TSP_RegAlloc((PVOID)S3C6410_BASE_REG_PA_GPIO, sizeof(S3C6410_GPIO_REG));
if (g_pIOPregs == NULL)
{
RETAILMSG(1,(TEXT("GIO_Init -> g_pIOPregs: VirtualAlloc failed!\r\n")));
}
...
}
//如有错误,请留言指正;同时希望有更好的方法与大家交流和分享,让我们大家一起进步!
本文由友坚科技整理:http://www.urbetter.com
|