Gestion des entrées-sorties numériques avec arm-gcc :
// Blink code for Adafruit Playground Express (APE)
// APE chip is an samd21g18a
// APE LED is on PA17
#include <stdint.h>
// Some constants about PORT A
#define PORT_BASE 0x41004400
#define PORT_OFFSET(o) (*(volatile uint32_t *)(0x41004400+o))
#define PORTA_DIRSET PORT_OFFSET(0x08)
#define PORTA_OUTCLR PORT_OFFSET(0x14)
#define PORTA_OUTSET PORT_OFFSET(0x18)
// Some constants for the LED
#define LED_PIN 17
// Some constants for sleep function
#define STEPS_PER_CHUNK 10000
void my_sleep(unsigned int chunks){
unsigned int i,s;
for(s=0;s<chunks;s++){
for(i=0;i<STEPS_PER_CHUNK;i++){
// skip CPU cycle or any other statement(s) for making loop
// untouched by C compiler code optimizations
asm volatile ("nop");
}
}
}
// Initialisation of PORT A
void init_ports(void){
PORTA_DIRSET=(1<<LED_PIN); // no need for read/modify/write
PORTA_OUTCLR=(1<<LED_PIN); // idem
}
// Main function
int main(void) {
// Initialize ports
init_ports();
// Forever loop
while(1){
// Fire up LED
PORTA_OUTSET=(1<<LED_PIN); // no need for read/modify/write
// Wait for some time
my_sleep(10);
// Shut LED
PORTA_OUTCLR=(1<<LED_PIN); // no need for read/modify/write
// Wait again for some time
my_sleep(10);
}
return 0;
}