Classes | |
struct | miosix::Time |
Defines | |
#define | led_on() IOCLR0=(1<<31) |
#define | led_off() IOSET0=(1<<31) |
#define | sd_card_sense() (!(IOPIN0 & (1<<11))) |
#define | USB_status() (IOPIN0 & (1<<15)) |
#define | button_enter() (!(IOPIN0 & (1<<14))) |
#define | pin_0_set(x) { IOSET0=((x) & GPIO_0_MASK); } |
#define | pin_0_clr(x) { IOCLR0=((x) & GPIO_0_MASK); } |
#define | pin_0_read() (IOPIN0) |
#define | mode_0_out(x) { IODIR0 |= ((x) & GPIO_0_MASK); } |
#define | mode_0_in(x) { IODIR0 &= ((x) | (~GPIO_0_MASK)); } |
#define | pin_1_set(x) { IOSET1=(x); } |
#define | pin_1_clr(x) { IOCLR1=(x); } |
#define | pin_1_read() (IOPIN1) |
#define | mode_1_out(x) { IODIR1 |= (x); } |
#define | mode_1_in(x) { IODIR1 &= (x); } |
#define | nop() { asm volatile("nop"::); } |
Enumerations | |
enum | miosix::DayOfWeek { miosix::MON, miosix::TUE, miosix::WED, miosix::THU, miosix::FRI, miosix::SAT, miosix::SUN } |
Functions | |
Time | miosix::get_time () |
void | miosix::set_time (Time t) |
void | miosix::sleep (Time *t) |
void | miosix::shutdown () |
void | miosix::reboot () |
Miosix provides functions to access the hardware on the miosix board. This includes:
The LPC2138 microcontroller provides many onboard peripherals, like two 10 bit ADC, a DAC, I2C, SPI, an additional serial port (UART1), and an hardware timer (TIMER1). To write drivers to use these peripherals, please read the LPC2138 datasheet.
Some hardware resources, however, are used by the kernel, and must not be used by user code, to avoid conflicts. These are:
GPIO pin availability map
This map shows which GPIO pin are available to the user, and which pin have some hardware restriction.
Pin marked as gpio / JTAG are not available if using JTAG in circuit debugger. If you are unsure about what this means, simply avoid using these pins.
Pin marked as * have the restriction that cannot be driven low when the microcontroller is in RESET because they trigger special functions, for more info, read the LPC2138 datasheet. If you are unsure about what this means, simply avoid using these pins.
Pin marked as # are open drain, that is, cannot force a high level without the use of an external pull up resistor. For more info read LPC2138 datasheet. If you are unsure about what this means, simply avoid using theses pins.
All pin not listed here are not available to the user.
in or out refers to the default state of the pin at boot time.
p0.2 in # gpio
p0.3 in # gpio
p0.4 in gpio
p0.5 in gpio
p0.6 in gpio
p0.7 in gpio
p0.8 in gpio
p0.9 in gpio
p0.10 in gpio
p0.12 in gpio
p0.16 in gpio
p0.21 in gpio
p0.22 in gpio
p0.23 in gpio
p0.25 in gpio
p0.26 in gpio
p0.27 in gpio
p0.28 in gpio
p0.29 in gpio
p0.30 in gpio
p1.16 in gpio
p1.17 in gpio
p1.18 in gpio
p1.19 in gpio
p1.20 in * gpio
p1.21 in gpio
p1.22 in gpio
p1.23 in gpio
p1.24 in gpio
p1.25 in gpio
p1.26 in * gpio / JTAG
p1.27 in gpio / JTAG
p1.28 in gpio / JTAG
p1.29 in gpio / JTAG
p1.30 in gpio / JTAG
p1.31 in gpio / JTAG
#define button_enter | ( | ) | (!(IOPIN0 & (1<<14))) |
Polls the button on the miosix board
#define led_off | ( | ) | IOSET0=(1<<31) |
Turn off LED connected to P0.31
#define led_on | ( | ) | IOCLR0=(1<<31) |
Turn on LED connected to P0.31
#define mode_0_in | ( | x | ) | { IODIR0 &= ((x) | (~GPIO_0_MASK)); } |
Modify the state of one or more pin of port 0, so that they become input. Once the pin are input, you can read them using pin_0_read() Available pin are p0.2 p0.3 p0.4 p0.5 p0.6 p0.7 p0.8 p0.9 p0.10 p0.12 p0.16 p0.21 p0.22 p0.23 p0.25 p0.26 p0.27 p0.28 p0.29 p0.30. To change the state of a pin with number k, the k-th bit in the x variable must be set. Example: to set pin 4,7 and 8 as input use:
mode_0_in( (1<<4) | (1<<7) | (1<<8) );
x | unsigned int where bits to set as input are @ 1 |
#define mode_0_out | ( | x | ) | { IODIR0 |= ((x) & GPIO_0_MASK); } |
Modify the state of one or more pin of port 0, so that they become output. Once the pin are output, you can write to them using pin_0_set() and pin_0_clr() Available pin are p0.2 p0.3 p0.4 p0.5 p0.6 p0.7 p0.8 p0.9 p0.10 p0.12 p0.16 p0.21 p0.22 p0.23 p0.25 p0.26 p0.27 p0.28 p0.29 p0.30. To change the state of a pin with number k, the k-th bit in the x variable must be set. Example: to set pin 4,7 and 8 as output use:
mode_0_out( (1<<4) | (1<<7) | (1<<8) );
x | unsigned int where bits to set as output are @ 1 |
#define mode_1_in | ( | x | ) | { IODIR1 &= (x); } |
Modify the state of one or more pin of port 1, so that they become input. Once the pin are input, you can read them using pin_1_read() Available pin are in range from p0.16 to p0.31. To change the state of a pin with number k, the k-th bit in the x variable must be set. Example: to set pin 16 and 18 as input use:
mode_1_in( (1<<16) | (1<<18) );
x | unsigned int where bits to set as input are @ 1 |
#define mode_1_out | ( | x | ) | { IODIR1 |= (x); } |
Modify the state of one or more pin of port 1, so that they become output. Once the pin are output, you can write to them using pin_1_set() and pin_1_clr() Available pin are in range from p0.16 to p0.31. To change the state of a pin with number k, the k-th bit in the x variable must be set. Example: to set pin 16 and 18 as output use:
mode_1_out( (1<<16) | (1<<18) );
x | unsigned int where bits to set as output are @ 1 |
#define nop | ( | ) | { asm volatile("nop"::); } |
No operation instruction. Expands to an assembler "nop".
#define pin_0_clr | ( | x | ) | { IOCLR0=((x) & GPIO_0_MASK); } |
Clear one or more gpio pin of port 0. If the pin is selected as output, it will become low. Available pin are p0.2 p0.3 p0.4 p0.5 p0.6 p0.7 p0.8 p0.9 p0.10 p0.12 p0.16 p0.21 p0.22 p0.23 p0.25 p0.26 p0.27 p0.28 p0.29 p0.30. To clear a pin with number k, the k-th bit in the x variable must be set. Example: to clear pin 4,7 and 8 use:
pin_0_clr( (1<<4) | (1<<7) | (1<<8) );
x | unsigned int where bits to clear are @ 1 |
#define pin_0_read | ( | ) | (IOPIN0) |
Read one or more gpio pin of port 0. If the pin is selected as input, its value can be read. Available pin are p0.2 p0.3 p0.4 p0.5 p0.6 p0.7 p0.8 p0.9 p0.10 p0.12 p0.16 p0.21 p0.22 p0.23 p0.25 p0.26 p0.27 p0.28 p0.29 p0.30. If the pin with number k is high, the k-th bit in the x variable will be set. The value of pin selected as output and of non-gpio pins is unspecified. Example: to read pin 9 use:
if(pin_0_read() & (1<<9)) { pin 9 is high } else { pin 9 is low }
#define pin_0_set | ( | x | ) | { IOSET0=((x) & GPIO_0_MASK); } |
Set one or more gpio pin of port 0. If the pin is selected as output, it will become high. Available pin are p0.2 p0.3 p0.4 p0.5 p0.6 p0.7 p0.8 p0.9 p0.10 p0.12 p0.16 p0.21 p0.22 p0.23 p0.25 p0.26 p0.27 p0.28 p0.29 p0.30. To set a pin with number k, the k-th bit in the x variable must be set. Example: to set pin 4,7 and 8 use:
pin_0_set( (1<<4) | (1<<7) | (1<<8) );
x | unsigned int where bits to set are @ 1 |
#define pin_1_clr | ( | x | ) | { IOCLR1=(x); } |
Clear one or more gpio pin of port 1. If the pin is selected as output, it will become low. Available pin are in range from p0.16 to p0.31. To clear a pin with number k, the k-th bit in the x variable must be set. Example: to clear pin 16 and 18 use:
pin_1_clr( (1<<16) | (1<<18) );
x | unsigned int where bits to clear are @ 1 |
#define pin_1_read | ( | ) | (IOPIN1) |
Read one or more gpio pin of port 1. If the pin is selected as input, its value can be read. Available pin are in range from p0.16 to p0.31. If the pin with number k is high, the k-th bit in the x variable will be set. The value of pin selected as output and of non-gpio pins is unspecified. Example: to read pin 19 use:
if(pin_1_read() & (1<<19)) { pin 19 is high } else { pin 19 is low }
#define pin_1_set | ( | x | ) | { IOSET1=(x); } |
Set one or more gpio pin of port 1. If the pin is selected as output, it will become high. Available pin are in range from p0.16 to p0.31. To set a pin with number k, the k-th bit in the x variable must be set. Example: to set pin 16 and 18 use:
pin_1_set( (1<<16) | (1<<18) );
x | unsigned int where bits to set are @ 1 |
#define sd_card_sense | ( | ) | (!(IOPIN0 & (1<<11))) |
Polls the SD card sense GPIO
#define USB_status | ( | ) | (IOPIN0 & (1<<15)) |
enum miosix::DayOfWeek |
Day of week field in Time struct
Time miosix::get_time | ( | ) |
Read time from RTC
void miosix::reboot | ( | ) |
The difference between this function and miosix_private::system_reboot() is that this function disables filesystem (if enabled), serial port (if enabled) while miosix_private::system_reboot() does not do all these things. miosix_private::system_reboot() is designed to reboot the system when an unrecoverable error occurs, and is used primarily in kernel code, reboot() is designed to reboot the system in normal conditions.
This function does not return.
WARNING: close all files before using this function, since it unmounts the filesystem.
void miosix::set_time | ( | Time | t | ) |
Set current time
t | time that will be written into RTC |
void miosix::shutdown | ( | ) |
This function disables filesystem (if enabled), serial port (if enabled) and puts the processor in deep sleep mode.
Wakeup occurs when p0.14 goes low, but instead of sleep(), a new boot happens.
This function does not return.
WARNING: close all files before using this function, since it unmounts the filesystem.
When in shutdown mode, power consumption of the miosix board is reduced to ~ 150uA, however, true power consumption depends on what is connected to the GPIO pins. The user is responsible to put the devices connected to the GPIO pin in the minimal power consumption mode before calling shutdown(). Please note that to minimize power consumption all unused GPIO must be set as output high.
void miosix::sleep | ( | Time * | t | ) |
This function disables filesystem (if enabled), serial port (if enabled) and puts the processor in deep sleep mode. After wakeup, the original status of filesystem and serial port is restored.
If t is NULL, wakeup only occurs when p0.14 goes low. If t is a valid time, wakeup occurs when that time is reached OR when p0.14 goes low, whichever occurs first.
Note that time support is only enabled if WITH_RTC is #define'd in miosix_settings.h. If it is not defined, time will be ignored.
WARNING: close all files before using this function, since it unmounts the filesystem.
Note: if using the wakeup time, it must be at least 2 seconds after the moment where sleep() is called, otherwise wakeup will not occur.
When in sleep mode, power consumption of the miosix board is reduced to ~ 150uA, however, true power consumption depends on what is connected to the GPIO pins. The user is responsible to put the devices connected to the GPIO pin in the minimal power consumption mode before calling sleep(). Please note that to minimize power consumption all unused GPIO must be set as output high.
t | wakeup time, or NULL |