标签:执行 技术 makefile 语句 优化 string res define day
#define NAND_SECTOR_SIZE 2048 /* 读函数 */ void nand_read(unsigned char *buf, unsigned long start_addr, int size) { int i, j; //if ((start_addr & NAND_BLOCK_MASK) || (size & NAND_BLOCK_MASK)) if (start_addr & NAND_BLOCK_MASK) return; /* 地址不对齐则退出 */ /* 选中芯片 */ nand_select_chip(); for(i=start_addr; i < (start_addr + size);) { /* 发出READ0命令 */ write_cmd(0); /* Write Address */ write_addr(i); write_cmd(0x30); /* 等待数据就绪 */ wait_idle(); for(j=0; j < NAND_SECTOR_SIZE; j++, i++) { *buf = read_data(); buf++; } } /* 取消片选信号 */ nand_disselect_chip(); return; }
/* * val : 需要转换的整形值 * bit : 该整形值的位数 * pdst : 转换字符串输出 */ void int_to_str(int val, unsigned char bit, char *pdst) { //根据val位数确定mult. E.G. val-1位 -> mult=1 int mult; for (mult = 1; --bit != 0; mult *= 10); for ( ; mult != 0; mult /= 10) { *pdst++ = (char)(val/mult + ‘0‘); val %= mult; } }
#Time: 2018-4-19 11:56:52
#Proj: General Makefile
#Designed by DZH for JZ2440
#Define vars
TARGET_NAME := iic
#final target
TARGET := $(TARGET_NAME).bin
#temp target
BUILD := $(TARGET_NAME).elf
#disa target
DISA := $(TARGET_NAME).dis
#default boot from NAND Flash
ENV ?= NAND
OBJS += start.o
OBJS += init.o
OBJS += main.o
OBJS += iic.o
OBJS += nand.o
OBJS += serial.o
OBJS += m41t11.o
OBJS += irq_handler.o
OBJS += lib/libc.a
CROSS_COMPILE := arm-linux-
CC := $(CROSS_COMPILE)gcc
LD := $(CROSS_COMPILE)ld
AR := $(CROSS_COMPILE)ar
OBJCOPY := $(CROSS_COMPILE)objcopy
OBJDUMP := $(CROSS_COMPILE)objdump
#warning
INCLUDEDIR := $(shell pwd)/include
CCFLAGS += -nostdinc -I$(INCLUDEDIR)
CCFLAGS += -Wall -O2
# 不加-O2优化,链接过程报错:
# lib/libc.a(string.o)(.text+0x38): In function `puts‘:
# : undefined reference to `putc‘
#basic address
#ifeq ($(ENV), NAND)
#LDFLAGS += -Ttext=0x0
#else
#LDFLAGS += -Ttext=0xXXX
#endif
LDFLAGS += -Tmap.lds
export CC LD OBJCOPY OBJDUMP INCLUDEDIR CCFLAGS AR
#Compile way
all : $(DISA) $(TARGET)
$(DISA) : $(BUILD)
$(OBJDUMP) -D $^ > $@
$(TARGET) : $(BUILD)
$(OBJCOPY) -O binary -S $^ $@
$(BUILD) : $(OBJS)
$(LD) $(LDFLAGS) -o $@ $^
.PHONY : lib/libc.a
lib/libc.a:
cd lib; make; cd ..
%.o : %.S
$(CC) $(CCFLAGS) -c -o $@ $^
%.o : %.c
$(CC) $(CCFLAGS) -c -o $@ $^
clean:
make clean -C lib
rm -f $(TARGET) $(BUILD) $(DISA) *.o
/* * pstr : 字符串首地址,空字符结束 * len : 字符串有效字符长度 */ int str_to_int(const char *pstr, unsigned char len) { unsigned int ret = 0; unsigned int mult; //根据pstr长度确定mult. E.G. pstr-1位 -> mult=1 for (mult = 1; --len != 0; mult *= 10); for ( ;*pstr != ‘\0‘; ++pstr) { ret += (unsigned int)(*pstr - ‘0‘) * mult; mult /= 10; } return (int)ret; }
/* * val : 需要转换的整形值 * bit : 该整形值的位数 * pdst : 转换字符串输出 */ void int_to_str(int val, unsigned char bit, char *pdst) { //根据val位数确定mult. E.G. val-1位 -> mult=1 int mult; for (mult = 1; --bit != 0; mult *= 10); for ( ; mult != 0; mult /= 10) { *pdst++ = (char)(val/mult + ‘0‘); val %= mult; } }
struct rtc_time { int tm_sec; int tm_min; int tm_hour; int tm_week; int tm_mday; int tm_mon; int tm_year; };
void set_rtc_time(char *pstr, struct rtc_time *prtc) { char *ptmp = pstr; char s_time[25]; unsigned char i; unsigned char len[7] = {0}; //1. 分拆时间字符串 for ( i = 0; *ptmp != ‘\0‘; ++ptmp) { if (*ptmp != ‘ ‘) len[i]++; else { *ptmp = ‘\0‘; ++i; } } //2. 设置对应rtc时间参数 send_l(pstr); prtc->tm_year = str_to_int(pstr, len[0]); pstr += len[0] + 1; prtc->tm_mon = str_to_int(pstr, len[1]); pstr += len[1] + 1; prtc->tm_mday = str_to_int(pstr, len[2]); pstr += len[2] + 1; prtc->tm_week = str_to_int(pstr, len[3]); pstr += len[3] + 1; prtc->tm_hour = str_to_int(pstr, len[4]); pstr += len[4] + 1; prtc->tm_min = str_to_int(pstr, len[5]); pstr += len[5] + 1; prtc->tm_sec = str_to_int(pstr, len[6]); } void set_time(void) { char s_time[30] = {0}; send_l("E.G.(year-mon-day-week-hour-min-sec): 2018 5 15 2 13 29 0"); recv_l(s_time); send_s("Input: "); send_l(s_time); set_rtc_time(s_time, &g_rtc_time); m41t11_set_datetime(&g_rtc_time); }
void set_rtc_time(char *pstr, struct rtc_time *prtc) { char *ptmp = pstr; char s_time[25]; unsigned char i; unsigned char len[7] = {0}; //1. 分拆时间字符串 for ( i = 0; *ptmp != ‘\0‘; ++ptmp) { if (*ptmp != ‘ ‘) len[i]++; else { *ptmp = ‘\0‘; ++i; } } //2. 设置对应rtc时间参数 send_l(pstr); prtc->tm_year = str_to_int(pstr, len[0]); pstr += len[0] + 1; send_l(pstr); prtc->tm_mon = str_to_int(pstr, len[1]); pstr += len[1] + 1; send_l(pstr); prtc->tm_mday = str_to_int(pstr, len[2]); pstr += len[2] + 1; send_l(pstr); prtc->tm_week = str_to_int(pstr, len[3]); pstr += len[3] + 1; send_l(pstr); prtc->tm_hour = str_to_int(pstr, len[4]); pstr += len[4] + 1; send_l(pstr); prtc->tm_min = str_to_int(pstr, len[5]); pstr += len[5] + 1; send_l(pstr); prtc->tm_sec = str_to_int(pstr, len[6]); get_rtc_time(&g_rtc_time, s_time); send_s("g_rtc_time: "); send_l(s_time); }
void get_rtc_time(const struct rtc_time *prtc, char *pdst) { //格式: 2018-05-15 2 19:30:00 int_to_str(prtc->tm_year, 4, pdst); *(pdst+4) = ‘-‘; int_to_str(prtc->tm_mon, 2, pdst+5); *(pdst+7) = ‘-‘; int_to_str(prtc->tm_mday, 2, pdst+8); *(pdst+10) = ‘ ‘; int_to_str(prtc->tm_week, 1, pdst+11); *(pdst+12) = ‘ ‘; int_to_str(prtc->tm_hour, 2, pdst+13); *(pdst+15) = ‘:‘; int_to_str(prtc->tm_min, 2, pdst+16); *(pdst+18) = ‘:‘; int_to_str(prtc->tm_sec, 2, pdst+19); *(pdst+21) = ‘\0‘; } void show_time(void) { //格式: 2018-05-15 2 13:29:00 char s_time[25] = {0}; send_s("Now is: "); m41t11_get_datetime(&g_rtc_time); get_rtc_time(&g_rtc_time, s_time); send_l(s_time); }
m41t11_set_datetime(&g_rtc_time);
ARM裸板开发:07_IIC 通过IIC总线接口读写时钟芯片时间参数实现的总结
标签:执行 技术 makefile 语句 优化 string res define day
原文地址:https://www.cnblogs.com/Glory-D/p/9062245.html