您好,欢迎访问三七文档
6avr-libc模块文件–9–66aavvrr--lliibbcc模模块块文文件件6.1assert.h:诊断6.1.1详细描述#includeassert.h这个头文件定义了调试的帮助。由于使用本库的许多应用程序没有标准错误输出流可供使用,默认情况下不允许产生一个可打印的错误信息。应用程序在包含头文件assert.h之前定义宏__ASSERT_USE_STDERR错误信息才会被生成。默认情况下,只有调用abort()才会挂起应用程序。z定义#defineassert(expression)参数:expression对表达式进行测试。宏assert()测试给定的参数expression,如果结果为假,调用assert()的进程将被终止。一条诊断信息写入stderr并且调用函数abort(),可以有效终止程序。如果expression为真,宏assert()不进行任何操作。如果编译时定义了宏NDEBUG(例如使用编译器选项-DNDEBUG),则宏assert()将会被忽略。6.2avr/boot.h:Bootloader功能支持6.2.1详细描述#includeavr/io.h#includeavr/boot.h这个模块定义的宏提供C语言的接口支持某些AVR单片机的Bootloader功能。这些宏设计为可在所有不同大小的Flash存储器下工作。注意:6avr-libc模块文件–10–不是所有的AVR单片机都提供bootloader支持。详情请查看AVR单片机的数据手册。Todo来自Marek的Email:小型器件(除了ATmega64/128),__SPM_REG是在I/O空间中,使用”in”和”out”指令可以生成较短的代码-由于bootloader空间有限,这可能是一个重要的优化方法。zAPI用法示例下面的代码显示了bootAPI的典型用法。#includeinttypes.h#includeavr/interrupt.h#includeavr/pgmspace.hvoidboot_program_page(uint32_tpage,uint8_t*buf){uint16_ti;uint8_tsreg;//关中断sreg=SREG;cli();eeprom_busy_wait();boot_page_erase(page);boot_spm_busy_wait();//等待Flash擦除结束for(i=0;iSPM_PAGESIZE;i+=2){//将数据转换成小端模式uint16_tw=*buf++;w+=(*buf++)8;boot_page_fill(page+i,w);}boot_page_write(page);//在Flash页存储缓冲数据boot_spm_busy_wait();//等待Flash写入结//再使能RWW-section//如果要在引导装入后跳转到应用程序需要这样操作boot_rww_enable();//重开中断(如果中断原来是打开的)SREG=sreg;}6avr-libc模块文件–11–z定义#defineBOOTLOADER_SECTION__attribute__((section(“.bootloader”)))#defineboot_spm_interrupt_enable()(__SPM_REG|=(uint8_t)_BV(SPMIE))#defineboot_spm_interrupt_disable()(__SPM_REG&=(uint8_t)∼_BV(SPMIE))#defineboot_is_spm_interrupt()(__SPM_REG&(uint8_t)_BV(SPMIE))#defineboot_rww_busy()(__SPM_REG&(uint8_t)_BV(__COMMON_ASB))#defineboot_spm_busy()(__SPM_REG&(uint8_t)_BV(SPMEN))#defineboot_spm_busy_wait()do{}while(boot_spm_busy())#defineGET_LOW_FUSE_BITS(0x0000)#defineGET_LOCK_BITS(0x0001)#defineGET_EXTENDED_FUSE_BITS(0x0002)#defineGET_HIGH_FUSE_BITS(0x0003)#defineboot_lock_fuse_bits_get(address)#defineboot_page_fill(address,data)__boot_page_fill_normal(address,data)#defineboot_page_erase(address)__boot_page_erase_normal(address)#defineboot_page_write(address)__boot_page_write_normal(address)#defineboot_rww_enable()__boot_rww_enable()#defineboot_lock_bits_set(lock_bits)__boot_lock_bits_set(lock_bits)#defineboot_page_fill_safe(address,data)#defineboot_page_erase_safe(address)#defineboot_page_write_safe(address)#defineboot_rww_enable_safe()#defineboot_lock_bits_set_safe(lock_bits)6.2.2Define文件6.2.2.1#defineboot_is_spm_interrupt()(__SPM_REG&(uint8_t)_-BV(SPMIE))检查是否使能SPM中断。6.2.2.2#defineboot_lock_bits_set(lock_bits)__boot_lock_bits_set(lock_bits)设置bootloader锁定位。参数:lock_bits置1一位BootLoader锁定位的掩码。注意:在这里,“置1一位”将会写入0值。同时要注意该命令只能用于编程BLBxx位。例如,要禁止SPM指令对Flash的BootLoader存储器段进行写操作,你可以如下所示6avr-libc模块文件–12–使用该宏:boot_lock_bits_set(_BV(BLB12));注意:和其他锁定位一样,BootLoader锁定位一旦设置就不能再清除,除非芯片擦除包括擦除bootloader本身。6.2.2.3#defineboot_lock_bits_set_safe(lock_bits)源代码:do{\boot_spm_busy_wait();\eeprom_busy_wait();\boot_lock_bits_set(lock_bits);\}while(0)等待eeprom和spm操作完成后再设置锁定位,其余与boot_lock_bits_set()相同。6.2.2.4#defineboot_lock_fuse_bits_get(address)源代码:(__extension__({\uint8_t__result;\__asm____volatile__\(\“ldir30,%3\n\t”\“ldir31,0\n\t”\“sts%1,%2\n\t”\“lpm%0,Z\n\t”\:“=r”(__result)\:“i”(_SFR_MEM_ADDR(__SPM_REG)),\“r”((uint8_t)__BOOT_LOCK_BITS_SET),\“M”(address)\:“r0”,“r30”,“r31”\);\__result;\}))读取给定地址的锁定位或熔丝位。参数:Address可以是GET_LOW_FUSE_BITS,GET_LOCK_BITS,6avr-libc模块文件–13–GET_EXTENDED_FUSE_BITS或GET_HIGH_FUSE_BITS之一。注意:锁定位和熔丝位返回的是物理值,返回0表示相应的熔丝位或锁定位已被编程。6.2.2.5#defineboot_page_erase(address)__boot_page_erase_normal(address)擦除包含address地址的Flash页。注意:address是指Flash的字节地址,不是字地址。6.2.2.6#defineboot_page_erase_safe(address)源代码:do{\boot_spm_busy_wait();\eeprom_busy_wait();\boot_page_erase(address);\}while(0)等待eeprom和spm操作完成后再擦除页,其余与boot_page_erase()相同。6.2.2.7#defineboot_page_fill(address,data)__boot_page_fill_normal(address,data)将待写入address地址的数据字data写入页临时缓冲区。注意:地址address是字节地址,数据是字(16位)。AVR单片机一次向缓冲区写入一个字,但是按照字节方式进行寻址!因此,一定要将地址增量设为2,并且按照字的格式一次送入两个字节的数据!数据的低8位写到低位地址,数据的高8位写入高位地址。6.2.2.8#defineboot_page_fill_safe(address,data)源代码:do{\boot_spm_busy_wait();\eeprom_busy_wait();\boot_page_fill(address,data);\}while(0)6avr-libc模块文件–14–等待eeprom和spm操作完成后再填充页,其余与boot_page_fill()相同。6.2.2.9#defineboot_page_write(address)__boot_page_write_normal(address)将bootloader页临时缓冲区的内容写入包含address地址的Flash页。注意:address是指Flash的字节地址,不是字地址。6.2.2.10#defineboot_page_write_safe(address)源代码:do{\boot_spm_busy_wait();\eeprom_busy_wait();\boot_page_write(address);\}while(0)等待eeprom和spm操作完成后再页写入,其余与boot_page_write()相同。6.2.2.11#defineboot_rww_busy()(__SPM_REG&(uint8_t)_BV(__-COMMON_ASB))检查RWW区域是否繁忙。6.2.2.12#defineboot_rww_enable()__boot_rww_enable()使能Read-While-Write存储器区。6.2.2.13#defineboot_rww_enable_safe()源代码:do{\boot_spm_busy_wait();\eeprom_busy_wait();\boot_rww_enable();\}while(0)等待eeprom和spm操作完成后再使能RWW存储器区,其余与boot_rww_enable()相同。6.2.2.14#defineboot_spm_busy()(__SPM_REG&(uint8_t)_BV(SPMEN))检查SPM指令是否繁忙。6avr-libc模块文件–15–6.2.2.15#defineboot_spm_busy_wait()do{}while(boot_spm_busy())当SPM指令繁忙时,等待。6.2.2.16#defineboot_spm_in
本文标题:AVR库参考手册
链接地址:https://www.777doc.com/doc-6242823 .html