From 4c73571eac60dd16103157d484ce4d0f53f91ae5 Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Wed, 15 Jun 2011 17:28:05 -0400 Subject: Remove usb_hardware.c and usb_hardware.h. These files contain a lot of duplicated and unused code. Move the relevant pieces that need to survive into usb.c and usb_callbacks.c. Signed-off-by: Marti Bolivar --- libmaple/rules.mk | 1 - libmaple/usb/usb.c | 4 +- libmaple/usb/usb_callbacks.c | 5 +- libmaple/usb/usb_hardware.c | 96 ---------------------------------- libmaple/usb/usb_hardware.h | 121 ------------------------------------------- 5 files changed, 6 insertions(+), 221 deletions(-) delete mode 100644 libmaple/usb/usb_hardware.c delete mode 100644 libmaple/usb/usb_hardware.h (limited to 'libmaple') diff --git a/libmaple/rules.mk b/libmaple/rules.mk index 5e704a7..495c366 100644 --- a/libmaple/rules.mk +++ b/libmaple/rules.mk @@ -34,7 +34,6 @@ cSRCS_$(d) := adc.c \ usb/descriptors.c \ usb/usb.c \ usb/usb_callbacks.c \ - usb/usb_hardware.c \ usb/usb_lib/usb_core.c \ usb/usb_lib/usb_init.c \ usb/usb_lib/usb_int.c \ diff --git a/libmaple/usb/usb.c b/libmaple/usb/usb.c index 173673e..1754360 100644 --- a/libmaple/usb/usb.c +++ b/libmaple/usb/usb.c @@ -34,9 +34,9 @@ #include "libmaple.h" #include "usb_lib.h" #include "gpio.h" -#include "usb_hardware.h" #include "delay.h" #include "nvic.h" +#include "rcc.h" #include "usb_config.h" #include "usb_callbacks.h" @@ -104,7 +104,7 @@ void usb_cdcacm_enable(gpio_dev *disc_dev, uint8 disc_bit) { gpio_set_mode(disc_dev, disc_bit, GPIO_OUTPUT_PP); /* setup the apb1 clock for USB */ - pRCC->APB1ENR |= 0x00800000; + RCC_BASE->APB1ENR |= 0x00800000; /* initialize the usb application */ gpio_write_bit(disc_dev, disc_bit, 0); // presents us to the host diff --git a/libmaple/usb/usb_callbacks.c b/libmaple/usb/usb_callbacks.c index b2edd8a..72f97ad 100644 --- a/libmaple/usb/usb_callbacks.c +++ b/libmaple/usb/usb_callbacks.c @@ -7,7 +7,10 @@ #include "descriptors.h" #include "usb_config.h" #include "usb.h" -#include "usb_hardware.h" + +/* macro'd register and peripheral definitions */ +#define EXC_RETURN 0xFFFFFFF9 +#define DEFAULT_CPSR 0x61000000 ONE_DESCRIPTOR Device_Descriptor = { (uint8*)&usbVcomDescriptor_Device, diff --git a/libmaple/usb/usb_hardware.c b/libmaple/usb/usb_hardware.c deleted file mode 100644 index e7fd078..0000000 --- a/libmaple/usb/usb_hardware.c +++ /dev/null @@ -1,96 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 LeafLabs LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file usb_hardware.c - * - * @brief init routines to setup clocks and interrupts for usb. - * - */ - -#include "nvic.h" -#include "usb_hardware.h" - -void nvicInit(NVIC_InitTypeDef* NVIC_InitStruct) { - u32 tmppriority = 0x00; - u32 tmpreg = 0x00; - u32 tmpmask = 0x00; - u32 tmppre = 0; - u32 tmpsub = 0x0F; - - SCB_TypeDef* rSCB = (SCB_TypeDef *) SCB_BASE_ADDR; - - /* Compute the Corresponding IRQ Priority -------------------------------*/ - tmppriority = (0x700 - (rSCB->AIRCR & (u32)0x700))>> 0x08; - tmppre = (0x4 - tmppriority); - tmpsub = tmpsub >> tmppriority; - - tmppriority = (u32)NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority << - tmppre; - tmppriority |= NVIC_InitStruct->NVIC_IRQChannelSubPriority & tmpsub; - - tmppriority = tmppriority << 0x04; - tmppriority = ((u32)tmppriority) << - ((NVIC_InitStruct->NVIC_IRQChannel & (u8)0x03) * 0x08); - - tmpreg = NVIC_BASE->IP[(NVIC_InitStruct->NVIC_IRQChannel >> 0x02)]; - tmpmask = (u32)0xFF << - ((NVIC_InitStruct->NVIC_IRQChannel & (u8)0x03) * 0x08); - tmpreg &= ~tmpmask; - tmppriority &= tmpmask; - tmpreg |= tmppriority; - - NVIC_BASE->IP[(NVIC_InitStruct->NVIC_IRQChannel >> 0x02)] = tmpreg; - - /* Enable the Selected IRQ Channels -------------------------------------*/ - NVIC_BASE->ISER[(NVIC_InitStruct->NVIC_IRQChannel >> 0x05)] = - (u32)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (u8)0x1F); -} - -void nvicDisableInterrupts() { - nvic_irq_disable_all(); - NVIC_BASE->ICPR[0] = 0xFFFFFFFF; - NVIC_BASE->ICPR[1] = 0xFFFFFFFF; - - /* Disable the systick timer, which operates separately from NVIC */ - SET_REG(STK_CTRL,0x04); -} - -void systemHardReset(void) { - SCB_TypeDef* rSCB = (SCB_TypeDef *) SCB_BASE_ADDR; - typedef void (*funcPtr)(void); - - /* Reset */ - rSCB->AIRCR = (u32)AIRCR_RESET_REQ; - - /* Should never get here */ - while (1) { - asm volatile("nop"); - } -} - - - diff --git a/libmaple/usb/usb_hardware.h b/libmaple/usb/usb_hardware.h deleted file mode 100644 index 6f347bb..0000000 --- a/libmaple/usb/usb_hardware.h +++ /dev/null @@ -1,121 +0,0 @@ -/* ***************************************************************************** - * The MIT License - * - * Copyright (c) 2010 LeafLabs LLC. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * ****************************************************************************/ - -#include "rcc.h" -#include "usb_type.h" - -#ifndef _USB_HARDWARE_H_ -#define _USB_HARDWARE_H_ - -/* macro'd register and peripheral definitions */ -#define EXC_RETURN 0xFFFFFFF9 -#define DEFAULT_CPSR 0x61000000 - -#define FLASH ((u32)0x40022000) - -#define USB_PACKET_BUFFER ((u32)0x40006000) - -#define SCS_BASE_ADDR ((u32)0xE000E000) -#define SCB_BASE_ADDR (SCS_BASE_ADDR + 0x0D00) - -#define SCS 0xE000E000 -#define NVIC (SCS+0x100) -#define SCB (SCS+0xD00) -#define STK (SCS+0x10) - -#define SCB_VTOR (SCB+0x08) -#define STK_CTRL (STK+0x00) - -#define USB_HP_IRQ ((u8)0x13) -#define USB_LP_IRQ ((u8)0x14) - -/* AIRCR */ -#define AIRCR_RESET 0x05FA0000 -#define AIRCR_RESET_REQ (AIRCR_RESET | (u32)0x04); - -/* temporary copyage of example from kiel */ -#define __VAL(__TIMCLK, __PERIOD) ((__TIMCLK/1000000UL)*__PERIOD) -#define __PSC(__TIMCLK, __PERIOD) (((__VAL(__TIMCLK, __PERIOD)+49999UL)/50000UL) - 1) -#define __ARR(__TIMCLK, __PERIOD) ((__VAL(__TIMCLK, __PERIOD)/(__PSC(__TIMCLK, __PERIOD)+1)) - 1) - -#define SET_REG(addr,val) do { *(vu32*)(addr)=val; } while (0) -#define GET_REG(addr) do { *(vu32*)(addr); } while (0) - -#if defined(__cplusplus) -extern "C" { -#endif - -/* todo: there must be some major misunderstanding in how we access regs. The direct access approach (GET_REG) - causes the usb init to fail upon trying to activate RCC_APB1 |= 0x00800000. However, using the struct approach - from ST, it works fine...temporarily switching to that approach */ -typedef struct -{ - vu32 CR; - vu32 CFGR; - vu32 CIR; - vu32 APB2RSTR; - vu32 APB1RSTR; - vu32 AHBENR; - vu32 APB2ENR; - vu32 APB1ENR; - vu32 BDCR; - vu32 CSR; -} RCC_RegStruct; -#define pRCC ((RCC_RegStruct *) RCC_BASE) - -typedef struct { - u8 NVIC_IRQChannel; - u8 NVIC_IRQChannelPreemptionPriority; - u8 NVIC_IRQChannelSubPriority; - USB_Bool NVIC_IRQChannelCmd; /* TRUE for enable */ -} NVIC_InitTypeDef; - -typedef struct { - vuc32 CPUID; - vu32 ICSR; - vu32 VTOR; - vu32 AIRCR; - vu32 SCR; - vu32 CCR; - vu32 SHPR[3]; - vu32 SHCSR; - vu32 CFSR; - vu32 HFSR; - vu32 DFSR; - vu32 MMFAR; - vu32 BFAR; - vu32 AFSR; -} SCB_TypeDef; - - -void systemHardReset(void); - -void nvicInit (NVIC_InitTypeDef*); -void nvicDisableInterrupts(void); - -#if defined(__cplusplus) -} -#endif - -#endif -- cgit v1.2.3