I need to write quite simple program which makes LED diode flashes using processor ARM AT91SAM9263. I need to run this code using QEMU emulator, which is installed on my Ubuntu machine.
I am trying to write a program with 4 functions, which are initializing LED ports and Buttons ports, which are flashing LED diodes and checks the Buttons status (if it is pulled or not).
I have defined base registers, although I have a problem with making LED diodes to switch them on/off and to check buttons status. Simply, nothing happens.
Below is my code:
#include <stdio.h>
#include "AT91SAM9263-EK.h"
#include "AT91SAM9263.h"
#include "project.h"
#include <stdint.h>
#include <stdbool.h>
#define AT91B_LED1 AT91C_PIO_PB8 /* DS1 */
#define AT91B_LED2 AT91C_PIO_PC29 /* DS2 */
#define AT91B_NB_LEB 2
#define AT91D_BASE_PIO_LED1 (AT91C_BASE_PIOB)
#define AT91D_BASE_PIO_LED2 (AT91C_BASE_PIOC)
#define AT91D_ID_PIO_LED1 (AT91C_ID_PIOB)
#define AT91D_ID_PIO_LED2 (AT91C_ID_PIOC)
#define AT91B_BP1 AT91C_PIO_PC5 // Left click#
#define AT91B_BP2 AT91C_PIO_PC4 // Right click
#define AT91D_BASE_PIO_BP AT91C_BASE_PIOC
#define AT91D_ID_PIO_BP AT91C_ID_PIOCDE
void LedPortInit()
{
AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_PIOCDE ); // peripheral clock enable register (port C, D, E)/* Set the PIO line as input */
AT91D_BASE_PIO_LED1->PIO_ODR = 0x0000000F;
AT91D_BASE_PIO_LED1->PIO_PER = AT91C_PIO_PB8;
AT91D_BASE_PIO_LED2->PIO_OER = AT91C_PIO_PC29 ;
AT91D_BASE_PIO_LED2->PIO_PER = 0xFFFFFFFF;// 1 – Enable PIO to control the pin
AT91C_BASE_PIOE->PIO_PER = AT91C_PIO_PB31;/* Disable pull-up */
AT91C_BASE_PIOA->PIO_PPUDR = 0xFFFF0000;
}
void ButonPortInit()
{
AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_PIOCDE ); // peripheral clock enable register (port C, D, E)/* Set the PIO line as input */
AT91C_BASE_PIOD->PIO_ODR = 0x0000000F;
AT91C_BASE_PIOD->PIO_PER = AT91C_PIO_PC5;
AT91C_BASE_PIOB->PIO_OER = AT91C_PIO_PC4 ;
AT91C_BASE_PIOD->PIO_PER = 0xFFFFFFFF;// 1 – Enable PIO to control the pin
AT91C_BASE_PIOE->PIO_PER = AT91C_PIO_PB31;/* Disable pull-up */
AT91C_BASE_PIOA->PIO_PPUDR = 0xFFFF0000;
}
void LedSwitch()
{
while(1)
{
AT91B_LED1->AT91C_PIO_PB8 ^= 1;
}
AT91C_PIO_PC29 << 29 ;
}
void ButtonTest()
{
AT91C_PIO_PC5 << 5;
AT91C_PIO_PC4 << 4;
}
int main(void)
{
LedPortInit();
void ButonPortInit();
void LedSwitch();
void ButtonTest();
}