Library to access LPC17xx peripherals. It uses static inline functions, constant propagation and dead code elimination to be as fast as possible.
Dependents: Chua-VGA Wolfram-1D-VGA WolframRnd-1D-VGA Basin-VGA ... more
Revision 0:7a91348b4a02, committed 2011-07-03
- Comitter:
- Ivop
- Date:
- Sun Jul 03 17:11:55 2011 +0000
- Child:
- 1:bc492a93e116
- Commit message:
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TODO.h Sun Jul 03 17:11:55 2011 +0000 @@ -0,0 +1,20 @@ +/* on a "need to have" basis :) + * + * adc + * can + * dac + * ethernet + * external interrupts + * i2c + * mcpwm + * mpu (memory protection unit) + * quadrature encoder interface + * repetitive interrupt timer + * spi + * ssp + * system timer (systick) + * timer + * usb + * watchdog timer + * + */ \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/clock.h Sun Jul 03 17:11:55 2011 +0000 @@ -0,0 +1,203 @@ +/* Copyright (C) 2010, 2011 by Ivo van Poorten <ivop@euronet.nl> + * This file is licensed under the terms of the GNU Lesser + * General Public License, version 3. + */ + +/* see chapter 4 of user manual for details on clocks and power */ + +#ifndef FASTLIB_CLKPWR_H +#define FASTLIB_CLKPWR_H + +#include "fastlib/common.h" + +#define FL_CLKSRCSEL ((volatile uint32_t *) 0x400FC10C) + +#define FL_PLL0CON ((volatile uint32_t *) 0x400FC080) +#define FL_PLL0CFG ((volatile uint32_t *) 0x400FC084) +#define FL_PLL0STAT ((volatile uint32_t *) 0x400FC088) +#define FL_PLL0FEED ((volatile uint32_t *) 0x400FC08C) + +#define FL_PLL1CON ((volatile uint32_t *) 0x400FC0A0) +#define FL_PLL1CFG ((volatile uint32_t *) 0x400FC0A4) +#define FL_PLL1STAT ((volatile uint32_t *) 0x400FC0A8) +#define FL_PLL1FEED ((volatile uint32_t *) 0x400FC0AC) + +#define FL_CCLKCFG ((volatile uint32_t *) 0x400FC104) +#define FL_USBCLKCFG ((volatile uint32_t *) 0x400FC108) +#define FL_PCLKSEL0 ((volatile uint32_t *) 0x400FC1A8) +#define FL_PCLKSEL1 ((volatile uint32_t *) 0x400FC1AC) + +#define FL_CLKOUTCFG ((volatile uint32_t *) 0x400FC1C8) + +/* Internal RC oscillator, nominal frequency is 4MHz + * Main oscillator --> mbed: 12MHz slave mode + * RTC oscillator --> mbed: FC-135 32.7680kHz 12.5pF + */ + +/* for USB, use only Main oscillator + * for CAN over 100 kbit/s, do not use Internal RC oscillator + */ + +#define FL_PLL0_CLOCK_SOURCE_INTERNAL 0 +#define FL_PLL0_CLOCK_SOURCE_MAIN 1 +#define FL_PLL0_CLOCK_SOURCE_RTC 2 + +static inline void fl_select_pll0_clock_source(const int source) { + *FL_CLKSRCSEL = source; +} + +/* PLL0: + * input source --> PLL input divider (N) --> PLL multiplier (M) + * + * input: 32kHz-50MHz --> + * N: 1-256 --> + * M: 6-512 --> 275MHz-550MHz + * + * PLL0 output dividers below + */ + +static inline void fl_pll0_control(const int enable, const int connect) { + *FL_PLL0CON = enable | (connect<<1); +} + +static inline void fl_pll0_config(const unsigned int N, const unsigned int M) { + *FL_PLL0CFG = (M-1) | ((N-1)<<16); +} + +static inline unsigned fl_pll0_get_M(void) { + return (*FL_PLL0STAT & 0x7fff) + 1; +} + +static inline unsigned fl_pll0_get_N(void) { + return ((*FL_PLL0STAT >> 16) & 0xff) + 1; +} + +static inline int fl_pll0_get_enable(void) { + return *FL_PLL0STAT & (1U<<24); +} + +static inline int fl_pll0_get_connect(void) { + return *FL_PLL0STAT & (1U<<25); +} + +static inline int fl_pll0_get_lock(void) { + return *FL_PLL0STAT & (1U<<26); +} + +static inline void fl_pll0_feed(void) { + *FL_PLL0FEED = 0xaa; + *FL_PLL0FEED = 0x55; +} + +/* PLL1: + * input main oscillator --> PLL multiplier (M) --> output divider (2P) + */ + +static inline void fl_pll1_control(const int enable, const int connect) { + *FL_PLL1CON = enable | (connect<<1); +} + +static inline void fl_pll1_config(const unsigned int M, const unsigned int P) { + *FL_PLL1CFG = M | (P<<5); +} + +static inline int fl_pll1_get_M(void) { + return *FL_PLL1STAT & 0x1f; +} + +static inline int fl_pll1_get_P(void) { + return (*FL_PLL1STAT >> 5) & 3; +} + +static inline int fl_pll1_get_enable(void) { + return *FL_PLL1STAT & (1U<<8); +} + +static inline int fl_pll1_get_connect(void) { + return *FL_PLL1STAT & (1U<<9); +} + +static inline int fl_pll1_get_lock(void) { + return *FL_PLL1STAT & (1U<<10); +} + +static inline void fl_pll1_feed(void) { + *FL_PLL1FEED = 0xaa; + *FL_PLL1FEED = 0x55; +} + +/* PLL0 output --> CPU Clock */ + +/* CPU clock must be at least 18MHz for USB to function */ + +/* div: 3-256 */ +static inline void fl_set_cpu_clock_divider(const int div) { + *FL_CCLKCFG = div - 1; +} + +static inline int fl_get_cpu_clock_divider(void) { + return *FL_CCLKCFG + 1; +} + +/* use only if USBPLL/PLL1 is not connected */ +/* div: 1-16 (only 6, 8 and 10 produce even number multiples */ +static inline void fl_set_pll0_usb_divider(const unsigned int div) { + *FL_USBCLKCFG = div - 1; +} + +static inline int fl_get_pll0_usb_divider(void) { + return *FL_USBCLKCFG + 1; +} + +#define FL_CLOCK_DIV4 0 +#define FL_CLOCK_DIV1 1 +#define FL_CLOCK_DIV2 2 +#define FL_CLOCK_DIV8 3 + +#define FL_SELECT_CLOCK(peripheral, reg, pos) \ + static inline void fl_select_clock_##peripheral(const unsigned int clock) { \ + *reg &= ~(3U << pos); \ + *reg |= clock << pos; \ +} + +FL_SELECT_CLOCK(wdt, FL_PCLKSEL0, 0) +FL_SELECT_CLOCK(timer0, FL_PCLKSEL0, 2) +FL_SELECT_CLOCK(timer1, FL_PCLKSEL0, 4) +FL_SELECT_CLOCK(uart0, FL_PCLKSEL0, 6) +FL_SELECT_CLOCK(uart1, FL_PCLKSEL0, 8) +FL_SELECT_CLOCK(pwm1, FL_PCLKSEL0, 12) +FL_SELECT_CLOCK(i2c0, FL_PCLKSEL0, 14) +FL_SELECT_CLOCK(spi, FL_PCLKSEL0, 16) +FL_SELECT_CLOCK(ssp1, FL_PCLKSEL0, 20) +FL_SELECT_CLOCK(dac, FL_PCLKSEL0, 22) +FL_SELECT_CLOCK(adc, FL_PCLKSEL0, 24) +FL_SELECT_CLOCK(can1, FL_PCLKSEL0, 26) +FL_SELECT_CLOCK(can2, FL_PCLKSEL0, 28) +FL_SELECT_CLOCK(acf, FL_PCLKSEL0, 30) + +FL_SELECT_CLOCK(qei, FL_PCLKSEL1, 0) +FL_SELECT_CLOCK(gpioint, FL_PCLKSEL1, 2) +FL_SELECT_CLOCK(pcb, FL_PCLKSEL1, 4) +FL_SELECT_CLOCK(i2c1, FL_PCLKSEL1, 6) +FL_SELECT_CLOCK(ssp0, FL_PCLKSEL1, 10) +FL_SELECT_CLOCK(timer2, FL_PCLKSEL1, 12) +FL_SELECT_CLOCK(timer3, FL_PCLKSEL1, 14) +FL_SELECT_CLOCK(uart2, FL_PCLKSEL1, 16) +FL_SELECT_CLOCK(uart3, FL_PCLKSEL1, 18) +FL_SELECT_CLOCK(i2c2, FL_PCLKSEL1, 20) +FL_SELECT_CLOCK(i2s, FL_PCLKSEL1, 22) +FL_SELECT_CLOCK(rit, FL_PCLKSEL1, 26) +FL_SELECT_CLOCK(syscon, FL_PCLKSEL1, 28) +FL_SELECT_CLOCK(mcpwm, FL_PCLKSEL1, 30) + +#define FL_CLOCK_OUT_CPU 0 +#define FL_CLOCK_OUT_MAIN 1 +#define FL_CLOCK_OUT_IRC 2 +#define FL_CLOCK_OUT_USB 3 +#define FL_CLOCK_OUT_RTC 4 + +static inline void fl_set_output_clock(const int clock) { + *FL_CLKOUTCFG = clock; +} + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/common.h Sun Jul 03 17:11:55 2011 +0000 @@ -0,0 +1,45 @@ +/* Copyright (C) 2010, 2011 by Ivo van Poorten <ivop@euronet.nl> + * This file is licensed under the terms of the GNU Lesser + * General Public License, version 3. + */ + +#ifndef FASTLIB_COMMON_H +#define FASTLIB_COMMON_H + +#include <stdint.h> + +#define FL_IGNORE (-1) + +#define FL_OFF 0 +#define FL_ON 1 + +#define FL_INPUT 0 +#define FL_OUTPUT 1 + +#define FL_RISE 0 +#define FL_FALL 1 +#define FL_BOTH 2 + +#define FL_DISABLE 0 +#define FL_ENABLE 1 + +#define FL_DISCONNECT 0 +#define FL_CONNECT 1 + +#define FL_SINGLE_EDGE 0 +#define FL_DOUBLE_EDGE 1 + +#define FL_8BITS 0 +#define FL_16BITS 1 +#define FL_32BITS 3 + +#define FL_STEREO 0 +#define FL_MONO 1 + +#define FL_MASTER 0 +#define FL_SLAVE 1 + +#define FL_LITTLE_ENDIAN 0 +#define FL_BIG_ENDIAN 1 + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dma.h Sun Jul 03 17:11:55 2011 +0000 @@ -0,0 +1,265 @@ +/* Copyright (C) 2010, 2011 by Ivo van Poorten <ivop@euronet.nl> + * This file is licensed under the terms of the GNU Lesser + * General Public License, version 3. + */ + +#ifndef FASTLIB_DMA_H +#define FASTLIB_DMA_H + +#include "fastlib/common.h" + +#define FL_DMACIntStat ((volatile uint32_t *) 0x50004000) +#define FL_DMACIntTCStat ((volatile uint32_t *) 0x50004004) +#define FL_DMACIntTCClear ((volatile uint32_t *) 0x50004008) +#define FL_DMACIntErrStat ((volatile uint32_t *) 0x5000400C) +#define FL_DMACIntErrClr ((volatile uint32_t *) 0x50004010) +#define FL_DMACRawIntTCStat ((volatile uint32_t *) 0x50004014) +#define FL_DMACRawIntErrStat ((volatile uint32_t *) 0x50004018) +#define FL_DMACEnbldChns ((volatile uint32_t *) 0x5000401C) +#define FL_DMACSoftBReq ((volatile uint32_t *) 0x50004020) +#define FL_DMACSoftSReq ((volatile uint32_t *) 0x50004024) +#define FL_DMACSoftLBReq ((volatile uint32_t *) 0x50004028) +#define FL_DMACSoftLSReq ((volatile uint32_t *) 0x5000402C) +#define FL_DMACConfig ((volatile uint32_t *) 0x50004030) +#define FL_DMACSync ((volatile uint32_t *) 0x50004034) +#define FL_DMAReqSel ((volatile uint32_t *) 0x400FC1C4) + +#define FL_DMACC0 0x50004100 +#define FL_DMACC1 0x50004120 +#define FL_DMACC2 0x50004140 +#define FL_DMACC3 0x50004160 +#define FL_DMACC4 0x50004180 +#define FL_DMACC5 0x500041A0 +#define FL_DMACC6 0x500041C0 +#define FL_DMACC7 0x500041E0 + +#define FL_DMA_SrcAddr 0x00 +#define FL_DMA_DestAddr 0x04 +#define FL_DMA_LLI 0x08 +#define FL_DMA_Control 0x0C +#define FL_DMA_Config 0x10 + +#define FL_DMA(channel, field) \ + ((volatile uint32_t *)(fl_dma_channel_to_base(channel) + FL_DMA_##field)) + +static inline unsigned fl_dma_channel_to_base(const unsigned channel) { + switch(channel) { + case 0: return FL_DMACC0; + case 1: return FL_DMACC1; + case 2: return FL_DMACC2; + case 3: return FL_DMACC3; + case 4: return FL_DMACC4; + case 5: return FL_DMACC5; + case 6: return FL_DMACC6; + default: return FL_DMACC7; + } +} + +// channel: 0-7 +static inline unsigned fl_dma_channel_has_active_interrupt_request(const unsigned channel) { + return *FL_DMACIntStat & (1U<<channel); +} + +static inline unsigned fl_dma_channel_has_active_terminal_count_interrupt_request(const unsigned channel) { + return *FL_DMACIntTCStat & (1U<<channel); +} +static inline void fl_dma_clear_terminal_count_interrupt_request(const unsigned channel) { + *FL_DMACIntTCClear |= 1U<<channel; +} +static inline unsigned fl_dma_channel_has_active_terminal_count_interrupt_request_raw(const unsigned channel) { + return *FL_DMACRawIntTCStat & (1U<<channel); // raw is prior to masking +} + +static inline unsigned fl_dma_channel_has_active_error_interrupt_request(const unsigned channel) { + return *FL_DMACIntErrStat & (1U<<channel); +} +static inline void fl_dma_clear_error_interrupt_request(const unsigned channel) { + *FL_DMACIntErrClr |= 1U<<channel; +} +static inline unsigned fl_dma_channel_has_active_error_interrupt_request_raw(const unsigned channel) { + return *FL_DMACRawIntErrStat & (1U<<channel); +} + +static inline unsigned fl_dma_channel_is_enabled(const unsigned channel) { + return *FL_DMACEnbldChns & (1U<<channel); +} + +static inline void fl_dma_generate_software_burst_request(const unsigned request) { + *FL_DMACSoftBReq |= 1U << request; +} +static inline unsigned fl_dma_software_burst_request_sources(void) { + return *FL_DMACSoftBReq; +} + +static inline void fl_dma_generate_software_single_request(const unsigned request) { + *FL_DMACSoftSReq |= 1U << request; +} +static inline unsigned fl_dma_software_single_request_sources(void) { + return *FL_DMACSoftSReq; +} + +static inline void fl_dma_generate_software_last_burst_request(const unsigned request) { + *FL_DMACSoftLBReq |= 1U << request; +} +static inline unsigned fl_dma_software_last_burst_request_sources(void) { + return *FL_DMACSoftLBReq; +} + +static inline void fl_dma_generate_software_last_single_request(const unsigned request) { + *FL_DMACSoftLSReq |= 1U << request; +} +static inline unsigned fl_dma_software_last_single_request_sources(void) { + return *FL_DMACSoftLSReq; +} + +static inline void fl_dma_enable(const unsigned state) { + if (state) *FL_DMACConfig |= 1U<<0 ; + else *FL_DMACConfig &= ~(1U<<0); +} + +static inline unsigned fl_dma_is_enabled(void) { + return *FL_DMACConfig & 1; +} + +static inline void fl_dma_set_endianness(const unsigned endianness) { + if (endianness) *FL_DMACConfig |= 1U<<1 ; + else *FL_DMACConfig &= ~(1U<<1); +} + +static inline void fl_dma_request_synchronization_enable(const unsigned request, const unsigned state) { + if (!state) *FL_DMACSync |= 1U<<request ; // note that 0 is enabled + else *FL_DMACSync &= ~(1U<<request); +} + +#define FL_DMA_UART 0 +#define FL_DMA_TIMER 1 + +// select between uart or timer dma requests for inputs 8 through 15 +// input: 8-16 which: 0-1 +static inline void fl_dma_request_select(const unsigned input, const unsigned which) { + if (which) *FL_DMAReqSel |= 1U<<(which-8) ; + else *FL_DMAReqSel &= ~(1U<<(which-8)); +} + +// channel: 0-7 +static inline void fl_dma_set_srcaddr(const unsigned channel, const void *srcaddr) { + *FL_DMA(channel, SrcAddr) = (unsigned) srcaddr; +} + +static inline void fl_dma_set_destaddr(const unsigned channel, const void *destaddr) { + *FL_DMA(channel, DestAddr) = (unsigned) destaddr; +} + +// lli must be word-aligned +static inline void fl_dma_set_next_lli(const unsigned channel, const void *lli) { + *FL_DMA(channel, LLI) = (unsigned) lli & (~3U); +} + +#define FL_NO_SRC_INCREMENT 0 +#define FL_SRC_INCREMENT 1 +#define FL_NO_DEST_INCREMENT 0 +#define FL_DEST_INCREMENT 1 + +static inline unsigned fl_dma_size_to_mask(const unsigned size) { + switch(size) { + case 4: return 1; + case 8: return 2; + case 16: return 3; + case 32: return 4; + case 64: return 5; + case 128: return 6; + case 256: return 7; + default: return 0; + } +} + +static inline unsigned fl_dma_width_to_mask(const unsigned width) { + switch(width) { + case 16: return 1; + case 32: return 2; + default: return 0; + } +} + +// transfer_size: 12 bits +// size: 1, 4, 8, 16, 32, 64, 128 or 256 +// width: 8, 16 or 32 +// irq: 0-1 +static inline void fl_dma_channel_control(const unsigned channel, const unsigned transfer_size, + const unsigned src_burst_size, const unsigned dest_burst_size, + const unsigned src_width, const unsigned dest_width, + const unsigned src_increment, const unsigned dest_increment, + const unsigned terminal_count_irq) { + *FL_DMA(channel, Control) = transfer_size & 0xfff + | (fl_dma_size_to_mask(src_burst_size) << 12) + | (fl_dma_size_to_mask(dest_burst_size) << 15) + | (fl_dma_width_to_mask(src_width) << 18) + | (fl_dma_width_to_mask(dest_width) << 21) + | (src_increment << 26) + | (dest_increment << 27) + | (terminal_count_irq << 31); +} + +static inline void fl_dma_channel_control_by_mask(const unsigned channel, const unsigned mask) { + *FL_DMA(channel, Control) = mask; +} + +static inline unsigned fl_dma_channel_get_control_mask(const unsigned channel) { + return *FL_DMA(channel, Control); +} + +static inline void fl_dma_channel_terminal_count_irq_enable(const unsigned channel, const unsigned state) { + if (state) *FL_DMA(channel, Control) |= 1U<<31 ; + else *FL_DMA(channel, Control) &= ~(1U<<31); +} + +// channel configuration constants, src and dest peripherals +#define FL_DMA_SINGLE_REQUEST_SSP0_Tx 0 +#define FL_DMA_SINGLE_REQUEST_SSP0_Rx 1 +#define FL_DMA_SINGLE_REQUEST_SSP1_Tx 2 +#define FL_DMA_SINGLE_REQUEST_SSP1_Rx 3 +#define FL_DMA_SINGLE_REQUEST_ADC 4 + +#define FL_DMA_BURST_REQUEST_SSP0_Tx 0 +#define FL_DMA_BURST_REQUEST_SSP0_Rx 1 +#define FL_DMA_BURST_REQUEST_SSP1_Tx 2 +#define FL_DMA_BURST_REQUEST_SSP1_Rx 3 +#define FL_DMA_BURST_REQUEST_ADC 4 +#define FL_DMA_BURST_REQUEST_I2S_CH0 5 +#define FL_DMA_BURST_REQUEST_I2S_CH1 6 +#define FL_DMA_BURST_REQUEST_DAC 7 +#define FL_DMA_BURST_REQUEST_UART0_Tx 8 +#define FL_DMA_BURST_REQUEST_UART0_Rx 9 +#define FL_DMA_BURST_REQUEST_UART1_Tx 10 +#define FL_DMA_BURST_REQUEST_uART1_Rx 11 +#define FL_DMA_BURST_REQUEST_UART2_Tx 12 +#define FL_DMA_BURST_REQUEST_UART2_Rx 13 +#define FL_DMA_BURST_REQUEST_UART3_Tx 14 +#define FL_DMA_BURST_REQUEST_UART3_Rx 15 + +#define FL_DMA_PERIPHERAL_IS_MEMORY 0 + +// transfer types +#define FL_DMA_MEMORY_TO_MEMORY 0 +#define FL_DMA_MEMORY_TO_PERIPHERAL 1 +#define FL_DMA_PERIPHERAL_TO_MEMORY 2 +#define FL_DMA_PERIPHERAL_TO_PERIPHERAL 3 + +static inline void fl_dma_channel_config(const unsigned channel, + const unsigned enable, const unsigned src_peripheral, const unsigned dest_peripheral, + const unsigned transfer_type, const unsigned mask_error, const unsigned mask_tc) { + *FL_DMA(channel, Config) = enable | (src_peripheral<<1) | (dest_peripheral<<6) | + (transfer_type<<11) | (mask_error<<14) | (mask_tc<<15); +} + +// return 0 or !0 (channel fifo has data) +static inline unsigned fl_dma_channel_is_active(const unsigned channel) { + return *FL_DMA(channel, Config) & (1U<<17); +} + +static inline void fl_dma_channel_halt(const unsigned channel, const unsigned state) { + if (state) *FL_DMA(channel, Config) |= 1U<<18 ; + else *FL_DMA(channel, Config) &= ~(1U<<18); +} + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gpio.h Sun Jul 03 17:11:55 2011 +0000 @@ -0,0 +1,104 @@ +/* Copyright (C) 2010, 2011 by Ivo van Poorten <ivop@euronet.nl> + * This file is licensed under the terms of the GNU Lesser + * General Public License, version 3. + */ + +#ifndef FASTLIB_GPIO_H +#define FASTLIB_GPIO_H + +#include "fastlib/common.h" + +static inline volatile uint32_t *fl_gpio_get_base(const int port) { + switch (port) { + case 0: return (volatile uint32_t *) 0x2009c000; + case 1: return (volatile uint32_t *) 0x2009c020; + case 2: return (volatile uint32_t *) 0x2009c040; + case 3: return (volatile uint32_t *) 0x2009c060; + case 4: return (volatile uint32_t *) 0x2009c080; + default: return (volatile uint32_t *) 0; + } +} + +#define FL_GPIO_OVERALL_INT_STATUS ((volatile uint32_t *) 0x40028080) + +#define FL_GPIO_PORT0_RISE_INT_STATUS ((volatile uint32_t *) 0x40028084) +#define FL_GPIO_PORT0_FALL_INT_STATUS ((volatile uint32_t *) 0x40028088) +#define FL_GPIO_PORT0_INT_CLEAR ((volatile uint32_t *) 0x4002808C) +#define FL_GPIO_PORT0_RISE_INT ((volatile uint32_t *) 0x40028090) +#define FL_GPIO_PORT0_FALL_INT ((volatile uint32_t *) 0x40028094) + +#define FL_GPIO_PORT2_RISE_INT_STATUS ((volatile uint32_t *) 0x400280A4) +#define FL_GPIO_PORT2_FALL_INT_STATUS ((volatile uint32_t *) 0x400280A8) +#define FL_GPIO_PORT2_INT_CLEAR ((volatile uint32_t *) 0x400280AC) +#define FL_GPIO_PORT2_RISE_INT ((volatile uint32_t *) 0x400280B0) +#define FL_GPIO_PORT2_FALL_INT ((volatile uint32_t *) 0x400280B4) + +/* dir: 0=input, 1=output */ +static inline void fl_gpio_set_direction(const unsigned port, const unsigned int bitmask, const unsigned dir) { + if (dir) *(fl_gpio_get_base(port)) |= bitmask; + else *(fl_gpio_get_base(port)) &= ~bitmask; +} + +static inline void fl_gpio_set_value(const unsigned port, const unsigned bitmask) { + *(fl_gpio_get_base(port) + 6) = bitmask; +} + +static inline void fl_gpio_clear_value(const unsigned port, const unsigned bitmask) { + *(fl_gpio_get_base(port) + 7) = bitmask; +} + +static inline uint32_t fl_gpio_get_value(const unsigned port, const unsigned bitmask) { + return *(fl_gpio_get_base(port) + 5); +} + +static inline void fl_gpio_set_mask(const unsigned port, const unsigned bitmask) { + *(fl_gpio_get_base(port) + 4) |= bitmask; +} + +static inline void fl_gpio_clear_mask(const unsigned port, const unsigned bitmask) { + *(fl_gpio_get_base(port) + 4) &= ~bitmask; +} + +/* interrupts only on port 0 or 2 */ + +/* return: 0 = none, !0 = at least one */ +static inline int fl_gpio_port_interrupt_status(const unsigned port) { + return *FL_GPIO_OVERALL_INT_STATUS & (1U<<port); +} + +static inline void fl_gpio_interrupt_enable(const unsigned port, const unsigned bitmask, const unsigned edge) { + if (port == 0) { + if (edge == FL_RISE) *FL_GPIO_PORT0_RISE_INT |= bitmask; + else *FL_GPIO_PORT0_FALL_INT |= bitmask; + } else { + if (edge == FL_RISE) *FL_GPIO_PORT2_RISE_INT |= bitmask; + else *FL_GPIO_PORT2_FALL_INT |= bitmask; + } +} + +static inline void fl_gpio_interrupt_disable(const unsigned port, const unsigned bitmask, const unsigned edge) { + if (port == 0) { + if (edge == FL_RISE) *FL_GPIO_PORT0_RISE_INT &= ~bitmask; + else *FL_GPIO_PORT0_FALL_INT &= ~bitmask; + } else { + if (edge == FL_RISE) *FL_GPIO_PORT2_RISE_INT &= ~bitmask; + else *FL_GPIO_PORT2_FALL_INT &= ~bitmask; + } +} + +static inline uint32_t fl_gpio_interrupt_status(const unsigned port, const unsigned bitmask, const unsigned edge) { + if (port == 0) { + if (edge == FL_RISE) return *FL_GPIO_PORT0_RISE_INT_STATUS & bitmask; + else return *FL_GPIO_PORT0_FALL_INT_STATUS & bitmask; + } else { + if (edge == FL_RISE) return *FL_GPIO_PORT2_RISE_INT_STATUS & bitmask; + else return *FL_GPIO_PORT2_FALL_INT_STATUS & bitmask; + } +} + +static inline void fl_gpio_interrupt_clear(const unsigned port, const unsigned bitmask) { + if (port == 0) *FL_GPIO_PORT0_INT_CLEAR = bitmask; + else *FL_GPIO_PORT2_INT_CLEAR = bitmask; +} + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/i2s.h Sun Jul 03 17:11:55 2011 +0000 @@ -0,0 +1,139 @@ +/* Copyright (C) 2010, 2011 by Ivo van Poorten <ivop@euronet.nl> + * This file is licensed under the terms of the GNU Lesser + * General Public License, version 3. + */ + +#ifndef FASTLIB_I2S_H +#define FASTLIB_I2S_H + +#include "fastlib/common.h" + +/* important: in mono mode, each word is transmitted twice(!) */ + +#define FL_I2SDAO ((volatile uint32_t *) 0x400A8000) +#define FL_I2SDAI ((volatile uint32_t *) 0x400A8004) +#define FL_I2STXFIFO ((volatile uint32_t *) 0x400A8008) +#define FL_I2SRXFIFO ((volatile uint32_t *) 0x400A800C) +#define FL_I2SSTATE ((volatile uint32_t *) 0x400A8010) +#define FL_I2SDMA1 ((volatile uint32_t *) 0x400A8014) +#define FL_I2SDMA2 ((volatile uint32_t *) 0x400A8018) +#define FL_I2SIRQ ((volatile uint32_t *) 0x400A801C) +#define FL_I2STXRATE ((volatile uint32_t *) 0x400A8020) +#define FL_I2SRXRATE ((volatile uint32_t *) 0x400A8024) +#define FL_I2STXBITRATE ((volatile uint32_t *) 0x400A8028) +#define FL_I2SRXBITRATE ((volatile uint32_t *) 0x400A802C) +#define FL_I2STXMODE ((volatile uint32_t *) 0x400A8030) +#define FL_I2SRXMODE ((volatile uint32_t *) 0x400A8034) + +static inline void fl_i2s_output_set_config(const unsigned width, const unsigned mono, const unsigned halfperiod, + const unsigned stop, const unsigned reset, const unsigned mute, const unsigned slave) { + *FL_I2SDAO = width | (mono<<2) | ((halfperiod-1)<<6) | (stop<<3) | (reset<<4) | (mute<<15) | (slave<<5); +} + +static inline unsigned fl_i2s_output_get_config(void) { + return *FL_I2SDAO; +} + +static inline void fl_i2s_input_set_config(const unsigned width, const unsigned mono, const unsigned halfperiod, + const unsigned stop, const unsigned reset, const unsigned mute, const unsigned slave) { + *FL_I2SDAI = width | (mono<<2) | ((halfperiod-1)<<6) | (stop<<3) | (reset<<4) | (mute<<15) | (slave<<5); +} + +static inline unsigned fl_i2s_input_get_config(void) { + return *FL_I2SDAI; +} + +static inline void fl_i2s_write_tx_fifo(const unsigned value) { + *FL_I2STXFIFO = value; +} + +static inline unsigned fl_i2s_read_rx_fifo(void) { + return *FL_I2SRXFIFO; +} + +static inline unsigned fl_i2s_status_irq(void) { + return *FL_I2SSTATE & (1U<<0); +} + +static inline unsigned fl_i2s_status_dmareq1(void) { + return *FL_I2SSTATE & (1U<<1); +} + +static inline unsigned fl_i2s_status_dmareq2(void) { + return *FL_I2SSTATE & (1U<<2); +} + +static inline unsigned fl_i2s_get_rx_level(void) { + return (*FL_I2SSTATE >> 8) & 15; +} + +static inline unsigned fl_i2s_get_tx_level(void) { + return (*FL_I2SSTATE >> 16) & 15; +} + +/* rx/tx_state: 0-1 rx/tx-level: 0-15 */ +static inline void fl_i2s_config_dma1(const unsigned rx_state, const unsigned tx_state, const unsigned rx_level, const unsigned tx_level) { + *FL_I2SDMA1 = rx_state | (tx_state<<1) | (rx_level<<8) | (tx_level<<16); +} +static inline void fl_i2s_config_dma2(const unsigned rx_state, const unsigned tx_state, const unsigned rx_level, const unsigned tx_level) { + *FL_I2SDMA2 = rx_state | (tx_state<<1) | (rx_level<<8) | (tx_level<<16); +} + +/* rx/tx_irq: 0-1 */ +static inline void fl_i2s_config_irq(const unsigned rx_irq, const unsigned tx_irq, const unsigned rx_level, const unsigned tx_level) { + *FL_I2SIRQ = rx_irq | (tx_irq<<1) | (rx_level<<8) | (tx_level<<16); +} + +/* tx rate = PCLK_I2S * (X/Y) / 2 X and Y: 1-255 (0=no clock) */ +static inline void fl_i2s_set_tx_rate(const unsigned X, const unsigned Y) { + *FL_I2STXRATE = Y | (X<<8); +} +static inline void fl_i2s_set_rx_rate(const unsigned X, const unsigned Y) { + *FL_I2SRXRATE = Y | (X<<8); +} + +/* bitrate: 1-32 */ +static inline void fl_i2s_set_tx_bitrate(const unsigned bitrate) { + *FL_I2STXBITRATE = bitrate-1; +} +static inline void fl_i2s_set_rx_bitrate(const unsigned bitrate) { + *FL_I2SRXBITRATE = bitrate-1; +} + +#define FL_TX_FRACTIONAL_RATE_DIVIDER 0 +#define FL_TX_USE_RX_CLOCK 1 + +static inline void fl_i2s_tx_mode_clock(const unsigned tx_clock) { + if (tx_clock) *FL_I2STXMODE |= 1U<<1; + else *FL_I2STXMODE &= ~(1U<<1); +} + +#define FL_RX_FRACTIONAL_RATE_DIVIDER 0 +#define FL_RX_USE_TX_CLOCK 1 + +static inline void fl_i2s_rx_mode_clock(const unsigned rx_clock) { + if (rx_clock) *FL_I2SRXMODE |= 1U<<1; + else *FL_I2SRXMODE &= ~(1U<<1); +} + +static inline void fl_i2s_tx_mode_4pin(const unsigned state) { + if (state) *FL_I2STXMODE |= 1U<<2; + else *FL_I2STXMODE &= ~(1U<<2); +} + +static inline void fl_i2s_rx_mode_4pin(const unsigned state) { + if (state) *FL_I2SRXMODE |= 1U<<2; + else *FL_I2SRXMODE &= ~(1U<<2); +} + +static inline void fl_i2s_tx_clock_output(const unsigned state) { + if (state) *FL_I2STXMODE |= 1U<<3; + else *FL_I2STXMODE &= ~(1U<<3); +} + +static inline void fl_i2s_rx_clock_output(const unsigned state) { + if (state) *FL_I2SRXMODE |= 1U<<3; + else *FL_I2SRXMODE &= ~(1U<<3); +} + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/license/gpl.h Sun Jul 03 17:11:55 2011 +0000 @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + <program> Copyright (C) <year> <name of author> + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +<http://www.gnu.org/licenses/>. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +<http://www.gnu.org/philosophy/why-not-lgpl.html>.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/license/lgpl.h Sun Jul 03 17:11:55 2011 +0000 @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nvic.h Sun Jul 03 17:11:55 2011 +0000 @@ -0,0 +1,101 @@ +/* Copyright (C) 2011 by Ivo van Poorten <ivop@euronet.nl> + * This file is licensed under the terms of the GNU Lesser + * General Public License, version 3. + */ + +#ifndef FASTLIB_NVIC_H +#define FASTLIB_NVIC_H + +#include "fastlib/common.h" + +#define FL_NVIC_ISER0 ((volatile uint32_t *) 0xE000E100) +#define FL_NVIC_ISER1 ((volatile uint32_t *) 0xE000E104) +#define FL_NVIC_ICER0 ((volatile uint32_t *) 0xE000E180) +#define FL_NVIC_ICER1 ((volatile uint32_t *) 0xE000E184) +#define FL_NVIC_ISPR0 ((volatile uint32_t *) 0xE000E200) +#define FL_NVIC_ISPR1 ((volatile uint32_t *) 0xE000E204) +#define FL_NVIC_ICPR0 ((volatile uint32_t *) 0xE000E280) +#define FL_NVIC_ICPR1 ((volatile uint32_t *) 0xE000E284) +#define FL_NVIC_IABR0 ((volatile uint32_t *) 0xE000E300) +#define FL_NVIC_IABR1 ((volatile uint32_t *) 0xE000E304) +#define FL_NVIC_IPR0 ((volatile uint32_t *) 0xE000E400) +#define FL_NVIC_IPR1 ((volatile uint32_t *) 0xE000E404) +#define FL_NVIC_IPR2 ((volatile uint32_t *) 0xE000E408) +#define FL_NVIC_IPR3 ((volatile uint32_t *) 0xE000E40C) +#define FL_NVIC_IPR4 ((volatile uint32_t *) 0xE000E410) +#define FL_NVIC_IPR5 ((volatile uint32_t *) 0xE000E414) +#define FL_NVIC_IPR6 ((volatile uint32_t *) 0xE000E418) +#define FL_NVIC_IPR7 ((volatile uint32_t *) 0xE000E41C) +#define FL_NVIC_IPR8 ((volatile uint32_t *) 0xE000E420) +#define FL_NVIC_STIR ((volatile uint32_t *) 0xE000EF00) + +#define FL_NVIC_INT_WDT 0 +#define FL_NVIC_INT_TIMER0 1 +#define FL_NVIC_INT_TIMER1 2 +#define FL_NVIC_INT_TIMER2 3 +#define FL_NVIC_INT_TIMER3 4 +#define FL_NVIC_INT_UART0 5 +#define FL_NVIC_INT_UART1 6 +#define FL_NVIC_INT_UART2 7 +#define FL_NVIC_INT_UART3 8 +#define FL_NVIC_INT_PWM 9 +#define FL_NVIC_INT_I2C0 10 +#define FL_NVIC_INT_I2C1 11 +#define FL_NVIC_INT_I2C2 12 +#define FL_NVIC_INT_SPI 13 +#define FL_NVIC_INT_SSP0 14 +#define FL_NVIC_INT_SSP1 15 +#define FL_NVIC_INT_PLL0 16 +#define FL_NVIC_INT_RTC 17 +#define FL_NVIC_INT_EINT0 18 +#define FL_NVIC_INT_EINT1 19 +#define FL_NVIC_INT_EINT2 20 +#define FL_NVIC_INT_EINT3 21 +#define FL_NVIC_INT_ADC 22 +#define FL_NVIC_INT_BOD 23 +#define FL_NVIC_INT_USB 24 +#define FL_NVIC_INT_CAN 25 +#define FL_NVIC_INT_DMA 26 +#define FL_NVIC_INT_I2S 27 +#define FL_NVIC_INT_ENET 28 +#define FL_NVIC_INT_RIT 29 +#define FL_NVIC_INT_MCPWM 30 +#define FL_NVIC_INT_QEI 31 + +#define FL_NVIC_INT_PLL1 32 +#define FL_NVIC_INT_USBACT 33 +#define FL_NVIC_INT_CANACT 34 + +#define FL_NVIC_INTERRUPT_FUNC(x, y) \ + static inline void fl_nvic_interrupt_##x(const unsigned interrupt) { \ + if (interrupt < 32) *FL_NVIC_##y##0 |= 1U<<interrupt; \ + else *FL_NVIC_##y##1 |= 1U<<(interrupt-32); \ + } \ + static inline unsigned fl_nvic_interrupt_##x##_status(const unsigned interrupt) { \ + if (interrupt < 32) return (*FL_NVIC_##y##0) & (1U<<interrupt); \ + else return (*FL_NVIC_##y##1) & (1U<<(interrupt-32)); \ + } + +FL_NVIC_INTERRUPT_FUNC(set_enable, ISER) +FL_NVIC_INTERRUPT_FUNC(clear_enable, ICER) +FL_NVIC_INTERRUPT_FUNC(set_pending, ISPR) +FL_NVIC_INTERRUPT_FUNC(clear_pending, ICPR) + +static inline unsigned fl_nvic_interrupt_active_bit_status(const unsigned interrupt) { + if (interrupt < 32) return (*FL_NVIC_IABR0) & (1U<<interrupt); + else return (*FL_NVIC_IABR1) & (1U<<(interrupt-32)); +} + +static inline void fl_nvic_interrupt_set_priority(const unsigned interrupt, const unsigned priority) { + const unsigned i = interrupt >> 3, + j = (31 <<3) << ((interrupt&3)<<3), + k = (priority<<3) << ((interrupt&3)<<3); + *(FL_NVIC_IPR0 + i) &= ~j; + *(FL_NVIC_IPR0 + i) |= k; +} + +static inline void fl_nvic_interrupt_software_trigger(const unsigned interrupt) { + *FL_NVIC_STIR = interrupt; +} + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pinsel.h Sun Jul 03 17:11:55 2011 +0000 @@ -0,0 +1,78 @@ +/* Copyright (C) 2010, 2011 by Ivo van Poorten <ivop@euronet.nl> + * This file is licensed under the terms of the GNU Lesser + * General Public License, version 3. + */ + +#ifndef FASTLIB_PINSEL_H +#define FASTLIB_PINSEL_H + +#include "fastlib/common.h" + +#define FL_PINSEL0 ((volatile uint32_t *) 0x4002c000) +#define FL_PINMODE0 ((volatile uint32_t *) 0x4002c040) +#define FL_PINMODE_OD0 ((volatile uint32_t *) 0x4002c068) + +#define FL_PULLUP 0 +#define FL_REPEATER 1 +#define FL_TRISTATE 2 +#define FL_FLOATING 2 +#define FL_PULLDOWN 3 + +#define FL_FUNC_DEFAULT 0 +#define FL_FUNC_ALT1 1 +#define FL_FUNC_ALT2 2 +#define FL_FUNC_ALT3 3 + +/* fl_pinsel(port,pin,func,resistor,opendrain) : + * + * port 0-4 + * pin 0-31 + * func 0-3 (-1 is ignore) default/alt1/alt2/alt3 + * resistor 0-3 (-1 is ignore) pull-up, repeater, tri-state, pull-down + * opendrain 0-1 (-1 is ignore) off, on + */ + +static inline void fl_pinsel(unsigned port, unsigned pin, const int func, const int resistor, const int opendrain) { + if (opendrain >= 0) { + *(FL_PINMODE_OD0 + port) &= ~( 1U << pin); + *(FL_PINMODE_OD0 + port) |= opendrain << pin ; + } + + if (func == -1 && resistor == -1) return; + + port <<= 1; + if (pin >= 16) { + pin -= 16; + port++; + } + pin <<= 1; + + if (func >= 0) { + *(FL_PINSEL0 + port) &= ~( 3U << pin); + *(FL_PINSEL0 + port) |= func << pin ; + } + if (resistor >= 0) { + *(FL_PINMODE0 + port) &= ~((uint32_t) 3U << pin); + *(FL_PINMODE0 + port) |= (uint32_t)resistor << pin ; + } +} + +/* Perhaps move this to i2c.h later??? */ + +#define FL_I2CPADCFG ((volatile uint32_t *) 0x4002C07C) + +#define FL_SDA0_STANDARD_DRIVE (0<<0) +#define FL_SDA0_FAST_DRIVE (1<<0) +#define FL_SDA0_GLITCH_ENABLE (0<<1) +#define FL_SDA0_GLITCH_DISABLE (1<<1) +#define FL_SCL0_STANDARD_DRIVE (0<<2) +#define FL_SCL0_FAST_DRIVE (1<<2) +#define FL_SCL0_GLITCH_ENABLE (0<<3) +#define FL_SCL0_GLITCH_DISABLE (1<<3) + +/* pins P0.27 and P0.28 */ +static inline void fl_i2c_pad_config(const unsigned config) { + *FL_I2CPADCFG = config; +} + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/power.h Sun Jul 03 17:11:55 2011 +0000 @@ -0,0 +1,77 @@ +/* Copyright (C) 2010, 2011 by Ivo van Poorten <ivop@euronet.nl> + * This file is licensed under the terms of the GNU Lesser + * General Public License, version 3. + */ + +/* see chapter 4 of user manual for details on clocks and power */ + +#ifndef FASTLIB_POWER_H +#define FASTLIB_POWER_H + +#include "fastlib/common.h" + +#define FL_PCON ((volatile uint32_t *) 0x400FC0C0) +#define FL_PCONP ((volatile uint32_t *) 0x400FC0C4) + +#define FL_POWER_DOWN (1<<0) +#define FL_DEEP_POWER_DOWN (1<<1) +#define FL_BROWN_OUT_REDUCED_POWER_MODE (1<<2) +#define FL_BROWN_OUT_GLOBAL_DISABLE (1<<3) +#define FL_BROWN_OUT_RESET_DISABLE (1<<4) + +#define FL_FLAG_SLEEP_MODE (1<<8) +#define FL_FLAG_DEEP_SLEEP_MODE (1<<9) +#define FL_FLAG_POWER_DOWN (1<<10) +#define FL_FLAG_DEEP_POWER_DOWN (1<<11) + +static inline void fl_set_power_mode(const unsigned mode) { + *FL_PCON = mode; +} + +static inline unsigned fl_get_power_mode(void) { + return *FL_PCON; +} + +#define FL_POWER(peripheral, pos) \ + static inline void fl_power_##peripheral(const unsigned on_off) { \ + *FL_PCONP &= ~( 1U<<pos); \ + *FL_PCONP |= (unsigned)on_off<<pos; \ + } + +FL_POWER(timer0, 1) +FL_POWER(timer1, 2) +FL_POWER(uart0, 3) +FL_POWER(uart1, 4) +FL_POWER(pwm1, 6) +FL_POWER(i2c0, 7) +FL_POWER(spi, 8) +FL_POWER(rtc, 9) +FL_POWER(ssp1, 10) +FL_POWER(adc, 12) +FL_POWER(can1, 13) +FL_POWER(can2, 14) +FL_POWER(gpio, 15) +FL_POWER(rit, 16) +FL_POWER(mcpwm, 17) +FL_POWER(qei, 18) +FL_POWER(i2c1, 19) +FL_POWER(ssp0, 21) +FL_POWER(timer2, 22) +FL_POWER(timer3, 23) +FL_POWER(uart2, 24) +FL_POWER(uart3, 25) +FL_POWER(i2c2, 26) +FL_POWER(i2s, 27) +FL_POWER(gpdma, 29) +FL_POWER(enet, 30) +FL_POWER(usb, 31) + +static inline void fl_power_off_all_peripherals(void) { + *FL_PCONP = 0; +} + +static inline void fl_power_on_all_peripherals(void) { + *FL_PCONP = ~((1<<0) | (1<<5) | (1<<11) | (1<<20) | (1<<28)); +} + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pwm.h Sun Jul 03 17:11:55 2011 +0000 @@ -0,0 +1,145 @@ +/* Copyright (C) 2010, 2011 by Ivo van Poorten <ivop@euronet.nl> + * This file is licensed under the terms of the GNU Lesser + * General Public License, version 3. + */ + +#ifndef FASTLIB_PWM_H +#define FASTLIB_PWM_H + +#include "fastlib/common.h" + +#define FL_PWM1IR ((volatile uint32_t *) 0x40018000) + +#define FL_PWM1TCR ((volatile uint32_t *) 0x40018004) +#define FL_PWM1TC ((volatile uint32_t *) 0x40018008) + +#define FL_PWM1PR ((volatile uint32_t *) 0x4001800C) +#define FL_PWM1PC ((volatile uint32_t *) 0x40018010) + +#define FL_PWM1MCR ((volatile uint32_t *) 0x40018014) +#define FL_PWM1MR0 ((volatile uint32_t *) 0x40018018) +#define FL_PWM1MR1 ((volatile uint32_t *) 0x4001801C) +#define FL_PWM1MR2 ((volatile uint32_t *) 0x40018020) +#define FL_PWM1MR3 ((volatile uint32_t *) 0x40018024) +#define FL_PWM1MR4 ((volatile uint32_t *) 0x40018040) +#define FL_PWM1MR5 ((volatile uint32_t *) 0x40018044) +#define FL_PWM1MR6 ((volatile uint32_t *) 0x40018048) + +#define FL_PWM1CCR ((volatile uint32_t *) 0x40018028) +#define FL_PWM1CR0 ((volatile uint32_t *) 0x4001802C) +#define FL_PWM1CR1 ((volatile uint32_t *) 0x40018030) +#define FL_PWM1CR2 ((volatile uint32_t *) 0x40018034) +#define FL_PWM1CR3 ((volatile uint32_t *) 0x40018038) + +#define FL_PWM1PCR ((volatile uint32_t *) 0x4001804C) +#define FL_PWM1LER ((volatile uint32_t *) 0x40018050) +#define FL_PWM1CTCR ((volatile uint32_t *) 0x40018070) + +/* match channel: 0-8 (0-6 pwm, 7-8 cap0-1) + * returns 0 or !0 + */ +static inline int fl_pwm_interrupt_status(const unsigned channel) { + int remap; + if (channel >= 7) remap = -3; + else if (channel >= 4) remap = 4; + return *FL_PWM1IR & (1U << (channel+remap)); +} + +static inline void fl_pwm_interrupt_clear(const unsigned channel) { + int remap; + if (channel >= 7) remap = -3; + else if (channel >= 4) remap = 4; + *FL_PWM1IR = 1U << (channel+remap); +} + +static inline void fl_pwm_timer_counter_enable(const unsigned state) { + if (state) *FL_PWM1TCR |= 1; + else *FL_PWM1TCR &= ~1U; +} + +static inline void fl_pwm_timer_counter_reset(const unsigned state) { + if (state) *FL_PWM1TCR |= 2; + else *FL_PWM1TCR &= ~2U; +} + +static inline void fl_pwm_enable(const unsigned state) { + if (state) *FL_PWM1TCR |= 8; + else *FL_PWM1TCR &= ~8U; +} + +static inline unsigned fl_pwm_get_timer_counter(void) { + return *FL_PWM1TC; +} + +static inline void fl_pwm_set_timer_counter(unsigned value) { + *FL_PWM1TC = value; +} + +/* value: 1-... */ +static inline void fl_pwm_set_prescale(const unsigned value) { + *FL_PWM1PR = value - 1; +} + +static inline unsigned fl_pwm_get_prescale_counter(void) { + return *FL_PWM1PR + 1; +} + +static inline void fl_pwm_set_timer_mode(void) { + *FL_PWM1CTCR &= ~3U; +} + +/* mode: 1-3 (FL_RISE/FALL/BOTH) pcap1: 0-1 */ +static inline void fl_pwm_set_counter_mode(const unsigned mode, const unsigned pcap1n) { + *FL_PWM1CTCR = mode | (pcap1n << 2); +} + +/* channel: 0-6 */ +static inline void fl_pwm_config_match(const unsigned channel, const unsigned interrupt, const unsigned reset, const unsigned stop) { + const unsigned mask = (interrupt | (reset << 1) | (stop << 2)) << ((channel<<1)+channel); + *FL_PWM1MCR &= ~mask; + *FL_PWM1MCR |= mask; +} + +/* channel: 0-6 */ +static inline void fl_pwm_set_match(const unsigned channel, const unsigned value) { + if (channel <= 3) *(FL_PWM1MR0+channel) = value; + else *(FL_PWM1MR0+channel+0x18) = value; +} + +/* pcap1n: 0-1 */ +static inline void fl_pwm_config_capture(const unsigned pcap1n, const unsigned rise, const unsigned fall, const unsigned interrupt) { + const unsigned mask = (rise | (fall << 1) | (interrupt << 2)) << ((pcap1n<<1)+pcap1n); + *FL_PWM1CCR &= ~mask; + *FL_PWM1CCR |= mask; +} + +/* pcap1n: 0-1 (2,3?) */ +static inline unsigned fl_pwm_get_capture(const unsigned pcap1n) { + return *(FL_PWM1CR0+pcap1n); +} + +/* channel: 2-6 edges: 0-1 (single/double) */ +static inline void fl_pwm_config_edges(const unsigned channel, const unsigned edges) { + if (edges) *FL_PWM1PCR |= edges << channel ; + else *FL_PWM1PCR &= ~(edges << channel); +} + +/* channel: 1-6 state: 0-1 */ +static inline void fl_pwm_output_enable(const unsigned channel, const unsigned state) { + if (state) *FL_PWM1PCR |= 1U << (channel+8) ; + else *FL_PWM1PCR &= ~(1U << (channel+8)); +} + +static inline void fl_pwm_latch_match_channel(const unsigned channel) { + *FL_PWM1LER |= 1U << channel; +} + +static inline void fl_pwm_latch_match_mask(const unsigned mask) { + *FL_PWM1LER = mask; +} + +static inline void fl_pwm_latch_match_all(void) { + fl_pwm_latch_match_mask(0x7f); +} + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/uart.h Sun Jul 03 17:11:55 2011 +0000 @@ -0,0 +1,348 @@ +/* Copyright (C) 2010, 2011 by Ivo van Poorten <ivop@euronet.nl> + * This file is licensed under the terms of the GNU Lesser + * General Public License, version 3. + */ + +#ifndef FASTLIB_UART_H +#define FASTLIB_UART_H + +#include "fastlib/common.h" + +#define FL_UART_RBR 0x00 +#define FL_UART_THR 0x00 +#define FL_UART_DLL 0x00 + +#define FL_UART_DLM 0x04 +#define FL_UART_IER 0x04 + +#define FL_UART_IIR 0x08 +#define FL_UART_FCR 0x08 + +#define FL_UART_LCR 0x0C +#define FL_UART_MCR 0x10 /* UART1 only */ +#define FL_UART_LSR 0x14 +#define FL_UART_MSR 0x18 /* UART1 only */ +#define FL_UART_SCR 0x1C +#define FL_UART_ACR 0x20 +#define FL_UART_ICR 0x24 /* UART023 only */ +#define FL_UART_FDR 0x28 +#define FL_UART_TER 0x30 + +#define FL_UART_RS485CTRL 0x4C /* UART1 only */ +#define FL_UART_RS485ADRMATCH 0x50 /* UART1 only */ +#define FL_UART_RS485DLY 0x54 /* UART1 only */ + +#define FL_UART0_BASE 0x4000C000 +#define FL_UART1_BASE 0x40010000 +#define FL_UART2_BASE 0x40098000 +#define FL_UART3_BASE 0x4009C000 + +#define FL_UART(num, field) \ + ((volatile uint32_t *)(fl_uart_num_to_base(num) + FL_UART_##field)) + +static inline unsigned fl_uart_num_to_base(const unsigned num) { + switch(num) { + case 0: return FL_UART0_BASE; + case 1: return FL_UART1_BASE; + case 2: return FL_UART2_BASE; + default: return FL_UART3_BASE; + } +} + +static inline unsigned fl_uart_receive_byte(const unsigned uart) { + return *FL_UART(uart, RBR); +} + +static inline void fl_uart_send_byte(const unsigned uart, const unsigned byte) { + *FL_UART(uart, THR); +} + +static inline unsigned fl_uart_get_divisor_latch(const unsigned uart) { + unsigned divisor; + *FL_UART(uart, LCR) |= 1U<<7; // enable access to latch + + divisor = *FL_UART(uart, DLL) | (*FL_UART(uart, DLM) << 8); + + *FL_UART(uart, LCR) &= ~(1U<<7); // disable access to latch + return divisor; +} + +/* divisor: 16-bit value */ +static inline void fl_uart_set_divisor_latch(const unsigned uart, const unsigned divisor) { + *FL_UART(uart, LCR) |= 1U<<7; // enable access to latch + + *FL_UART(uart, DLL) = divisor & 0xff; + *FL_UART(uart, DLM) = (divisor >> 8) & 0xff; + + *FL_UART(uart, LCR) &= ~(1U<<7); // disable access to latch +} + +static inline void fl_uart_rx_data_available_interrupt_enable(const unsigned uart, const unsigned state) { + if (state) *FL_UART(uart, IER) |= (1U<<0); + else *FL_UART(uart, IER) &= ~(1U<<0); +} + +static inline void fl_uart_tx_fifo_empty_interrupt_enable(const unsigned uart, const unsigned state) { + if (state) *FL_UART(uart, IER) |= (1U<<1); + else *FL_UART(uart, IER) &= ~(1U<<1); +} + +static inline void fl_uart_rx_line_status_interrupt_enable(const unsigned uart, const unsigned state) { + if (state) *FL_UART(uart, IER) |= (1U<<2); + else *FL_UART(uart, IER) &= ~(1U<<2); +} + +static inline void fl_uart_end_of_autobaud_interrupt_enable(const unsigned uart, const unsigned state) { + if (state) *FL_UART(uart, IER) |= (1U<<8); + else *FL_UART(uart, IER) &= ~(1U<<8); +} + +static inline void fl_uart_timeout_autobaud_interrupt_enable(const unsigned uart, const unsigned state) { + if (state) *FL_UART(uart, IER) |= (1U<<9); + else *FL_UART(uart, IER) &= ~(1U<<9); +} + +static inline unsigned fl_uart_interrupt_status(const unsigned uart) { + return !(*FL_UART(uart, IIR) & 1); // negate, because status is active low +} + +#define FL_UART_INTERRUPT_RLS 3 /* rx line status */ +#define FL_UART_INTERRUPT_RDA 2 /* rx data available */ +#define FL_UART_INTERRUPT_CTI 6 /* character time-out */ +#define FL_UART_INTERRUPT_THRE 1 /* tx fifo empty */ +#define FL_UART_INTERRUPT_MODEM 0 /* modem interrupt, uart1 only */ + +static inline unsigned fl_uart_get_interrupt_identification(const unsigned uart) { + return (*FL_UART(uart, IIR) >> 1) & 7; +} + +/* returns 0 or !0 */ +static inline unsigned fl_uart_end_of_autobaud_interrupt(const unsigned uart) { + return *FL_UART(uart, IIR) & (1U<<8); +} +static inline unsigned fl_uart_timeout_autobaud_interrupt(const unsigned uart) { + return *FL_UART(uart, IIR) & (1U<<9); +} + +/* call is more or less mandatory for application (page 305) */ +static inline void fl_uart_enable_fifos(const unsigned uart) { + *FL_UART(uart, FCR) |= 1U<<0; +} +/* disable/enable cycle clears fifo */ +static inline void fl_uart_disable_fifos(const unsigned uart) { + *FL_UART(uart, FCR) &= ~(1U<<0); +} + +static inline void fl_uart_reset_rx_fifo(const unsigned uart) { + *FL_UART(uart, FCR) |= 1U<<1; // bit is self-clearing +} + +static inline void fl_uart_reset_tx_fifo(const unsigned uart) { + *FL_UART(uart, FCR) |= 1U<<2; // bit is self-clearing +} + +static inline void fl_uart_enable_dma_mode(const unsigned uart, const unsigned state) { + if (state) *FL_UART(uart, FCR) |= 1U<<3 ; + else *FL_UART(uart, FCR) &= ~(1U<<3); +} + +static inline void fl_uart_set_rx_trigger_level(const unsigned uart, const unsigned level) { + if (level != 14) *FL_UART(uart, FCR) &= ~(3U<<6); + switch(level) { + default: return; + case 4: *FL_UART(uart, FCR) |= 1U<<6; return; + case 8: *FL_UART(uart, FCR) |= 2U<<6; return; + case 14: *FL_UART(uart, FCR) |= 3U<<6; return; + } +} + +#define FL_UART_5BIT 0 +#define FL_UART_6BIT 1 +#define FL_UART_7BIT 2 +#define FL_UART_8BIT 3 + +#define FL_UART_1STOPBIT 0 +#define FL_UART_2STOPBITS 1 + +#define FL_UART_NO_PARITY 0 +#define FL_UART_PARITY 1 + +#define FL_UART_ODD 0 +#define FL_UART_EVEN 1 +#define FL_UART_FORCE1 2 +#define FL_UART_FORCE0 3 + +static inline void fl_uart_line_config(const unsigned uart, const unsigned wordlength, const unsigned stopbit, \ + const unsigned parity_enable, const unsigned parity_type) { + const unsigned combined = wordlength | (stopbit << 2) | (parity_enable << 3) | (parity_type << 4); + *FL_UART(uart, LCR) &= ~(0x3fU); + *FL_UART(uart, LCR) |= combined; +} + +static inline void fl_uart_break_transmission(const unsigned uart, const unsigned state) { + if (state) *FL_UART(uart, LCR) |= 1U<<6 ; + else *FL_UART(uart, LCR) &= ~(1U<<6); +} + +static inline unsigned fl_uart_get_line_status(const unsigned uart) { + return *FL_UART(uart, LSR); +} + +/* read status first and use functions below to test what is happening */ +/* the reason for this is that a status read clears several bits */ + +#define FL_LSR_TEST(what, where) \ + static inline unsigned fl_uart_##what(const unsigned status) { \ + return status & (where); \ + } + +FL_LSR_TEST(rx_fifo_not_empty, 1U<<0); +FL_LSR_TEST(rx_fifo_overun_error, 1U<<1); +FL_LSR_TEST(rx_parity_error, 1U<<2); +FL_LSR_TEST(rx_framing_error, 1U<<3); +FL_LSR_TEST(rx_break_interrupt, 1U<<4); /* associated with top of fifo */ +FL_LSR_TEST(tx_send_register_empty, 1U<<5); +FL_LSR_TEST(tx_empty, 1U<<6); /* both send and status register */ +FL_LSR_TEST(rx_error_entered_fifo, 1U<<7); + +static inline void fl_uart_write_scratch_pad(const unsigned uart, const unsigned byte) { + *FL_UART(uart, SCR) = byte & 0xff; +} + +static inline unsigned fl_uart_read_scratch_pad(const unsigned uart) { + return *FL_UART(uart, SCR); +} + +static inline void fl_uart_autobaud_config(const unsigned uart, const unsigned mode, const unsigned autorestart) { + *FL_UART(uart, ACR) = (mode << 1) | (autorestart << 2); // writing zeroes to other bits has no impact (p.308/309) +} + +static inline void fl_uart_start_autobaud(const unsigned uart) { + *FL_UART(uart, ACR) |= 1; // bit is auto-clearing +} + +static inline void fl_uart_clear_end_of_autobaud_interrupt(const unsigned uart) { + *FL_UART(uart, ACR) |= 1U<<8; +} + +static inline void fl_uart_clear_autobaud_timeout_interrupt(const unsigned uart) { + *FL_UART(uart, ACR) |= 1U<<9; +} + +static inline void fl_uart_set_fractional_divider(const unsigned uart, const unsigned divaddval, const unsigned mulval) { + *FL_UART(uart, FDR) &= ~(0xff); + *FL_UART(uart, FDR) |= divaddval | (mulval<<4); +} + +static inline unsigned fl_uart_get_fractional_divider(const unsigned uart) { + return *FL_UART(uart, FDR); +} + +static inline void fl_uart_transmitter_enable(const unsigned uart, const unsigned state) { + if (state) *FL_UART(uart, TER) |= 1U<<7 ; + else *FL_UART(uart, TER) &= ~(1U<<7); +} + +// infrared mode only works on uart0, 2 and 3 + +static inline void fl_uart_infrared_mode(const unsigned uart, const unsigned state) { + if (state) *FL_UART(uart, ICR) |= 1U<<0; + else *FL_UART(uart, ICR) &= ~(1U<<0); +} +static inline void fl_uart_infrared_input_inverted(const unsigned uart, const unsigned state) { + if (state) *FL_UART(uart, ICR) |= 1U<<1; + else *FL_UART(uart, ICR) &= ~(1U<<1); +} +static inline void fl_uart_infrared_fixed_pulsewidth(const unsigned uart, const unsigned state) { + if (state) *FL_UART(uart, ICR) |= 1U<<2; + else *FL_UART(uart, ICR) &= ~(1U<<2); +} +// see UM10360 page 312 for pulsediv values (0-7) +static inline void fl_uart_infrared_config_pulse(const unsigned uart, const unsigned pulsediv) { + *FL_UART(uart, ICR) &= ~(7U<<3); + *FL_UART(uart, ICR) |= pulsediv << 3; +} + + +// functions below only work for uart1 (full modem interface) + +static inline void fl_modem_status_interrupt_enable(const unsigned state) { + if (state) *FL_UART(1, IER) |= (1U<<3); + else *FL_UART(1, IER) &= ~(1U<<3); +} + +static inline void fl_modem_cts_interrupt_enable(const unsigned state) { + if (state) *FL_UART(1, IER) |= (1U<<7); + else *FL_UART(1, IER) &= ~(1U<<7); +} + +static inline void fl_modem_control(const unsigned dtr_control, const unsigned rts_control, const unsigned loopback, + const unsigned rts, const unsigned cts) { + *FL_UART(1, MCR) = dtr_control | (rts_control << 1) | (loopback << 4) | (rts << 6) | (cts << 7); +} + +static inline unsigned fl_modem_get_status(void) { + return *FL_UART(1, MSR); +} + +/* read status first and use functions below to test what is happening */ +/* the reason for this is that a status read clears several bits */ + +#define FL_MSR_TEST(what, where) \ + static inline unsigned fl_modem_##what(const unsigned status) { \ + return status & (where); \ + } + +FL_MSR_TEST(cts_state_changed, 1U<<0); +FL_MSR_TEST(dsr_state_changed, 1U<<1); +FL_MSR_TEST(low_to_high_ri, 1U<<2); +FL_MSR_TEST(dcd_state_changed, 1U<<3); +FL_MSR_TEST(cts_state, 1U<<4); /* clear to send */ +FL_MSR_TEST(dsr_state, 1U<<5); /* data set ready */ +FL_MSR_TEST(ri_state, 1U<<6); /* ring indicator */ +FL_MSR_TEST(dcd_state, 1U<<7); /* data carrier detect */ + +// RS-485/EIA-485 mode functions, also uart1 only + +static inline void fl_rs485_normal_multidrop_mode_enable(const unsigned state) { + if (state) *FL_UART(1, RS485CTRL) |= 1U<<0 ; + else *FL_UART(1, RS485CTRL) &= ~(1U<<0); +} + +static inline void fl_rs485_receiver_enable(const unsigned state) { + if (state) *FL_UART(1, RS485CTRL) |= 1U<<1 ; + else *FL_UART(1, RS485CTRL) &= ~(1U<<1); +} + +static inline void fl_rs485_auto_address_detect_enable(const unsigned state) { + if (state) *FL_UART(1, RS485CTRL) |= 1U<<2 ; + else *FL_UART(1, RS485CTRL) &= ~(1U<<2); +} + +static inline void fl_rs485_auto_direction_control_enable(const unsigned state) { + if (state) *FL_UART(1, RS485CTRL) |= 1U<<4 ; + else *FL_UART(1, RS485CTRL) &= ~(1U<<4); +} + +static inline void fl_rs485_direction_control_on_rts_pin(void) { + *FL_UART(1, RS485CTRL) &= ~(1U<<3); +} + +static inline void fl_rs485_direction_control_on_dtr_pin(void) { + *FL_UART(1, RS485CTRL) |= 1U<<3; +} + +static inline void fl_rs485_direction_control_polarity(const unsigned oinv) { + if (oinv) *FL_UART(1, RS485CTRL) |= 1U<<5 ; + else *FL_UART(1, RS485CTRL) &= ~(1U<<5); +} + +static inline void fl_rs485_set_address_match(const unsigned byte) { + *FL_UART(1, RS485ADRMATCH) = byte & 0xff; +} + +static inline void fl_rs485_set_delay_time(const unsigned byte) { + *FL_UART(1, RS485DLY) = byte & 0xff; +} + +#endif \ No newline at end of file