1
0
mirror of https://github.com/elua/elua.git synced 2025-01-25 01:02:54 +08:00

Bring type definitions in line with eLua standard conventions.

This commit is contained in:
Andreas Bogk 2015-04-23 16:23:08 +02:00
parent cc425be821
commit 480d6352ea
7 changed files with 1088 additions and 1204 deletions

View File

@ -1,8 +1,10 @@
-- Configuration file for the LPC17xx backend
addi( sf( 'src/platform/%s/drivers/inc', platform ) )
addi( sf( 'src/platform/%s/usbstack/inc', platform ) )
local fwlib_files = utils.get_files( sf( "src/platform/%s/drivers/src", platform ), ".*%.c$" )
fwlib_files = fwlib_files .. " " .. utils.get_files( sf( "src/platform/%s/usbstack/src", platform ), ".*%.c$" )
specific_files = "startup_LPC17xx.c system_LPC17xx.c core_cm3.c platform.c"
local board = comp.board:upper()

View File

@ -1,68 +0,0 @@
/*
LPCUSB, an USB device driver for LPC microcontrollers
Copyright (C) 2006 Bertrik Sikken (bertrik@sikken.nl)
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR 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
primitive types used in the USB stack
*/
// ***********************************************
// Code Red Technologies - port to RDB1768 board
// In order to avoid clashing with the NXP-produced type.h file, this
// one has been renamed to lpcusb_type.h, the NXP-produced type.h has
// been included, and the duplicate contents of this file commented out.
// ***********************************************
#ifndef _LPCUSB_TYPE_H_
#define _LPCUSB_TYPE_H_
// CodeRed - include NXP-produced type.h file
#include "type.h"
typedef unsigned char U8; /**< unsigned 8-bit */
typedef unsigned short int U16; /**< unsigned 16-bit */
typedef unsigned int U32; /**< unsigned 32-bit */
// CodeRed - comment out defines duplicated in NXP type.h
//typedef int BOOL; /**< #TRUE or #FALSE */
//#define TRUE 1 /**< TRUE */
//#define FALSE 0 /**< FALSE */
//#ifndef NULL
//#define NULL ((void*)0) /**< NULL pointer */
//#endif
//#endif
/* some other useful macros */
#define MIN(x,y) ((x)<(y)?(x):(y)) /**< MIN */
#define MAX(x,y) ((x)>(y)?(x):(y)) /**< MAX */
#endif /* _LPCUSB_TYPE_H_ */

View File

@ -1,38 +0,0 @@
/*****************************************************************************
* type.h: Type definition Header file for NXP LPC17xx Family
* Microprocessors
*
* Copyright(C) 2008, NXP Semiconductor
* All rights reserved.
*
* History
* 2008.08.21 ver 1.00 Prelimnary version, first Release
*
******************************************************************************/
#ifndef __TYPE_H__
#define __TYPE_H__
#ifndef NULL
#define NULL ((void *)0)
#endif
#ifndef FALSE
#define FALSE (0)
#endif
#ifndef TRUE
#define TRUE (1)
#endif
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef unsigned long DWORD;
typedef unsigned int BOOL;
typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus;
typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState;
/* Pointer to Function returning Void (any number of parameters) */
typedef void (*PFV)();
#endif /* __TYPE_H__ */

View File

@ -48,9 +48,7 @@
control transfer data. The data is then packetised and sent to the host.
*/
// CodeRed - include the LPCUSB type.h file rather than NXP one directly
//#include "type.h"
#include "lpcusb_type.h"
#include "type.h"
#include "usbdebug.h"
@ -64,14 +62,14 @@
static TSetupPacket Setup; /**< setup packet */
static U8 *pbData; /**< pointer to data buffer */
static u8 *pbData; /**< pointer to data buffer */
static int iResidue; /**< remaining bytes in buffer */
static int iLen; /**< total length of control transfer */
/** Array of installed request handler callbacks */
static TFnHandleRequest *apfnReqHandlers[4] = {NULL, NULL, NULL, NULL};
/** Array of installed request data pointers */
static U8 *apbDataStore[4] = {NULL, NULL, NULL, NULL};
static u8 *apbDataStore[4] = {NULL, NULL, NULL, NULL};
/**
Local function to handle a request by calling one of the installed
@ -87,7 +85,7 @@ static U8 *apbDataStore[4] = {NULL, NULL, NULL, NULL};
@return TRUE if the request was handles successfully
*/
static BOOL _HandleRequest(TSetupPacket *pSetup, int *piLen, U8 **ppbData)
static BOOL _HandleRequest(TSetupPacket *pSetup, int *piLen, u8 **ppbData)
{
TFnHandleRequest *pfnHandler;
int iType;
@ -108,16 +106,16 @@ static BOOL _HandleRequest(TSetupPacket *pSetup, int *piLen, U8 **ppbData)
@param [in] bEPStat Endpoint status
*/
static void StallControlPipe(U8 bEPStat)
static void StallControlPipe(u8 bEPStat)
{
U8 *pb;
u8 *pb;
int i;
USBHwEPStall(0x80, TRUE);
// dump setup packet
DBG("STALL on [");
pb = (U8 *)&Setup;
pb = (u8 *)&Setup;
for (i = 0; i < 8; i++) {
DBG(" %02x", *pb++);
}
@ -145,7 +143,7 @@ static void DataIn(void)
* @param [in] bEP Endpoint address
* @param [in] bEPStat Endpoint status
*/
void USBHandleControlTransfer(U8 bEP, U8 bEPStat)
void USBHandleControlTransfer(u8 bEP, u8 bEPStat)
{
int iChunk, iType;
@ -153,7 +151,7 @@ void USBHandleControlTransfer(U8 bEP, U8 bEPStat)
// OUT transfer
if (bEPStat & EP_STATUS_SETUP) {
// setup packet, reset request message state machine
USBHwEPRead(0x00, (U8 *)&Setup, sizeof(Setup));
USBHwEPRead(0x00, (u8 *)&Setup, sizeof(Setup));
DBG("S%x", Setup.bRequest);
// defaults for data pointer and residue
@ -224,11 +222,10 @@ void USBHandleControlTransfer(U8 bEP, U8 bEPStat)
@param [in] *pfnHandler Callback function pointer
@param [in] *pbDataStore Data storage area for this type of request
*/
void USBRegisterRequestHandler(int iType, TFnHandleRequest *pfnHandler, U8 *pbDataStore)
void USBRegisterRequestHandler(int iType, TFnHandleRequest *pfnHandler, u8 *pbDataStore)
{
ASSERT(iType >= 0);
ASSERT(iType < 4);
apfnReqHandlers[iType] = pfnHandler;
apbDataStore[iType] = pbDataStore;
}

View File

@ -30,9 +30,7 @@
USB hardware layer
*/
// CodeRed - include the LPCUSB type.h file rather than NXP one directly
//#include "type.h"
#include "lpcusb_type.h"
#include "type.h"
#include "usbdebug.h"
#include "usbhw_lpc.h"
@ -102,7 +100,7 @@ static TFnFrameHandler *_pfnFrameHandler = NULL;
@param [in] dwIntr Bitmask of interrupts to wait for
*/
static void Wait4DevInt(U32 dwIntr)
static void Wait4DevInt(u32 dwIntr)
{
// wait for specific interrupt
while ((LPC_USB->USBDevIntSt & dwIntr) != dwIntr);
@ -116,7 +114,7 @@ static void Wait4DevInt(U32 dwIntr)
@param [in] bCmd Command to send
*/
static void USBHwCmd(U8 bCmd)
static void USBHwCmd(u8 bCmd)
{
// clear CDFULL/CCEMTY
LPC_USB->USBDevIntClr = CDFULL | CCEMTY;
@ -132,7 +130,7 @@ static void USBHwCmd(U8 bCmd)
@param [in] bCmd Command to send
@param [in] bData Data to send
*/
static void USBHwCmdWrite(U8 bCmd, U16 bData)
static void USBHwCmdWrite(u8 bCmd, u16 bData)
{
// write command code
USBHwCmd(bCmd);
@ -150,7 +148,7 @@ static void USBHwCmdWrite(U8 bCmd, U16 bData)
@return the data
*/
static U8 USBHwCmdRead(U8 bCmd)
static u8 USBHwCmdRead(u8 bCmd)
{
// write command code
USBHwCmd(bCmd);
@ -173,7 +171,7 @@ static U8 USBHwCmdRead(U8 bCmd)
@param [in] idx Endpoint index
@param [in] wMaxPSize Maximum packet size for this endpoint
*/
static void USBHwEPRealize(int idx, U16 wMaxPSize)
static void USBHwEPRealize(int idx, u16 wMaxPSize)
{
LPC_USB->USBReEP |= (1 << idx);
LPC_USB->USBEpInd = idx;
@ -200,7 +198,7 @@ static void USBHwEPEnable(int idx, BOOL fEnable)
@param [in] bEP Endpoint number
@param [in] wMaxPacketSize Maximum packet size for this EP
*/
void USBHwEPConfig(U8 bEP, U16 wMaxPacketSize)
void USBHwEPConfig(u8 bEP, u16 wMaxPacketSize)
{
int idx;
@ -220,7 +218,7 @@ void USBHwEPConfig(U8 bEP, U16 wMaxPacketSize)
@param [in] bEP Endpoint number
@param [in] pfnHandler Callback function
*/
void USBHwRegisterEPIntHandler(U8 bEP, TFnEPIntHandler *pfnHandler)
void USBHwRegisterEPIntHandler(u8 bEP, TFnEPIntHandler *pfnHandler)
{
int idx;
@ -276,7 +274,7 @@ void USBHwRegisterFrameHandler(TFnFrameHandler *pfnHandler)
@param [in] bAddr Device address to set
*/
void USBHwSetAddress(U8 bAddr)
void USBHwSetAddress(u8 bAddr)
{
USBHwCmdWrite(CMD_DEV_SET_ADDRESS, DEV_EN | bAddr);
}
@ -306,7 +304,7 @@ void USBHwConnect(BOOL fConnect)
@param [in] bIntBits Bitmap indicating which NAK interrupts to enable
*/
void USBHwNakIntEnable(U8 bIntBits)
void USBHwNakIntEnable(u8 bIntBits)
{
USBHwCmdWrite(CMD_DEV_SET_MODE, bIntBits);
}
@ -318,7 +316,7 @@ void USBHwNakIntEnable(U8 bIntBits)
@param [in] bEP Endpoint number
@return Endpoint status byte (containing EP_STATUS_xxx bits)
*/
U8 USBHwEPGetStatus(U8 bEP)
u8 USBHwEPGetStatus(u8 bEP)
{
int idx = EP2IDX(bEP);
@ -332,7 +330,7 @@ U8 USBHwEPGetStatus(U8 bEP)
@param [in] bEP Endpoint number
@param [in] fStall TRUE to stall, FALSE to unstall
*/
void USBHwEPStall(U8 bEP, BOOL fStall)
void USBHwEPStall(u8 bEP, BOOL fStall)
{
int idx = EP2IDX(bEP);
@ -349,7 +347,7 @@ void USBHwEPStall(U8 bEP, BOOL fStall)
@return TRUE if the data was successfully written or <0 in case of error.
*/
int USBHwEPWrite(U8 bEP, U8 *pbBuf, int iLen)
int USBHwEPWrite(u8 bEP, u8 *pbBuf, int iLen)
{
int idx;
@ -385,10 +383,10 @@ int USBHwEPWrite(U8 bEP, U8 *pbBuf, int iLen)
@return the number of bytes available in the EP (possibly more than iMaxLen),
or <0 in case of error.
*/
int USBHwEPRead(U8 bEP, U8 *pbBuf, int iMaxLen)
int USBHwEPRead(u8 bEP, u8 *pbBuf, int iMaxLen)
{
int i, idx;
U32 dwData, dwLen;
u32 dwData, dwLen;
idx = EP2IDX(bEP);
@ -455,11 +453,11 @@ void USBHwConfigDevice(BOOL fConfigured)
*/
void USBHwISR(void)
{
U32 dwStatus;
U32 dwIntBit;
U8 bEPStat, bDevStat, bStat;
u32 dwStatus;
u32 dwIntBit;
u8 bEPStat, bDevStat, bStat;
int i;
U16 wFrame;
u16 wFrame;
// LED9 monitors total time in interrupt routine
DEBUG_LED_ON(6);
@ -624,4 +622,3 @@ BOOL USBHwInit(void)
return TRUE;
}

View File

@ -30,16 +30,14 @@
USB stack initialisation
*/
// CodeRed - include the LPCUSB type.h file rather than NXP one directly
//#include "type.h"
#include "lpcusb_type.h"
#include "type.h"
#include "usbdebug.h"
#include "usbapi.h"
/** data storage area for standard requests */
static U8 abStdReqData[8];
static u8 abStdReqData[8];
/**
@ -47,7 +45,7 @@ static U8 abStdReqData[8];
@param [in] bDevStatus Device status
*/
static void HandleUsbReset(U8 bDevStatus)
static void HandleUsbReset(u8 bDevStatus)
{
if (bDevStatus & DEV_STATUS_RESET) {
DBG("\n!");
@ -82,4 +80,3 @@ BOOL USBInit(void)
return TRUE;
}

View File

@ -43,9 +43,7 @@
@todo SET_FEATURE, GET_FEATURE
*/
// CodeRed - include the LPCUSB type.h file rather than NXP one directly
//#include "type.h"
#include "lpcusb_type.h"
#include "type.h"
#include "usbdebug.h"
#include "usbstruct.h"
@ -72,11 +70,11 @@
/** Currently selected configuration */
static U8 bConfiguration = 0;
static u8 bConfiguration = 0;
/** Installed custom request handler */
static TFnHandleRequest *pfnHandleCustomReq = NULL;
/** Pointer to registered descriptors */
static const U8 *pabDescrip = NULL;
static const u8 *pabDescrip = NULL;
/**
@ -85,7 +83,7 @@ static const U8 *pabDescrip = NULL;
@param [in] pabDescriptors The descriptor byte array
*/
void USBRegisterDescriptors(const U8 *pabDescriptors)
void USBRegisterDescriptors(const u8 *pabDescriptors)
{
pabDescrip = pabDescriptors;
}
@ -102,10 +100,10 @@ void USBRegisterDescriptors(const U8 *pabDescriptors)
@return TRUE if the descriptor was found, FALSE otherwise
*/
BOOL USBGetDescriptor(U16 wTypeIndex, U16 wLangID, int *piLen, U8 **ppbData)
BOOL USBGetDescriptor(u16 wTypeIndex, u16 wLangID, int *piLen, u8 **ppbData)
{
U8 bType, bIndex;
U8 *pab;
u8 bType, bIndex;
u8 *pab;
int iCurIndex;
ASSERT(pabDescrip != NULL);
@ -113,7 +111,7 @@ BOOL USBGetDescriptor(U16 wTypeIndex, U16 wLangID, int *piLen, U8 **ppbData)
bType = GET_DESC_TYPE(wTypeIndex);
bIndex = GET_DESC_INDEX(wTypeIndex);
pab = (U8 *)pabDescrip;
pab = (u8 *)pabDescrip;
iCurIndex = 0;
while (pab[DESC_bLength] != 0) {
@ -156,12 +154,12 @@ BOOL USBGetDescriptor(U16 wTypeIndex, U16 wLangID, int *piLen, U8 **ppbData)
@return TRUE if successfully configured, FALSE otherwise
*/
static BOOL USBSetConfiguration(U8 bConfigIndex, U8 bAltSetting)
static BOOL USBSetConfiguration(u8 bConfigIndex, u8 bAltSetting)
{
U8 *pab;
U8 bCurConfig, bCurAltSetting;
U8 bEP;
U16 wMaxPktSize;
u8 *pab;
u8 bCurConfig, bCurAltSetting;
u8 bEP;
u16 wMaxPktSize;
ASSERT(pabDescrip != NULL);
@ -171,7 +169,7 @@ static BOOL USBSetConfiguration(U8 bConfigIndex, U8 bAltSetting)
}
else {
// configure endpoints for this configuration/altsetting
pab = (U8 *)pabDescrip;
pab = (u8 *)pabDescrip;
bCurConfig = 0xFF;
bCurAltSetting = 0xFF;
@ -225,9 +223,9 @@ static BOOL USBSetConfiguration(U8 bConfigIndex, U8 bAltSetting)
@return TRUE if the request was handled successfully
*/
static BOOL HandleStdDeviceReq(TSetupPacket *pSetup, int *piLen, U8 **ppbData)
static BOOL HandleStdDeviceReq(TSetupPacket *pSetup, int *piLen, u8 **ppbData)
{
U8 *pbData = *ppbData;
u8 *pbData = *ppbData;
switch (pSetup->bRequest) {
@ -294,9 +292,9 @@ static BOOL HandleStdDeviceReq(TSetupPacket *pSetup, int *piLen, U8 **ppbData)
@return TRUE if the request was handled successfully
*/
static BOOL HandleStdInterfaceReq(TSetupPacket *pSetup, int *piLen, U8 **ppbData)
static BOOL HandleStdInterfaceReq(TSetupPacket *pSetup, int *piLen, u8 **ppbData)
{
U8 *pbData = *ppbData;
u8 *pbData = *ppbData;
switch (pSetup->bRequest) {
@ -344,9 +342,9 @@ static BOOL HandleStdInterfaceReq(TSetupPacket *pSetup, int *piLen, U8 **ppbData
@return TRUE if the request was handled successfully
*/
static BOOL HandleStdEndPointReq(TSetupPacket *pSetup, int *piLen, U8 **ppbData)
static BOOL HandleStdEndPointReq(TSetupPacket *pSetup, int *piLen, u8 **ppbData)
{
U8 *pbData = *ppbData;
u8 *pbData = *ppbData;
switch (pSetup->bRequest) {
case REQ_GET_STATUS:
@ -398,7 +396,7 @@ static BOOL HandleStdEndPointReq(TSetupPacket *pSetup, int *piLen, U8 **ppbData)
@return TRUE if the request was handled successfully
*/
BOOL USBHandleStandardRequest(TSetupPacket *pSetup, int *piLen, U8 **ppbData)
BOOL USBHandleStandardRequest(TSetupPacket *pSetup, int *piLen, u8 **ppbData)
{
// try the custom request handler first
if ((pfnHandleCustomReq != NULL) && pfnHandleCustomReq(pSetup, piLen, ppbData)) {
@ -431,4 +429,3 @@ void USBRegisterCustomReqHandler(TFnHandleRequest *pfnHandler)
{
pfnHandleCustomReq = pfnHandler;
}