public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] Fwd: Running C program in U-BOOT
       [not found] <d3540f4d0809200157h1ff0e01fr1a6be866637fceac@mail.gmail.com>
@ 2008-09-20  9:03 ` Light King
  2008-09-20 13:59   ` Jerry Van Baren
  0 siblings, 1 reply; 2+ messages in thread
From: Light King @ 2008-09-20  9:03 UTC (permalink / raw)
  To: u-boot

---------- Forwarded message ----------
From: Light King <thelightking@gmail.com>
Date: Sep 20, 2008 2:27 PM
Subject: Running C program in U-BOOT
To: u-boot-users at lists.sourceforge.net

Dear All ,

I m running following code in the U-BOOT but it is not behaving as a C code
. My processor is AT91SAM9263 . This code is to run a ADC present in my
board .

After compiling when I m running this code executable in the board it is not
starting from main function but starting from
pio_set_B_periph function . Can any one help me what is wrong happening here
?



CODE *********************************>>>>>>>>>>>>>>>

#include "AT91SAM9263_inc.h"

#include "gpio.h"



#define writel(value, address) \

(*(volatile unsigned int *)(address)) = (value)

#define readl(address) \

(*(volatile unsigned int *)(address))

//#define EINVAL 1 /* Error code returned when the PIN is unknown */

/* Write PIO register */

static inline void write_pio(unsigned int offset, const unsigned int value)

{

writel(value, offset + AT91C_BASE_PIOA);

}

/* Read PIO registers */

static inline unsigned int read_pio(volatile unsigned int offset)

{

return readl(offset + AT91C_BASE_PIOA);

}



static inline int pio_set_B_periph(unsigned pin, int use_pullup)

{

unsigned pio = ((pin) / PIO_NB_IO);

unsigned mask = (1 << ((pin) % PIO_NB_IO));

//if (pio >= AT91C_NR_PIO)

// return -EINVAL;

write_pio(PIO_IDR(pio), mask);

write_pio((use_pullup ? PIO_PPUER(pio) : PIO_PPUDR(pio)), mask);

write_pio(PIO_BSR(pio), mask);

write_pio(PIO_PDR(pio), mask);

return 0;

}



static inline int pio_set_gpio_input(unsigned pin, int use_pullup)

{

unsigned pio = ((pin) / PIO_NB_IO);

unsigned mask = (1 << ((pin) % PIO_NB_IO));

if (pio >= AT91C_NR_PIO)

return -EINVAL;

write_pio(PIO_IDR(pio), mask);

write_pio((use_pullup ? PIO_PPUER(pio) : PIO_PPUDR(pio)), mask);

write_pio(PIO_ODR(pio), mask);

write_pio(PIO_PER(pio), mask);

return 0;

}



static inline int pio_set_gpio_output(unsigned pin, int value)

{

unsigned pio = ((pin) / PIO_NB_IO);

unsigned mask = (1 << ((pin) % PIO_NB_IO));

//if (pio >= AT91C_NR_PIO)

// return -EINVAL;

write_pio(PIO_IDR(pio), mask);

write_pio(PIO_PPUDR(pio), mask);

write_pio((value ? PIO_SODR(pio) : PIO_CODR(pio)), mask);

write_pio(PIO_OER(pio), mask);

write_pio(PIO_PER(pio), mask);

return 0;

}



static inline int pio_set_value(unsigned pin, int value)

{

unsigned pio = ((pin) / PIO_NB_IO);

unsigned mask = (1 << ((pin) % PIO_NB_IO));

//if (pio >= AT91C_NR_PIO)

// return -EINVAL;

write_pio((value ? PIO_SODR(pio) : PIO_CODR(pio)), mask);

return 0;

}

static inline int pio_get_value(unsigned pin)

{

unsigned pio = ((pin) / PIO_NB_IO);

unsigned mask = (1 << ((pin) % PIO_NB_IO));

unsigned int pdsr;

//if (pio >= AT91C_NR_PIO)

// return -EINVAL;

pdsr = read_pio(PIO_PDSR(pio));

return (pdsr & mask) != 0;

}

main()

{

int i,j,*p,arr[12];

*p=arr;

printf("Setting the PIO as peripherals\n");

pio_set_B_periph(AT91C_PIN_PA(0),(PIO_DEFAULT & PIO_PULLUP) ? 1 : 0);

pio_set_B_periph(AT91C_PIN_PA(1),(PIO_DEFAULT & PIO_PULLUP) ? 1 : 0);

pio_set_B_periph(AT91C_PIN_PA(2),(PIO_DEFAULT & PIO_PULLUP) ? 1 : 0);

pio_set_B_periph(AT91C_PIN_PA(3),(PIO_DEFAULT & PIO_PULLUP) ? 1 : 0);



printf("Setting the PIO as i/p o/p \n");

pio_set_gpio_input(AT91C_PIN_PA(0),(PIO_DEFAULT & PIO_PULLUP) ? 1 : 0);

pio_set_gpio_output(AT91C_PIN_PA(1),PIO_DEFAULT );

pio_set_gpio_output(AT91C_PIN_PA(2),PIO_DEFAULT );

pio_set_gpio_output(AT91C_PIN_PA(3),PIO_DEFAULT );

printf("Loops for writng data and reading data to ADC\n");

pio_set_value(AT91C_PIN_PA(3),1);

pio_set_value(AT91C_PIN_PA(2),1);

for(i=0;i<6;i++);

pio_set_value(AT91C_PIN_PA(3),0);

pio_set_value(AT91C_PIN_PA(1),0);

pio_set_value(AT91C_PIN_PA(2),0);

for(i=0;i<9;i++);

pio_set_value(AT91C_PIN_PA(2),1);

for(i=0;i<9;i++);

p=((if(pio_get_value(AT91C_PIN_PA(0))==1))?1:0);

p++;

pio_set_value(AT91C_PIN_PA(1),1);

pio_set_value(AT91C_PIN_PA(2),0);

for(i=0;i<9;i++);

pio_set_value(AT91C_PIN_PA(2),1);

for(i=0;i<9;i++);

p=((if(pio_get_value(AT91C_PIN_PA(0))==1))?1:0);

p++;

for(j=1;j<=10;j++)

{

pio_set_value(AT91C_PIN_PA(2),0);

for(i=0;i<9;i++);

pio_set_value(AT91C_PIN_PA(2),1);

for(i=0;i<9;i++);

p=((if(pio_get_value(AT91C_PIN_PA(0))==1))?1:0);

p++;

}

pio_set_value(AT91C_PIN_PA(3),1);

printf("digital value is %d",arr);

}

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [U-Boot] Fwd: Running C program in U-BOOT
  2008-09-20  9:03 ` [U-Boot] Fwd: Running C program in U-BOOT Light King
@ 2008-09-20 13:59   ` Jerry Van Baren
  0 siblings, 0 replies; 2+ messages in thread
From: Jerry Van Baren @ 2008-09-20 13:59 UTC (permalink / raw)
  To: u-boot

Light King wrote:
> ---------- Forwarded message ----------
> From: Light King <thelightking@gmail.com>
> Date: Sep 20, 2008 2:27 PM
> Subject: Running C program in U-BOOT
> To: u-boot-users at lists.sourceforge.net
> 
> Dear All ,
> 
> I m running following code in the U-BOOT but it is not behaving as a C code
> . My processor is AT91SAM9263 . This code is to run a ADC present in my
> board .
> 
> After compiling when I m running this code executable in the board it is not
> starting from main function but starting from
> pio_set_B_periph function . Can any one help me what is wrong happening here
> ?

FAQ?
<http://www.denx.de/wiki/view/DULG/MyStandaloneProgramDoesNotWork>

Best regards,
gvb

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-09-20 13:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <d3540f4d0809200157h1ff0e01fr1a6be866637fceac@mail.gmail.com>
2008-09-20  9:03 ` [U-Boot] Fwd: Running C program in U-BOOT Light King
2008-09-20 13:59   ` Jerry Van Baren

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox