• 大小: 3.71MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-11-19
  • 语言: 其他
  • 标签: OLED  K60  SPI  

资源简介

本OLED程序例程包含了K60_4WIRE_SPI例程,使用keil软件开发环境,程序注释完整详细,可作为学习及参考的样本

资源截图

代码片段和文件信息

/*
 * File:        alloc.c
 * Purpose:     generic malloc() and free() engine
 *
 * Notes:       99% of this code stolen/borrowed from the K&R C
 *              examples.
 *
 */

#include “common.h“
#include “stdlib.h“

#pragma section = “HEAP“

/********************************************************************/

/*
 * This struct forms the minimum block size which is allocated and
 * also forms the linked list for the memory space used with alloc()
 * and free().  It is padded so that on a 32-bit machine all malloc‘ed
 * pointers are 16-byte aligned.
 */
typedef struct ALLOC_HDR
{
    struct
    {
        struct ALLOC_HDR     *ptr;
        unsigned int size;
    } s;
    unsigned int align;
    unsigned int pad;
} ALLOC_HDR;

static ALLOC_HDR base;
static ALLOC_HDR *freep = NULL;

/********************************************************************/
void
free (void *ap)
{
    ALLOC_HDR *bp *p;

    bp = (ALLOC_HDR *)ap - 1;   /* point to block header */
    for (p = freep; !((bp > p) && (bp < p->s.ptr)) ; p = p->s.ptr)
    {
        if ((p >= p->s.ptr) && ((bp > p) || (bp < p->s.ptr)))
        {
            break; /* freed block at start or end of arena */
        }
    }

    if ((bp + bp->s.size) == p->s.ptr)
    {
        bp->s.size += p->s.ptr->s.size;
        bp->s.ptr = p->s.ptr->s.ptr;
    }
    else
    {
        bp->s.ptr = p->s.ptr;
    }

    if ((p + p->s.size) == bp)
    {
        p->s.size += bp->s.size;
        p->s.ptr = bp->s.ptr;
    }
    else
    {
        p->s.ptr = bp;
    }

    freep = p;
}

/********************************************************************/
void *
malloc (unsigned nbytes)
{
    /* Get addresses for the HEAP start and end */
#if (defined(CW))
      extern char __HEAP_START;
      extern char __HEAP_END[];
    #elif (defined(IAR))
      char* __HEAP_START = __section_begin(“HEAP“);
      char* __HEAP_END = __section_end(“HEAP“);
    #endif
   
    ALLOC_HDR *p *prevp;
    unsigned nunits;

    nunits = ((nbytes+sizeof(ALLOC_HDR)-1) / sizeof(ALLOC_HDR)) + 1;

    if ((prevp = freep) == NULL)
    {
        p = (ALLOC_HDR *)__HEAP_START;
        p->s.size = ( ((uint32)__HEAP_END - (uint32)__HEAP_START)
            / sizeof(ALLOC_HDR) );
        p->s.ptr = &base;
        base.s.ptr = p;
        base.s.size = 0;
        prevp = freep = &base;
    }

    for (p = prevp->s.ptr; ; prevp = p p = p->s.ptr)
    {
        if (p->s.size >= nunits)
        {
            if (p->s.size == nunits)
            {
                prevp->s.ptr = p->s.ptr;
            }
            else
            {
                p->s.size -= nunits;
                p += p->s.size;
                p->s.size = nunits;
            }
            freep = prevp;
            return (void *)(p + 1);
        }

        if (p == freep)
            return NULL;
    }
}

/*******************************************

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2015-07-12 11:12  K60_4WIRE_SPI\
     文件         191  2013-05-25 16:53  K60_4WIRE_SPI\Demo_OLED.eww
     目录           0  2015-07-12 11:12  K60_4WIRE_SPI\build\
     目录           0  2015-07-12 11:12  K60_4WIRE_SPI\build\iar\
     目录           0  2015-07-12 11:12  K60_4WIRE_SPI\build\iar\config files\
     文件        2030  2010-10-27 14:30  K60_4WIRE_SPI\build\iar\config files\128KB_Pflash.icf
     文件        2206  2010-11-11 14:41  K60_4WIRE_SPI\build\iar\config files\128KB_Pflash_128KB_Dflash.icf
     文件        2034  2010-10-27 14:30  K60_4WIRE_SPI\build\iar\config files\128KB_Ram.icf
     文件        2030  2010-10-27 14:30  K60_4WIRE_SPI\build\iar\config files\256KB_Pflash.icf
     文件        2214  2010-11-11 14:41  K60_4WIRE_SPI\build\iar\config files\256KB_Pflash_256KB_Dflash.icf
     文件        2024  2010-10-27 14:30  K60_4WIRE_SPI\build\iar\config files\32KB_Ram.icf
     文件        2041  2010-10-27 14:30  K60_4WIRE_SPI\build\iar\config files\512KB_Pflash.icf
     文件        2217  2010-11-11 14:41  K60_4WIRE_SPI\build\iar\config files\64KB_Pflash_64KB_Dflash.icf
     文件        2024  2010-10-27 14:30  K60_4WIRE_SPI\build\iar\config files\64KB_Ram.icf
     目录           0  2015-07-12 11:12  K60_4WIRE_SPI\build\iar\hello_world\
     目录           0  2015-07-12 11:12  K60_4WIRE_SPI\build\iar\hello_world\FLASH_512KB_PFLASH\
     目录           0  2015-07-12 11:12  K60_4WIRE_SPI\build\iar\hello_world\FLASH_512KB_PFLASH\Exe\
     文件      195912  2014-06-26 09:42  K60_4WIRE_SPI\build\iar\hello_world\FLASH_512KB_PFLASH\Exe\hello_world_K60.out
     文件       23296  2014-06-26 09:42  K60_4WIRE_SPI\build\iar\hello_world\FLASH_512KB_PFLASH\Exe\hello_world_K60.srec
     目录           0  2015-07-12 11:12  K60_4WIRE_SPI\build\iar\hello_world\FLASH_512KB_PFLASH\List\
     文件       34505  2014-06-26 09:41  K60_4WIRE_SPI\build\iar\hello_world\FLASH_512KB_PFLASH\List\CRC.lst
     文件       22901  2014-06-26 09:41  K60_4WIRE_SPI\build\iar\hello_world\FLASH_512KB_PFLASH\List\CRC.s
     文件       29979  2014-06-26 09:41  K60_4WIRE_SPI\build\iar\hello_world\FLASH_512KB_PFLASH\List\HAL_SPI.lst
     文件       23213  2014-06-26 09:41  K60_4WIRE_SPI\build\iar\hello_world\FLASH_512KB_PFLASH\List\HAL_SPI.s
     文件       31263  2014-05-04 15:25  K60_4WIRE_SPI\build\iar\hello_world\FLASH_512KB_PFLASH\List\Oled_Printf.lst
     文件       22061  2014-05-04 15:25  K60_4WIRE_SPI\build\iar\hello_world\FLASH_512KB_PFLASH\List\Oled_Printf.s
     文件      107529  2014-05-04 15:25  K60_4WIRE_SPI\build\iar\hello_world\FLASH_512KB_PFLASH\List\Oled_SSD1306.lst
     文件       44249  2014-05-04 15:25  K60_4WIRE_SPI\build\iar\hello_world\FLASH_512KB_PFLASH\List\Oled_SSD1306.s
     文件       67363  2014-06-26 09:41  K60_4WIRE_SPI\build\iar\hello_world\FLASH_512KB_PFLASH\List\SPI_FLASH.lst
     文件       43925  2014-06-26 09:41  K60_4WIRE_SPI\build\iar\hello_world\FLASH_512KB_PFLASH\List\SPI_FLASH.s
     文件       20539  2014-06-26 09:41  K60_4WIRE_SPI\build\iar\hello_world\FLASH_512KB_PFLASH\List\adc16.lst
............此处省略1077个文件信息

评论

共有 条评论