Browse Source

xc_ppf1901: add lmk_regs.S

Signed-off-by: surenyi <surenyi82@163.com>
master
surenyi 5 years ago
parent
commit
ccd0ea45bc
  1. 37
      2q
  2. 58
      lib/spi.c
  3. 9
      lib/spi.h
  4. 8
      targets/xc_ppf1901/flash.ld
  5. 3
      targets/xc_ppf1901/lmk.c
  6. 2
      targets/xc_ppf1901/lmk_regs.S
  7. 128
      targets/xc_ppf1901/regs_data.txt
  8. 2
      targets/xc_ppf1901/target.mk

37
2q

@ -1,37 +0,0 @@
TARGET_CFLAGS += -I$(lib_dir)
lib_srcs += \
$(lib_dir)/gcc_stubs.c \
$(lib_dir)/tick.c \
$(lib_dir)/fifo.c \
$(lib_dir)/cmd.c \
$(lib_dir)/commands.c \
$(lib_dir)/gpio.c \
$(lib_dir)/a3k.c \
$(lib_dir)/serial.c \
$(lib_dir)/vrom.c \
$(lib_dir)/utils.c \
$(lib_dir)/sdram.c \
$(lib_dir)/is42s32800g.c \
$(lib_dir)/timer.c \
$(lib_dir)/ymodem.c \
$(lib_dir)/iic.c \
$(lib_dir)/i2c.c \
$(lib_dir)/iis.c \
$(lib_dir)/spi.c \
$(lib_dir)/can.c \
$(lib_dir)/spi_flash.c \
$(lib_dir)/at24c256_i2c.c \
$(lib_dir)/at24c256_iic.c \
$(lib_dir)/eeprom.c \
$(lib_dir)/bkp_sram.c \
$(lib_dir)/flash_if.c \
$(lib_dir)/iwdg.c \
$(lib_dir)/wm8978.c \
$(lib_dir)/serial_ymodem.c \
$(lib_dir)/stdio_ymodem.c \
$(lib_dir)/sdio_sd.c \
$(lib_dir)/printf.c \
lib_objs = $(lib_srcs:.c=.o)

58
lib/spi.c

@ -26,9 +26,45 @@ static uint32_t __PCLK1()
return clks.PCLK1_Frequency;
}
int spi_setup(spi_t spi, uint32_t cs, int mode, int bps)
static uint16_t __clk_prescale(int bps)
{
uint16_t prescale = SPI_BaudRatePrescaler_4;
uint32_t clk;
clk = __PCLK1();
if (bps >= (clk / 2)) {
prescale = SPI_BaudRatePrescaler_2;
} else if ((bps >= (clk / 4)) && (bps < (clk / 2))) {
prescale = SPI_BaudRatePrescaler_4;
} else if ((bps >= (clk / 8)) && (bps < (clk / 4))) {
prescale = SPI_BaudRatePrescaler_8;
} else if ((bps >= (clk / 16)) && (bps < (clk / 8))) {
prescale = SPI_BaudRatePrescaler_16;
} else if ((bps >= (clk / 32)) && (bps < (clk / 16))) {
prescale = SPI_BaudRatePrescaler_32;
} else if ((bps >= (clk / 64)) && (bps < (clk / 32))) {
prescale = SPI_BaudRatePrescaler_64;
} else if ((bps >= (clk / 128)) && (bps < (clk / 64))) {
prescale = SPI_BaudRatePrescaler_128;
} else if (bps < (clk / 128)) {
prescale = SPI_BaudRatePrescaler_256;
}
return prescale;
}
void spi_set_speed(spi_t spi, int bps)
{
if (bps > 0) {
SPI_Cmd(spi->base, DISABLE);
spi->conf.SPI_BaudRatePrescaler = __clk_prescale(bps);
SPI_Init(spi->base, &spi->conf);
SPI_Cmd(spi->base, ENABLE);
}
}
int spi_setup(spi_t spi, uint32_t cs, int mode, int bps)
{
uint16_t prescale = SPI_BaudRatePrescaler_4;
if (spi->setup)
@ -56,25 +92,7 @@ int spi_setup(spi_t spi, uint32_t cs, int mode, int bps)
spi->conf.SPI_Mode = SPI_Mode_Master;
if (bps > 0) {
clk = __PCLK1();
if (bps >= (clk / 2)) {
prescale = SPI_BaudRatePrescaler_2;
} else if ((bps >= (clk / 4)) && (bps < (clk / 2))) {
prescale = SPI_BaudRatePrescaler_4;
} else if ((bps >= (clk / 8)) && (bps < (clk / 4))) {
prescale = SPI_BaudRatePrescaler_8;
} else if ((bps >= (clk / 16)) && (bps < (clk / 8))) {
prescale = SPI_BaudRatePrescaler_16;
} else if ((bps >= (clk / 32)) && (bps < (clk / 16))) {
prescale = SPI_BaudRatePrescaler_32;
} else if ((bps >= (clk / 64)) && (bps < (clk / 32))) {
prescale = SPI_BaudRatePrescaler_64;
} else if ((bps >= (clk / 128)) && (bps < (clk / 64))) {
prescale = SPI_BaudRatePrescaler_128;
} else if (bps < (clk / 128)) {
prescale = SPI_BaudRatePrescaler_256;
}
prescale = __clk_prescale(bps);
}
spi->conf.SPI_BaudRatePrescaler = prescale;

9
lib/spi.h

@ -3,6 +3,7 @@
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include "config.h"
@ -18,13 +19,18 @@ typedef struct spi_descr *spi_t;
int spi_setup(spi_t, uint32_t cs, int mode, int bps);
void spi_close(spi_t spi);
void spi_set_speed(spi_t spi, int bps);
void spi_set_mode(spi_t, int mode);
void spi_close(spi_t spi);
uint8_t spi_send_byte(spi_t spi, uint8_t data);
int spi_transfer(spi_t spi, const uint8_t *tx, uint8_t *rx, int len);
void spi_cs(spi_t spi, int cs);
uint8_t spi_txrx(spi_t spi, uint8_t data);
#if (TARGET_HAS_SPI1)
@ -38,5 +44,6 @@ extern struct spi_descr spi1;
#ifdef __cplusplus
}
#endif
#endif

8
targets/xc_ppf1901/flash.ld

@ -60,6 +60,14 @@ SECTIONS {
PROVIDE_HIDDEN (__fini_array_end = .);
} >flash
.regdata : {
. = ALIGN(0x4);
__lmk_reg_data_start = .;
KEEP(*(.lmk_regdata*))
__lmk_reg_data_end = .;
} > flash
.cmdline_cmd : {
. = ALIGN(0x4);
__cmdline_cmd_start = .;

3
targets/xc_ppf1901/lmk.c

@ -402,6 +402,8 @@ static reg_cfg_t lmk1regs[] = {
};
#endif
extern char * __lmk_reg_data_start;
extern char * __lmk_reg_data_end;
int lmk_init(int cs)
{
int i;
@ -412,6 +414,7 @@ int lmk_init(int cs)
lmk_write(cs, 0, 16);
dwt_wait_ms(100);
*/
printf("start: %u, end: %u, len: %d\r\n", (unsigned int)__lmk_reg_data_start, (unsigned int)__lmk_reg_data_end, ((unsigned int)__lmk_reg_data_end - (unsigned int)__lmk_reg_data_start));
lmk_write(cs, 0, 90);
dwt_wait_ms(10);

2
targets/xc_ppf1901/lmk_regs.S

@ -0,0 +1,2 @@
.section .lmk_regdata,"a",%progbits
.incbin "regs_data.txt"

128
targets/xc_ppf1901/regs_data.txt

@ -0,0 +1,128 @@
R0 (INIT) 0x000090
R0 0x000010
R2 0x000200
R3 0x000306
R4 0x0004D0
R5 0x00055B
R6 0x000600
R12 0x000C51
R13 0x000D04
R256 0x010006
R257 0x010165
R258 0x010255
R259 0x010301
R260 0x010422
R261 0x010500
R262 0x010670
R263 0x010715
R264 0x01081E
R265 0x010955
R266 0x010A55
R267 0x010B01
R268 0x010C02
R269 0x010D00
R270 0x010E30
R271 0x010F10
R272 0x01101E
R273 0x011155
R274 0x011255
R275 0x011300
R276 0x011402
R277 0x011500
R278 0x011670
R279 0x011701
R280 0x01181E
R281 0x011955
R282 0x011A55
R283 0x011B00
R284 0x011C02
R285 0x011D00
R286 0x011E71
R287 0x011F01
R288 0x01201E
R289 0x012155
R290 0x012255
R291 0x012300
R292 0x012402
R293 0x012500
R294 0x012600
R295 0x012711
R296 0x012818
R297 0x012955
R298 0x012A55
R299 0x012B00
R300 0x012C02
R301 0x012D00
R302 0x012E40
R303 0x012F11
R304 0x01301E
R305 0x013155
R306 0x013255
R307 0x013300
R308 0x013422
R309 0x013500
R310 0x013600
R311 0x013701
R312 0x013826
R313 0x013903
R314 0x013A00
R315 0x013B1E
R316 0x013C00
R317 0x013D00
R318 0x013E00
R319 0x013F01
R320 0x014001
R321 0x014100
R322 0x014200
R323 0x014313
R324 0x0144FF
R325 0x01457F
R326 0x014618
R327 0x014702
R328 0x014802
R329 0x014942
R330 0x014A02
R331 0x014B16
R332 0x014C00
R333 0x014D00
R334 0x014EC0
R335 0x014F7F
R336 0x015003
R337 0x015102
R338 0x015200
R339 0x015300
R340 0x015480
R341 0x015500
R342 0x015678
R343 0x015700
R344 0x015896
R345 0x015900
R346 0x015A33
R347 0x015BD4
R348 0x015C20
R349 0x015D00
R350 0x015E01
R351 0x015F0B
R352 0x016000
R353 0x016104
R354 0x016204
R355 0x016300
R356 0x016400
R357 0x01650B
R369 0x0171AA
R370 0x017202
R380 0x017C15
R381 0x017D33
R358 0x016600
R359 0x016700
R360 0x016896
R361 0x016959
R362 0x016A20
R363 0x016B00
R364 0x016C00
R365 0x016D00
R366 0x016E13
R371 0x017300
R8189 0x1FFD00
R8190 0x1FFE00
R8191 0x1FFF53

2
targets/xc_ppf1901/target.mk

@ -27,5 +27,5 @@ vocoder_srcs := \
iap_srcs := \
$(target_dir)/iap.c
$(target)_objs := $(vocoder_srcs:.c=.o)
$(target)_objs := $(vocoder_srcs:.c=.o) $(target_dir)/lmk_regs.o

Loading…
Cancel
Save