nios ii C语言编程

nios ii C语言编程,第1张

看一些教程吧,刚上手就看NIOS手册不容易懂.

这里掘孝推荐<NIOS那些事儿>.虽然内容比较浅,但都很实用.

其它你可茄散举以直接在百度上搜 SOPC教程,书内容都颤碧差不多的,全是直接翻译NIOS手册的.

quartus里面可以用vhdl语言编写管教 或者利用电路图做管教 VHDL可以用到SOPC来建立你要使用的板子上的东西 其首巧慎实就相当于一个驱动

Nios是写内核的 写的程序控制你整个系统

这俩软件加上板子 构成了你整个的FPGA系统者敬 也宽乱就是嵌入式系统

QUARTUS里也是可以写程序的 VERLOG 和VHDL 你可以查下这俩词你就懂了

还有什么问题你可以补充

/drivers/video/niosii/nois11.c

自己去看吧。还要看/drivers/video/fbmem.c 这里面的函数有些会被调用.

给你举个例伍雀子:

static void ipu_clear_usage(int ipu, int di)

{

ipu_usage[ipu][di] = false

}

/*!

 * Probe routine for the framebuffer driver. It is called during the

 * driver binding process.      The following functions are performed in

 * this routine: Framebuffer initialization, Memory allocation and

 * mapping, Framebuffer registration, IPU initialization.

 *

 * @return      Appropriate error code to the kernel common code

 */

static int mxcfb_probe(struct platform_device *pdev)

{

struct ipuv3_fb_platform_data *plat_data = pdev->dev.platform_data

struct fb_info *fbi

struct mxcfb_info *mxcfbi

struct resource *res

struct device *disp_dev

char buf[32]

int ret = 0

/* Initialize FB structures */

fbi = mxcfb_init_fbinfo(&pdev->dev, &mxcfb_ops)

if (!fbi) {

ret = -ENOMEM

goto init_fbinfo_failed

}

ret = mxcfb_option_setup(pdev, fbi)

if (ret)

goto get_fb_option_failed

/**********by zxy add:mod 腔镇早para *************************************************

printk("\n\n\n by zxy 1 : fbi->var.xres =0x%x,fbi->var.yres=0x%x \n\n",fbi->var.xres,fbi->var.yres)

printk("\n\n\n by zxy 1: fbi->var.xres_virtual =0x%x,fbi->var.yres_virtual=0x%x \n\n",fbi->var.xres_virtual,fbi->var.yres_virtual)

fbi->var.xres=800

fbi->var.yres=480

fbi->var.xres_virtual=1920

fbi->var.yres_virtual=1440

printk("\n\n\n by zxy 2: fbi->var.xres =0x%x,fbi->var.yres=0x%x \n\n",fbi->var.xres,fbi->var.yres)

printk("\n\n\n by zxy 2: fbi->var.xres_virtual =0x%x,fbi->var.yres_virtual=0x%x \n\n",fbi->var.xres_virtual,fbi->var.yres_virtual)

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

mxcfbi = (struct mxcfb_info *)fbi->par

spin_lock_init(&旅盯mxcfbi->lock)

mxcfbi->fbi = fbi

mxcfbi->ipu_int_clk = plat_data->int_clk

mxcfbi->late_init = plat_data->late_init

mxcfbi->first_set_par = true

mxcfbi->panel_width_mm = plat_data->panel_width_mm

mxcfbi->panel_height_mm = plat_data->panel_height_mm

ret = mxcfb_dispdrv_init(pdev, fbi)

//by zxy add

//printk("\n\n\n by zxy 1 : mxcfbi->default_bpp==%d\n\n\n",mxcfbi->default_bpp)

//mxcfbi->default_bpp = 16

//printk("\n\n\n by zxy 1 : mxcfbi->default_bpp==%d\n\n\n",mxcfbi->default_bpp)

if (ret < 0)

goto init_dispdrv_failed

ret = ipu_test_set_usage(mxcfbi->ipu_id, mxcfbi->ipu_di)

if (ret < 0) {

dev_err(&pdev->dev, "ipu%d-di%d already in use\n",

mxcfbi->ipu_id, mxcfbi->ipu_di)

goto ipu_in_busy

}

res = platform_get_resource(pdev, IORESOURCE_MEM, 0)

if (res && res->start && res->end) {

fbi->fix.smem_len = res->end - res->start + 1

fbi->fix.smem_start = res->start

// printk("\n\n\n by zxy 2: fbi->fix.smem_start =0x%x \n\n",fbi->fix.smem_start )

fbi->screen_base = ioremap(fbi->fix.smem_start, fbi->fix.smem_len)

// printk("\n\n\n by zxy 3: fbi->screen_base =0x%x \n\n",fbi->screen_base )

// printk("\n\n\n by zxy 4: fbi->fix.smem_len =0x%x \n\n",fbi->fix.smem_len )

//by zxy see 2

/* Do not clear the fb content drawn in bootloader. */

if (!mxcfbi->late_init)

memset(fbi->screen_base, 0, fbi->fix.smem_len)

}

mxcfbi->ipu = ipu_get_soc(mxcfbi->ipu_id)

if (IS_ERR(mxcfbi->ipu)) {

ret = -ENODEV

goto get_ipu_failed

}

/* first user uses DP with alpha feature */

if (!g_dp_in_use[mxcfbi->ipu_id]) {

mxcfbi->ipu_ch_irq = IPU_IRQ_BG_SYNC_EOF

mxcfbi->ipu_ch_nf_irq = IPU_IRQ_BG_SYNC_NFACK

mxcfbi->ipu_alp_ch_irq = IPU_IRQ_BG_ALPHA_SYNC_EOF

mxcfbi->ipu_vsync_pre_irq = mxcfbi->ipu_di ?

    IPU_IRQ_VSYNC_PRE_1 :

    IPU_IRQ_VSYNC_PRE_0

mxcfbi->ipu_ch = MEM_BG_SYNC

/* Unblank the primary fb only by default */

if (pdev->id == 0)

mxcfbi->cur_blank = mxcfbi->next_blank = FB_BLANK_UNBLANK

else

mxcfbi->cur_blank = mxcfbi->next_blank = FB_BLANK_POWERDOWN

ret = mxcfb_register(fbi)

if (ret < 0)

goto mxcfb_register_failed

ipu_disp_set_global_alpha(mxcfbi->ipu, mxcfbi->ipu_ch,

  true, 0x80)

ipu_disp_set_color_key(mxcfbi->ipu, mxcfbi->ipu_ch, false, 0)

res = platform_get_resource(pdev, IORESOURCE_MEM, 1)

ret = mxcfb_setup_overlay(pdev, fbi, res)

if (ret < 0) {

mxcfb_unregister(fbi)

goto mxcfb_setupoverlay_failed

}

g_dp_in_use[mxcfbi->ipu_id] = true

ret = device_create_file(mxcfbi->ovfbi->dev,

 &dev_attr_fsl_disp_property)

if (ret)

dev_err(mxcfbi->ovfbi->dev, "Error %d on creating "

    "file for disp property\n",

    ret)

ret = device_create_file(mxcfbi->ovfbi->dev,

 &dev_attr_fsl_disp_dev_property)

if (ret)

dev_err(mxcfbi->ovfbi->dev, "Error %d on creating "

    "file for disp device "

    "propety\n", ret)

} else {

mxcfbi->ipu_ch_irq = IPU_IRQ_DC_SYNC_EOF

mxcfbi->ipu_ch_nf_irq = IPU_IRQ_DC_SYNC_NFACK

mxcfbi->ipu_alp_ch_irq = -1

mxcfbi->ipu_vsync_pre_irq = mxcfbi->ipu_di ?

    IPU_IRQ_VSYNC_PRE_1 :

    IPU_IRQ_VSYNC_PRE_0

mxcfbi->ipu_ch = MEM_DC_SYNC

mxcfbi->cur_blank = mxcfbi->next_blank = FB_BLANK_POWERDOWN

ret = mxcfb_register(fbi)

if (ret < 0)

goto mxcfb_register_failed

}

platform_set_drvdata(pdev, fbi)

ret = device_create_file(fbi->dev, &dev_attr_fsl_disp_property)

if (ret)

dev_err(&pdev->dev, "Error %d on creating file for disp "

    "property\n", ret)

ret = device_create_file(fbi->dev, &dev_attr_fsl_disp_dev_property)

if (ret)

dev_err(&pdev->dev, "Error %d on creating file for disp "

    " device propety\n", ret)

disp_dev = mxc_dispdrv_getdev(mxcfbi->dispdrv)

if (disp_dev) {

ret = sysfs_create_link(&fbi->dev->kobj,

&disp_dev->kobj, "disp_dev")

if (ret)

dev_err(&pdev->dev,

"Error %d on creating file\n", ret)

}

INIT_WORK(&mxcfbi->vsync_pre_work, mxcfb_vsync_pre_work)

snprintf(buf, sizeof(buf), "mxcfb%d-vsync-pre", fbi->node)

mxcfbi->vsync_pre_queue = create_singlethread_workqueue(buf)

if (mxcfbi->vsync_pre_queue == NULL) {

dev_err(fbi->device,

"Failed to alloc vsync-pre workqueue\n")

ret = -ENOMEM

goto workqueue_alloc_failed

}

#ifdef CONFIG_HAS_EARLYSUSPEND

mxcfbi->fbdrv_earlysuspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB

mxcfbi->fbdrv_earlysuspend.suspend = mxcfb_early_suspend

mxcfbi->fbdrv_earlysuspend.resume = mxcfb_later_resume

mxcfbi->fbdrv_earlysuspend.data = pdev

register_early_suspend(&mxcfbi->fbdrv_earlysuspend)

#endif

//by zxy del,to load  logo.bmp

printk("\n\n\n by zxy 3: fbi->var.xres =%d,fbi->var.yres=%d \n\n",fbi->var.xres,fbi->var.yres)

printk("\n\n\n by zxy 3: fbi->var.xres_virtual =%d,fbi->var.yres_virtual=%d \n\n",fbi->var.xres_virtual,fbi->var.yres_virtual)

printk("\n\n\n by zxy 3: fbi->var.bits_per_pixel =%d,fbi->var.pixclock=%d \n\n",fbi->var.bits_per_pixel,fbi->var.pixclock)

// printk("\n\n\n by zxy 3: fbi->var.xres_virtual =0x%x,fbi->var.yres_virtual=0x%x \n\n",fbi->var.xres_virtual,fbi->var.yres_virtual)

 

#ifdef CONFIG_LOGO

fb_prepare_logo(fbi, 0)

fb_show_logo(fbi, 0)

#endif

return 0

workqueue_alloc_failed:

mxcfb_setupoverlay_failed:

mxcfb_register_failed:

get_ipu_failed:

ipu_clear_usage(mxcfbi->ipu_id, mxcfbi->ipu_di)

ipu_in_busy:

init_dispdrv_failed:

fb_dealloc_cmap(&fbi->cmap)

framebuffer_release(fbi)

get_fb_option_failed:

init_fbinfo_failed:

return ret

}

static int mxcfb_remove(struct platform_device *pdev)

{

struct fb_info *fbi = platform_get_drvdata(pdev)

struct mxcfb_info *mxc_fbi = fbi->par

if (!fbi)

return 0

#ifdef CONFIG_HAS_EARLYSUSPEND

unregister_early_suspend(&mxc_fbi->fbdrv_earlysuspend)

#endif

device_remove_file(fbi->dev, &dev_attr_fsl_disp_dev_property)

device_remove_file(fbi->dev, &dev_attr_fsl_disp_property)

mxcfb_blank(FB_BLANK_POWERDOWN, fbi)

mxcfb_unregister(fbi)

mxcfb_unmap_video_memory(fbi)

if (mxc_fbi->ovfbi) {

device_remove_file(mxc_fbi->ovfbi->dev,

   &dev_attr_fsl_disp_dev_property)

device_remove_file(mxc_fbi->ovfbi->dev,

   &dev_attr_fsl_disp_property)

mxcfb_blank(FB_BLANK_POWERDOWN, mxc_fbi->ovfbi)

mxcfb_unsetup_overlay(fbi)

mxcfb_unmap_video_memory(mxc_fbi->ovfbi)

}

ipu_clear_usage(mxc_fbi->ipu_id, mxc_fbi->ipu_di)

if (&fbi->cmap)

fb_dealloc_cmap(&fbi->cmap)

framebuffer_release(fbi)

return 0

}

/*!

 * This structure contains pointers to the power management callback functions.

 */

static struct platform_driver mxcfb_driver = {

.driver = {

   .name = MXCFB_NAME,

   },

.probe = mxcfb_probe,

.remove = mxcfb_remove,

.suspend = mxcfb_suspend,

.resume = mxcfb_resume,

}

#ifdef CONFIG_HAS_EARLYSUSPEND

static void mxcfb_early_suspend(struct early_suspend *h)

{

struct platform_device *pdev = (struct platform_device *)h->data

struct fb_info *fbi = platform_get_drvdata(pdev)

struct mxcfb_info *mxcfbi = (struct mxcfb_info *)fbi->par

pm_message_t state = { .event = PM_EVENT_SUSPEND }

struct fb_event event

int blank = FB_BLANK_POWERDOWN

if (mxcfbi->ipu_ch == MEM_FG_SYNC)

return

if (strstr(mxcfbi->dispdrv->drv->name, "hdmi")) {

/* Only black the hdmi fb due to audio dependency */

memset(fbi->screen_base, 0, fbi->fix.smem_len)

return

}

mxcfb_core_suspend(pdev, state)

event.info = fbi

event.data = &blank

fb_notifier_call_chain(FB_EVENT_BLANK, &event)

}

static void mxcfb_later_resume(struct early_suspend *h)

{

struct platform_device *pdev = (struct platform_device *)h->data

struct fb_info *fbi = platform_get_drvdata(pdev)

struct mxcfb_info *mxcfbi = (struct mxcfb_info *)fbi->par

struct fb_event event

if (mxcfbi->ipu_ch == MEM_FG_SYNC)

return

/* HDMI resume function has been called */

if (strstr(mxcfbi->dispdrv->drv->name, "hdmi"))

return

mxcfb_core_resume(pdev)

event.info = fbi

event.data = &mxcfbi->next_blank

fb_notifier_call_chain(FB_EVENT_BLANK, &event)

}

#endif

/*!

 * Main entry function for the framebuffer. The function registers the power

 * management callback functions with the kernel and also registers the MXCFB

 * callback functions with the core Linux framebuffer driver \b fbmem.c

 *

 * @return      Error code indicating success or failure

 */

int __init mxcfb_init(void)

{

return platform_driver_register(&mxcfb_driver)

}

void mxcfb_exit(void)

{

platform_driver_unregister(&mxcfb_driver)

}

module_init(mxcfb_init)

module_exit(mxcfb_exit)


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12512819.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-26
下一篇 2023-05-26

发表评论

登录后才能评论

评论列表(0条)

保存