Lazuli
arch.c
Go to the documentation of this file.
1 /*
2  * SPDX-License-Identifier: GPL-3.0-only
3  * This file is part of Lazuli.
4  */
5 
17 #include <stdint.h>
18 
19 #include <Lazuli/common.h>
20 #include <Lazuli/config.h>
22 #include <Lazuli/sys/arch/arch.h>
23 
24 #include "avr_arch.h"
25 
26 void
28 {
29 #if LZ_CONFIG_ON_IDLE_SLEEP && \
30  ((LZ_CONFIG_AVR_SLEEP_WITH_IDLE_MODE + \
31  LZ_CONFIG_AVR_SLEEP_WITH_ADC_NOISE_REDUCTION_MODE + \
32  LZ_CONFIG_AVR_SLEEP_WITH_POWER_DOWN_MODE + \
33  LZ_CONFIG_AVR_SLEEP_WITH_POWER_SAVE_MODE + \
34  LZ_CONFIG_AVR_SLEEP_WITH_STANDBY_MODE + \
35  LZ_CONFIG_AVR_SLEEP_WITH_EXTENDED_STANDBY_MODE) > 1)
36 #error "Idle mode for architecture AVR must be unique."
37 #endif
38 
40  return;
41  }
42 
44  SMCR = 0x02;
46  SMCR = 0x04;
48  SMCR = 0x06;
50  SMCR = 0x0c;
52  SMCR = 0x0e;
53  } else {
54  /* Default value : LZ_CONFIG_AVR_SLEEP_WITH_IDLE_MODE */
55  SMCR = 0x00;
56  }
57 }
58 
59 void
61 {
63  cpu_sleep();
65 }
66 
67 /* TODO: Put that in a module */
68 void
70 {
72  return;
73  }
74 
75  /* Direction of the pin */
76  /* WARNING: This is very specific to the AVR ATmega328p. */
78  uint8_t,
81  uint8_t,
83 }
void Arch_InitIdleCpuMode(void)
Initialize idle CPU modes.
Definition: arch.c:27
const bool LZ_CONFIG_INSTRUMENT_CONTEXT_SWITCHES
When set, add instrumentation code to measure context switches.
#define DIRECT(X)
Define a direct read/write register at an absolute address.
Definition: common.h:206
ATmega328P registers.
const bool LZ_CONFIG_AVR_SLEEP_WITH_STANDBY_MODE
Enter "Standby Mode" when sleeping.
Include appropriate config file.
uint8_t LZ_CONFIG_AVR_INSTRUMENT_POSITION
The position in the port used for instrumentation on AVR machines.
#define SET_BITS(V, T, X)
Set the corresponding bits of X in the value V of type T.
Definition: common.h:143
#define SMCR
Sleep Mode Control Register.
Definition: registers.h:58
void Arch_CpuSleep(void)
Put the CPU to sleep according to the sleep settings.
Definition: arch.c:60
const bool LZ_CONFIG_AVR_SLEEP_WITH_ADC_NOISE_REDUCTION_MODE
Enter "ADC Noise Reduction Mode" when sleeping.
const bool LZ_CONFIG_AVR_SLEEP_WITH_EXTENDED_STANDBY_MODE
Enter "Extended Standby Mode" when sleeping.
void cpu_sleep(void)
Put the AVR CPU to sleep according to the sleep settings.
#define POSITION(X)
Define a constant bit at position X, starting from index 0.
Definition: common.h:174
void Arch_InitInstrumentation(void)
Initialize the context switch instrumentation.
Definition: arch.c:69
unsigned char uint8_t
Represents a unsigned integer type with width of exactly 8 bits.
Definition: stdint.h:89
#define CLEAR_BITS(V, T, X)
Clear the corresponding bits of X in the value V of type T.
Definition: common.h:156
Header file specific to the AVR arch module.
const bool LZ_CONFIG_AVR_SLEEP_WITH_POWER_DOWN_MODE
Enter "Power-down Mode" when sleeping.
Basic type definitions and useful macros.
Architecture Abstraction API.
uint16_t LZ_CONFIG_AVR_INSTRUMENT_PORT
The port used for instrumentation on AVR machines.
const bool LZ_CONFIG_ON_IDLE_SLEEP
When 1, put the CPU to sleep when it&#39;s idle.
const bool LZ_CONFIG_AVR_SLEEP_WITH_POWER_SAVE_MODE
Enter "Power-save Mode" when sleeping.