# HG changeset patch # User Mychaela Falconia # Date 1451508492 0 # Node ID 5cff3579814c781dbede1dd73df250d1dbce0a34 # Parent 2a867e5768e9954733e1608050cfcd68c42ee14e target-utils: libbase factored out of libcommon The library dependency order is now strictly unidirectional diff -r 2a867e5768e9 -r 5cff3579814c target-utils/Makefile --- a/target-utils/Makefile Sat Dec 12 20:07:51 2015 +0000 +++ b/target-utils/Makefile Wed Dec 30 20:48:12 2015 +0000 @@ -1,17 +1,17 @@ FOR_LOADTOOLS= compalstage loadagent ALLPROGS= ${FOR_LOADTOOLS} c139explore c139-lldbg helloapp pirexplore \ tf-breakin -LIBS= libcommon libload libprintf libtiffs +LIBS= libbase libcommon libload libprintf libtiffs SUBDIR= ${ALLPROGS} ${LIBS} default: ${FOR_LOADTOOLS} all: ${ALLPROGS} -c139explore: libcommon libprintf -c139-lldbg: libcommon libprintf -helloapp: libcommon libprintf -loadagent: libcommon libload libprintf -pirexplore: libcommon libprintf libtiffs +c139explore: libbase libcommon libprintf +c139-lldbg: libbase libcommon libprintf +helloapp: libbase libcommon libprintf +loadagent: libbase libcommon libload libprintf +pirexplore: libbase libcommon libprintf libtiffs ${SUBDIR}: FRC cd $@; ${MAKE} ${MFLAGS} diff -r 2a867e5768e9 -r 5cff3579814c target-utils/c139-lldbg/Makefile --- a/target-utils/c139-lldbg/Makefile Sat Dec 12 20:07:51 2015 +0000 +++ b/target-utils/c139-lldbg/Makefile Wed Dec 30 20:48:12 2015 +0000 @@ -6,7 +6,7 @@ PROG= lldbg OBJS= entry.o cmdtab.o entryinfo.o main.o mygetchar.o -LIBS= ../libcommon/libcommon.a ../libprintf/libprintf.a +LIBS= ../libcommon/libcommon.a ../libprintf/libprintf.a ../libbase/libbase.a LDS= lldbg.lds TC_LIBS=`${CC} -print-file-name=libc.a` \ @@ -15,8 +15,7 @@ all: ${PROG}.bin ${PROG}.elf: ${OBJS} ${LIBS} ${LDS} - ${LD} -N -T ${LDS} -o $@ ${OBJS} \ - --start-group ${LIBS} --end-group \ + ${LD} -N -T ${LDS} -o $@ ${OBJS} ${LIBS} \ --start-group ${TC_LIBS} --end-group ${PROG}.bin: ${PROG}.elf diff -r 2a867e5768e9 -r 5cff3579814c target-utils/c139explore/Makefile --- a/target-utils/c139explore/Makefile Sat Dec 12 20:07:51 2015 +0000 +++ b/target-utils/c139explore/Makefile Wed Dec 30 20:48:12 2015 +0000 @@ -6,7 +6,7 @@ PROG= c139explore OBJS= crt0.o backlight.o cmdtab.o lcd.o main.o mygetchar.o uwire.o -LIBS= ../libcommon/libcommon.a ../libprintf/libprintf.a +LIBS= ../libcommon/libcommon.a ../libprintf/libprintf.a ../libbase/libbase.a LDS= ../env/compalram.lds TC_LIBS=`${CC} -print-file-name=libc.a` \ @@ -18,8 +18,7 @@ ln -s $< . ${PROG}.elf: ${OBJS} ${LIBS} ${LDS} - ${LD} -N -T ${LDS} -o $@ ${OBJS} \ - --start-group ${LIBS} --end-group \ + ${LD} -N -T ${LDS} -o $@ ${OBJS} ${LIBS} \ --start-group ${TC_LIBS} --end-group ${PROG}.bin: ${PROG}.elf diff -r 2a867e5768e9 -r 5cff3579814c target-utils/helloapp/Makefile --- a/target-utils/helloapp/Makefile Sat Dec 12 20:07:51 2015 +0000 +++ b/target-utils/helloapp/Makefile Wed Dec 30 20:48:12 2015 +0000 @@ -6,7 +6,7 @@ PROG= helloapp OBJS= crt0.o cmdtab.o main.o mygetchar.o -LIBS= ../libcommon/libcommon.a ../libprintf/libprintf.a +LIBS= ../libcommon/libcommon.a ../libprintf/libprintf.a ../libbase/libbase.a LDS= ../env/iram.lds TC_LIBS=`${CC} -print-file-name=libc.a` \ @@ -19,8 +19,7 @@ ${PROG}.elf: ${OBJS} ${LIBS} ${LDS} ${LD} -N --defsym Base_addr=0x800750 --defsym stack_bottom=0x83FFFC \ - -T ${LDS} -o $@ ${OBJS} \ - --start-group ${LIBS} --end-group \ + -T ${LDS} -o $@ ${OBJS} ${LIBS} \ --start-group ${TC_LIBS} --end-group ${PROG}.srec: ${PROG}.elf diff -r 2a867e5768e9 -r 5cff3579814c target-utils/libbase/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/target-utils/libbase/Makefile Wed Dec 30 20:48:12 2015 +0000 @@ -0,0 +1,16 @@ +CC= arm-elf-gcc +CFLAGS= -Os -fno-builtin +CPPFLAGS=-I../include +AR= arm-elf-ar +RANLIB= arm-elf-ranlib + +OBJS= abbdrv.o osmodelay.o serio.o spidrv.o + +all: libbase.a + +libbase.a: ${OBJS} + ${AR} cru $@ ${OBJS} + ${RANLIB} $@ + +clean: + rm -f *.[oa] *errs diff -r 2a867e5768e9 -r 5cff3579814c target-utils/libbase/abbdrv.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/target-utils/libbase/abbdrv.c Wed Dec 30 20:48:12 2015 +0000 @@ -0,0 +1,102 @@ +/* Driver for Analog Baseband Circuit (TWL3025) */ +/* lifted from OsmocomBB and ported to FreeCalypso target-utils environment */ + +/* (C) 2010 by Harald Welte + * + * All Rights Reserved + * + * 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 2 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, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#include "types.h" +#include "abbdefs.h" + +/* TWL3025 */ +#define REG_PAGE(n) ((n) >> 7) +#define REG_ADDR(n) ((n) & 0x1f) + +#define TWL3025_DEV_IDX 0 /* On the SPI bus */ +#define TWL3025_TSP_DEV_IDX 0 /* On the TSP bus */ + +int abb_state_initdone, abb_state_page; + +void +abb_reg_write(reg, data) +{ + u16 tx; + + if (reg != PAGEREG && REG_PAGE(reg) != abb_state_page) + abb_select_page(REG_PAGE(reg)); + + tx = ((data & 0x3ff) << 6) | (REG_ADDR(reg) << 1); + + spi_xfer(TWL3025_DEV_IDX, 16, &tx, 0); +} + +u16 +abb_reg_read(reg) +{ + u16 tx, rx; + + if (REG_PAGE(reg) != abb_state_page) + abb_select_page(REG_PAGE(reg)); + + tx = (REG_ADDR(reg) << 1) | 1; + + /* A read cycle contains two SPI transfers */ + spi_xfer(TWL3025_DEV_IDX, 16, &tx, &rx); + osmo_delay_ms(1); + spi_xfer(TWL3025_DEV_IDX, 16, &tx, &rx); + + rx >>= 6; + + return rx; +} + +/* Switch the register page of the TWL3025 */ +abb_select_page(page) +{ + if (page == 0) + abb_reg_write(PAGEREG, 1 << 0); + else + abb_reg_write(PAGEREG, 1 << 1); + abb_state_page = page; + return(0); +} + +abb_init() +{ + if (abb_state_initdone) + return(0); + spi_init(); + abb_select_page(0); + /* CLK13M enable */ + abb_reg_write(TOGBR2, TOGBR2_ACTS); + osmo_delay_ms(1); + /* for whatever reason we need to do this twice */ + abb_reg_write(TOGBR2, TOGBR2_ACTS); + osmo_delay_ms(1); + abb_state_initdone = 1; + return(1); +} + +void +abb_power_off() +{ + abb_init(); + serial_flush(); + abb_reg_write(VRPCDEV, 0x01); +} diff -r 2a867e5768e9 -r 5cff3579814c target-utils/libbase/osmodelay.S --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/target-utils/libbase/osmodelay.S Wed Dec 30 20:48:12 2015 +0000 @@ -0,0 +1,30 @@ +/* + * This assembly module provides a replica of OsmocomBB's bogo-millisecond + * delay_ms() function. It is literally a copy of what OsmocomBB's delay_ms() + * compiles to with their gcc version and their optimization settings, as seen + * by doing arm-elf-objdump on their lib/delay.o. + * + * This hack is intended for those cases where we have to copy OsmocomBB's + * black magic voodoo operations with no ability to understand what is actually + * needed, such as SPCA552E initialization on the Pirelli DP-L10. + */ + + .text + .code 32 + .globl osmo_delay_ms +osmo_delay_ms: + mov r3, #0 + sub sp, sp, #4 + str r3, [sp] + ldr r3, =1300 + mul r3, r0, r3 + b 2f +1: ldr r2, [sp] + ldr r2, [sp] + add r2, r2, #1 + str r2, [sp] +2: ldr r2, [sp] + cmp r2, r3 + bcc 1b + add sp, sp, #4 + bx lr diff -r 2a867e5768e9 -r 5cff3579814c target-utils/libbase/serio.S --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/target-utils/libbase/serio.S Wed Dec 30 20:48:12 2015 +0000 @@ -0,0 +1,34 @@ +#include "ns16550.h" + +@ this module implements the elementary serial I/O operations + + .text + .code 32 + .global serial_out +serial_out: + ldr r1, =uart_base + ldr r2, [r1] +1: ldrb r3, [r2, #NS16550_LSR] + tst r3, #NS16550_LSR_THRE + beq 1b + strb r0, [r2, #NS16550_THR] + bx lr + + .global serial_in_poll +serial_in_poll: + ldr r1, =uart_base + ldr r2, [r1] + ldrb r3, [r2, #NS16550_LSR] + tst r3, #NS16550_LSR_DR + ldrneb r0, [r2, #NS16550_RBR] + mvneq r0, #0 + bx lr + + .global serial_flush +serial_flush: + ldr r1, =uart_base + ldr r2, [r1] +1: ldrb r3, [r2, #NS16550_LSR] + tst r3, #NS16550_LSR_TEMP + beq 1b + bx lr diff -r 2a867e5768e9 -r 5cff3579814c target-utils/libbase/spidrv.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/target-utils/libbase/spidrv.c Wed Dec 30 20:48:12 2015 +0000 @@ -0,0 +1,139 @@ +/* Driver for SPI Master Controller inside TI Calypso */ +/* lifted from OsmocomBB and ported to FreeCalypso target-utils environment */ + +/* (C) 2010 by Harald Welte + * + * All Rights Reserved + * + * 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 2 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, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#include "types.h" + +#define ASIC_CONF_REG (*(volatile u16 *) 0xFFFEF008) + +struct spi_regs { + u16 reg_set1; + u16 reg_set2; + u16 reg_ctrl; + u16 reg_status; + u16 reg_tx_lsb; + u16 reg_tx_msb; + u16 reg_rx_lsb; + u16 reg_rx_msb; +}; + +#define SPI_REGS (*(volatile struct spi_regs *) 0xFFFE3000) + +#define BASE_ADDR_SPI 0xfffe3000 +#define SPI_REG(n) (BASE_ADDR_SPI+(n)) + +#define SPI_SET1_EN_CLK (1 << 0) +#define SPI_SET1_WR_IRQ_DIS (1 << 4) +#define SPI_SET1_RDWR_IRQ_DIS (1 << 5) + +#define SPI_CTRL_RDWR (1 << 0) +#define SPI_CTRL_WR (1 << 1) +#define SPI_CTRL_NB_SHIFT 2 +#define SPI_CTRL_AD_SHIFT 7 + +#define SPI_STATUS_RE (1 << 0) /* Read End */ +#define SPI_STATUS_WE (1 << 1) /* Write End */ + +spi_init() +{ + static int initdone; + + if (initdone) + return(0); + ASIC_CONF_REG |= 0x6000; + SPI_REGS.reg_set1 = SPI_SET1_EN_CLK | SPI_SET1_WR_IRQ_DIS | + SPI_SET1_RDWR_IRQ_DIS; + SPI_REGS.reg_set2 = 0x0001; + initdone = 1; + return(1); +} + +spi_xfer(dev_idx, bitlen, dout, din) + void *dout, *din; +{ + int bytes_per_xfer; + u16 reg_status, reg_ctrl = 0; + u32 tmp; + + if (bitlen <= 0) + return 0; + + if (bitlen > 32) + return -1; + + if (dev_idx > 4) + return -1; + + bytes_per_xfer = bitlen / 8; + if (bitlen % 8) + bytes_per_xfer ++; + + reg_ctrl |= (bitlen - 1) << SPI_CTRL_NB_SHIFT; + reg_ctrl |= (dev_idx & 0x7) << SPI_CTRL_AD_SHIFT; + + if (bitlen <= 8) { + tmp = *(u8 *)dout; + tmp <<= 24 + (8-bitlen); /* align to MSB */ + } else if (bitlen <= 16) { + tmp = *(u16 *)dout; + tmp <<= 16 + (16-bitlen); /* align to MSB */ + } else { + tmp = *(u32 *)dout; + tmp <<= (32-bitlen); /* align to MSB */ + } + + /* fill transmit registers */ + SPI_REGS.reg_tx_msb = tmp >> 16; + SPI_REGS.reg_tx_lsb = tmp; + + /* initiate transfer */ + if (din) + reg_ctrl |= SPI_CTRL_RDWR; + else + reg_ctrl |= SPI_CTRL_WR; + SPI_REGS.reg_ctrl = reg_ctrl; + + /* wait until the transfer is complete */ + while (1) { + reg_status = SPI_REGS.reg_status; + if (din && (reg_status & SPI_STATUS_RE)) + break; + else if (reg_status & SPI_STATUS_WE) + break; + } + /* FIXME: calibrate how much delay we really need (seven 13MHz cycles) */ + osmo_delay_ms(1); + + if (din) { + tmp = SPI_REGS.reg_rx_msb << 16; + tmp |= SPI_REGS.reg_rx_lsb; + + if (bitlen <= 8) + *(u8 *)din = tmp & 0xff; + else if (bitlen <= 16) + *(u16 *)din = tmp & 0xffff; + else + *(u32 *)din = tmp; + } + + return 0; +} diff -r 2a867e5768e9 -r 5cff3579814c target-utils/libcommon/Makefile --- a/target-utils/libcommon/Makefile Sat Dec 12 20:07:51 2015 +0000 +++ b/target-utils/libcommon/Makefile Wed Dec 30 20:48:12 2015 +0000 @@ -4,10 +4,9 @@ AR= arm-elf-ar RANLIB= arm-elf-ranlib -OBJS= cmdentry.o dispatch.o hexarg.o parseargs.o serio.o uartsel.o \ +OBJS= abbcmd.o cmdentry.o dispatch.o hexarg.o parseargs.o uartsel.o \ cmd_baud_switch.o cmd_dieid.o cmd_jump.o cmd_r8.o cmd_r16.o cmd_r32.o \ - cmd_w8.o cmd_w16.o cmd_w32.o cmd_memdump_human.o cmd_memdump_machine.o \ - abbcmd.o abbdrv.o osmodelay.o spidrv.o + cmd_w8.o cmd_w16.o cmd_w32.o cmd_memdump_human.o cmd_memdump_machine.o all: libcommon.a diff -r 2a867e5768e9 -r 5cff3579814c target-utils/libcommon/abbdrv.c --- a/target-utils/libcommon/abbdrv.c Sat Dec 12 20:07:51 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,102 +0,0 @@ -/* Driver for Analog Baseband Circuit (TWL3025) */ -/* lifted from OsmocomBB and ported to FreeCalypso target-utils environment */ - -/* (C) 2010 by Harald Welte - * - * All Rights Reserved - * - * 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 2 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, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - -#include "types.h" -#include "abbdefs.h" - -/* TWL3025 */ -#define REG_PAGE(n) ((n) >> 7) -#define REG_ADDR(n) ((n) & 0x1f) - -#define TWL3025_DEV_IDX 0 /* On the SPI bus */ -#define TWL3025_TSP_DEV_IDX 0 /* On the TSP bus */ - -int abb_state_initdone, abb_state_page; - -void -abb_reg_write(reg, data) -{ - u16 tx; - - if (reg != PAGEREG && REG_PAGE(reg) != abb_state_page) - abb_select_page(REG_PAGE(reg)); - - tx = ((data & 0x3ff) << 6) | (REG_ADDR(reg) << 1); - - spi_xfer(TWL3025_DEV_IDX, 16, &tx, 0); -} - -u16 -abb_reg_read(reg) -{ - u16 tx, rx; - - if (REG_PAGE(reg) != abb_state_page) - abb_select_page(REG_PAGE(reg)); - - tx = (REG_ADDR(reg) << 1) | 1; - - /* A read cycle contains two SPI transfers */ - spi_xfer(TWL3025_DEV_IDX, 16, &tx, &rx); - osmo_delay_ms(1); - spi_xfer(TWL3025_DEV_IDX, 16, &tx, &rx); - - rx >>= 6; - - return rx; -} - -/* Switch the register page of the TWL3025 */ -abb_select_page(page) -{ - if (page == 0) - abb_reg_write(PAGEREG, 1 << 0); - else - abb_reg_write(PAGEREG, 1 << 1); - abb_state_page = page; - return(0); -} - -abb_init() -{ - if (abb_state_initdone) - return(0); - spi_init(); - abb_select_page(0); - /* CLK13M enable */ - abb_reg_write(TOGBR2, TOGBR2_ACTS); - osmo_delay_ms(1); - /* for whatever reason we need to do this twice */ - abb_reg_write(TOGBR2, TOGBR2_ACTS); - osmo_delay_ms(1); - abb_state_initdone = 1; - return(1); -} - -void -abb_power_off() -{ - abb_init(); - serial_flush(); - abb_reg_write(VRPCDEV, 0x01); -} diff -r 2a867e5768e9 -r 5cff3579814c target-utils/libcommon/osmodelay.S --- a/target-utils/libcommon/osmodelay.S Sat Dec 12 20:07:51 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ -/* - * This assembly module provides a replica of OsmocomBB's bogo-millisecond - * delay_ms() function. It is literally a copy of what OsmocomBB's delay_ms() - * compiles to with their gcc version and their optimization settings, as seen - * by doing arm-elf-objdump on their lib/delay.o. - * - * This hack is intended for those cases where we have to copy OsmocomBB's - * black magic voodoo operations with no ability to understand what is actually - * needed, such as SPCA552E initialization on the Pirelli DP-L10. - */ - - .text - .code 32 - .globl osmo_delay_ms -osmo_delay_ms: - mov r3, #0 - sub sp, sp, #4 - str r3, [sp] - ldr r3, =1300 - mul r3, r0, r3 - b 2f -1: ldr r2, [sp] - ldr r2, [sp] - add r2, r2, #1 - str r2, [sp] -2: ldr r2, [sp] - cmp r2, r3 - bcc 1b - add sp, sp, #4 - bx lr diff -r 2a867e5768e9 -r 5cff3579814c target-utils/libcommon/serio.S --- a/target-utils/libcommon/serio.S Sat Dec 12 20:07:51 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +0,0 @@ -#include "ns16550.h" - -@ this module implements the elementary serial I/O operations - - .text - .code 32 - .global serial_out -serial_out: - ldr r1, =uart_base - ldr r2, [r1] -1: ldrb r3, [r2, #NS16550_LSR] - tst r3, #NS16550_LSR_THRE - beq 1b - strb r0, [r2, #NS16550_THR] - bx lr - - .global serial_in_poll -serial_in_poll: - ldr r1, =uart_base - ldr r2, [r1] - ldrb r3, [r2, #NS16550_LSR] - tst r3, #NS16550_LSR_DR - ldrneb r0, [r2, #NS16550_RBR] - mvneq r0, #0 - bx lr - - .global serial_flush -serial_flush: - ldr r1, =uart_base - ldr r2, [r1] -1: ldrb r3, [r2, #NS16550_LSR] - tst r3, #NS16550_LSR_TEMP - beq 1b - bx lr diff -r 2a867e5768e9 -r 5cff3579814c target-utils/libcommon/spidrv.c --- a/target-utils/libcommon/spidrv.c Sat Dec 12 20:07:51 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,139 +0,0 @@ -/* Driver for SPI Master Controller inside TI Calypso */ -/* lifted from OsmocomBB and ported to FreeCalypso target-utils environment */ - -/* (C) 2010 by Harald Welte - * - * All Rights Reserved - * - * 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 2 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, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - -#include "types.h" - -#define ASIC_CONF_REG (*(volatile u16 *) 0xFFFEF008) - -struct spi_regs { - u16 reg_set1; - u16 reg_set2; - u16 reg_ctrl; - u16 reg_status; - u16 reg_tx_lsb; - u16 reg_tx_msb; - u16 reg_rx_lsb; - u16 reg_rx_msb; -}; - -#define SPI_REGS (*(volatile struct spi_regs *) 0xFFFE3000) - -#define BASE_ADDR_SPI 0xfffe3000 -#define SPI_REG(n) (BASE_ADDR_SPI+(n)) - -#define SPI_SET1_EN_CLK (1 << 0) -#define SPI_SET1_WR_IRQ_DIS (1 << 4) -#define SPI_SET1_RDWR_IRQ_DIS (1 << 5) - -#define SPI_CTRL_RDWR (1 << 0) -#define SPI_CTRL_WR (1 << 1) -#define SPI_CTRL_NB_SHIFT 2 -#define SPI_CTRL_AD_SHIFT 7 - -#define SPI_STATUS_RE (1 << 0) /* Read End */ -#define SPI_STATUS_WE (1 << 1) /* Write End */ - -spi_init() -{ - static int initdone; - - if (initdone) - return(0); - ASIC_CONF_REG |= 0x6000; - SPI_REGS.reg_set1 = SPI_SET1_EN_CLK | SPI_SET1_WR_IRQ_DIS | - SPI_SET1_RDWR_IRQ_DIS; - SPI_REGS.reg_set2 = 0x0001; - initdone = 1; - return(1); -} - -spi_xfer(dev_idx, bitlen, dout, din) - void *dout, *din; -{ - int bytes_per_xfer; - u16 reg_status, reg_ctrl = 0; - u32 tmp; - - if (bitlen <= 0) - return 0; - - if (bitlen > 32) - return -1; - - if (dev_idx > 4) - return -1; - - bytes_per_xfer = bitlen / 8; - if (bitlen % 8) - bytes_per_xfer ++; - - reg_ctrl |= (bitlen - 1) << SPI_CTRL_NB_SHIFT; - reg_ctrl |= (dev_idx & 0x7) << SPI_CTRL_AD_SHIFT; - - if (bitlen <= 8) { - tmp = *(u8 *)dout; - tmp <<= 24 + (8-bitlen); /* align to MSB */ - } else if (bitlen <= 16) { - tmp = *(u16 *)dout; - tmp <<= 16 + (16-bitlen); /* align to MSB */ - } else { - tmp = *(u32 *)dout; - tmp <<= (32-bitlen); /* align to MSB */ - } - - /* fill transmit registers */ - SPI_REGS.reg_tx_msb = tmp >> 16; - SPI_REGS.reg_tx_lsb = tmp; - - /* initiate transfer */ - if (din) - reg_ctrl |= SPI_CTRL_RDWR; - else - reg_ctrl |= SPI_CTRL_WR; - SPI_REGS.reg_ctrl = reg_ctrl; - - /* wait until the transfer is complete */ - while (1) { - reg_status = SPI_REGS.reg_status; - if (din && (reg_status & SPI_STATUS_RE)) - break; - else if (reg_status & SPI_STATUS_WE) - break; - } - /* FIXME: calibrate how much delay we really need (seven 13MHz cycles) */ - osmo_delay_ms(1); - - if (din) { - tmp = SPI_REGS.reg_rx_msb << 16; - tmp |= SPI_REGS.reg_rx_lsb; - - if (bitlen <= 8) - *(u8 *)din = tmp & 0xff; - else if (bitlen <= 16) - *(u16 *)din = tmp & 0xffff; - else - *(u32 *)din = tmp; - } - - return 0; -} diff -r 2a867e5768e9 -r 5cff3579814c target-utils/loadagent/Makefile --- a/target-utils/loadagent/Makefile Sat Dec 12 20:07:51 2015 +0000 +++ b/target-utils/loadagent/Makefile Wed Dec 30 20:48:12 2015 +0000 @@ -8,7 +8,8 @@ PROG= loadagent OBJS= crt0.o cmdtab.o main.o mygetchar.o -LIBS= ../libcommon/libcommon.a ../libload/libload.a ../libprintf/libprintf.a +LIBS= ../libload/libload.a ../libcommon/libcommon.a ../libprintf/libprintf.a \ + ../libbase/libbase.a LDS= ../env/iram.lds TC_LIBS=`${CC} -print-file-name=libc.a` \ @@ -21,8 +22,7 @@ ${PROG}.elf: ${OBJS} ${LIBS} ${LDS} ${LD} -N --defsym Base_addr=0x838000 --defsym stack_bottom=0x83FFFC \ - -T ${LDS} -o $@ ${OBJS} \ - --start-group ${LIBS} --end-group \ + -T ${LDS} -o $@ ${OBJS} ${LIBS} \ --start-group ${TC_LIBS} --end-group ${PROG}.srec: ${PROG}.elf diff -r 2a867e5768e9 -r 5cff3579814c target-utils/pirexplore/Makefile --- a/target-utils/pirexplore/Makefile Sat Dec 12 20:07:51 2015 +0000 +++ b/target-utils/pirexplore/Makefile Wed Dec 30 20:48:12 2015 +0000 @@ -6,7 +6,8 @@ PROG= pirexplore OBJS= crt0.o cmdtab.o ffsparam.o flashid.o lcd.o main.o mygetchar.o rtc.o -LIBS= ../libcommon/libcommon.a ../libtiffs/libtiffs.a ../libprintf/libprintf.a +LIBS= ../libtiffs/libtiffs.a ../libcommon/libcommon.a \ + ../libprintf/libprintf.a ../libbase/libbase.a LDS= ../env/iram.lds TC_LIBS=`${CC} -print-file-name=libc.a` \ @@ -19,8 +20,7 @@ ${PROG}.elf: ${OBJS} ${LIBS} ${LDS} ${LD} -N --defsym Base_addr=0x800750 --defsym stack_bottom=0x87FFFC \ - -T ${LDS} -o $@ ${OBJS} \ - --start-group ${LIBS} --end-group \ + -T ${LDS} -o $@ ${OBJS} ${LIBS} \ --start-group ${TC_LIBS} --end-group ${PROG}.srec: ${PROG}.elf