agileRTOS (zrtos)  Version 0.8.0 (ghostbuster)
atmega2560.h File Reference
#include <util/delay_basic.h>
Include dependency graph for atmega2560.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ZRTOS_ARCH__FOUND
 
#define ZRTOS_ARCH__BYTE_ORDER   ZRTOS_ARCH__BYTE_ORDER_LITTLE_ENDIAN
 
#define ZRTOS_ARCH__CPU_CLOCK_HZ   ( ( uint32_t ) F_CPU )
 
#define ZRTOS_ARCH__BYTE_ALIGNMENT   (1)
 
#define ZRTOS_ARCH__FATAL()   ((void(*)(void))0)();
 
#define ZRTOS_ARCH__SET_STACK_PTR(ptr)   (SP = (uint16_t)(ptr))
 
#define ZRTOS_ARCH__GET_STACK_PTR()   ((void*)SP)
 
#define ZRTOS_ARCH__IS_INTERRUPTS_DISABLED()   ((SREG & 0x80) == 0)
 
#define ZRTOS_ARCH__IS_INTERRUPTS_ENABLED()   ((SREG & 0x80) > 0)
 
#define ZRTOS_ARCH__DISABLE_INTERRUPTS()   asm volatile ( "cli" :: );
 
#define ZRTOS_ARCH__ENABLE_INTERRUPTS()   asm volatile ( "sei" :: );
 
#define zrtos_arch__cpu_state_init   zrtos_arch__cpu_state_init_a
 
#define ZRTOS_ARCH__GET_CPU_STATE_BUFFER_LENGTH()   33
 
#define ZRTOS_ARCH__GET_FN_CALL_STACK_LENGTH()   20
 
#define ZRTOS_ARCH__SAVE_CPU_STATE()
 
#define ZRTOS_ARCH__SAVE_CPU_STATE_EX(ptr)
 
#define ZRTOS_ARCH__LOAD_CPU_STATE()
 
#define ZRTOS_ARCH__LOAD_CPU_STATE_EX(ptr)
 
#define ZRTOS_ARCH__RETURN_FROM_INTERRUPT()   __asm__ __volatile__("reti");
 

Typedefs

typedef uint8_t zrtos_arch_stack_t
 
typedef int8_t zrtos_arch_stack_signed_t
 
typedef uint8_t zrtos_arch_gpio_pin_t
 
typedef uint16_t zrtos_arch_gpio_value_analog_t
 

Functions

zrtos_arch_stack_tzrtos_arch__cpu_state_init_helper (zrtos_arch_stack_t *pxTopOfStack, zrtos_arch_callback_t pxCode, void *pvParameters)
 
zrtos_arch_stack_tzrtos_arch__cpu_state_init_b (zrtos_arch_stack_t *thiz, zrtos_arch_callback_t callback, void *args)
 
zrtos_arch_stack_tzrtos_arch__cpu_state_init_a (zrtos_arch_stack_t *thiz, zrtos_arch_callback_t callback, void *args)
 
void zrtos_arch__delay_microseconds (uint16_t us)
 
void zrtos_arch__delay_milliseconds (uint16_t ms)
 

Macro Definition Documentation

◆ ZRTOS_ARCH__BYTE_ALIGNMENT

#define ZRTOS_ARCH__BYTE_ALIGNMENT   (1)

Definition at line 28 of file atmega2560.h.

◆ ZRTOS_ARCH__BYTE_ORDER

#define ZRTOS_ARCH__BYTE_ORDER   ZRTOS_ARCH__BYTE_ORDER_LITTLE_ENDIAN

Definition at line 24 of file atmega2560.h.

◆ ZRTOS_ARCH__CPU_CLOCK_HZ

#define ZRTOS_ARCH__CPU_CLOCK_HZ   ( ( uint32_t ) F_CPU )

Definition at line 26 of file atmega2560.h.

◆ zrtos_arch__cpu_state_init

#define zrtos_arch__cpu_state_init   zrtos_arch__cpu_state_init_a

Definition at line 187 of file atmega2560.h.

◆ ZRTOS_ARCH__DISABLE_INTERRUPTS

#define ZRTOS_ARCH__DISABLE_INTERRUPTS ( )    asm volatile ( "cli" :: );

Definition at line 44 of file atmega2560.h.

◆ ZRTOS_ARCH__ENABLE_INTERRUPTS

#define ZRTOS_ARCH__ENABLE_INTERRUPTS ( )    asm volatile ( "sei" :: );

Definition at line 47 of file atmega2560.h.

◆ ZRTOS_ARCH__FATAL

#define ZRTOS_ARCH__FATAL ( )    ((void(*)(void))0)();

Definition at line 30 of file atmega2560.h.

◆ ZRTOS_ARCH__FOUND

#define ZRTOS_ARCH__FOUND

Definition at line 15 of file atmega2560.h.

◆ ZRTOS_ARCH__GET_CPU_STATE_BUFFER_LENGTH

#define ZRTOS_ARCH__GET_CPU_STATE_BUFFER_LENGTH ( )    33

Definition at line 192 of file atmega2560.h.

◆ ZRTOS_ARCH__GET_FN_CALL_STACK_LENGTH

#define ZRTOS_ARCH__GET_FN_CALL_STACK_LENGTH ( )    20

Definition at line 193 of file atmega2560.h.

◆ ZRTOS_ARCH__GET_STACK_PTR

#define ZRTOS_ARCH__GET_STACK_PTR ( )    ((void*)SP)

Definition at line 35 of file atmega2560.h.

◆ ZRTOS_ARCH__IS_INTERRUPTS_DISABLED

#define ZRTOS_ARCH__IS_INTERRUPTS_DISABLED ( )    ((SREG & 0x80) == 0)

Definition at line 38 of file atmega2560.h.

◆ ZRTOS_ARCH__IS_INTERRUPTS_ENABLED

#define ZRTOS_ARCH__IS_INTERRUPTS_ENABLED ( )    ((SREG & 0x80) > 0)

Definition at line 41 of file atmega2560.h.

◆ ZRTOS_ARCH__LOAD_CPU_STATE

#define ZRTOS_ARCH__LOAD_CPU_STATE ( )

Definition at line 245 of file atmega2560.h.

◆ ZRTOS_ARCH__LOAD_CPU_STATE_EX

#define ZRTOS_ARCH__LOAD_CPU_STATE_EX (   ptr)
Value:
;__asm__ __volatile__( \
"lds __tmp_reg__, %0 \n\t" \
"out __SP_L__, __tmp_reg__ \n\t" \
"lds __tmp_reg__, %0 + 1 \n\t" \
"out __SP_H__, __tmp_reg__ \n\t" \
: : "m" (ptr) \
); \
ZRTOS_ARCH__LOAD_CPU_STATE();

Definition at line 283 of file atmega2560.h.

◆ ZRTOS_ARCH__RETURN_FROM_INTERRUPT

#define ZRTOS_ARCH__RETURN_FROM_INTERRUPT ( )    __asm__ __volatile__("reti");

Definition at line 293 of file atmega2560.h.

◆ ZRTOS_ARCH__SAVE_CPU_STATE

#define ZRTOS_ARCH__SAVE_CPU_STATE ( )

Definition at line 195 of file atmega2560.h.

◆ ZRTOS_ARCH__SAVE_CPU_STATE_EX

#define ZRTOS_ARCH__SAVE_CPU_STATE_EX (   ptr)
Value:
;__asm__ __volatile__( \
"in __tmp_reg__, __SP_L__ \n\t" \
"sts %0, __tmp_reg__ \n\t" \
"in __tmp_reg__, __SP_H__ \n\t" \
"sts %0 + 1, __tmp_reg__ \n\t" \
: "=m" (ptr) \
);
#define ZRTOS_ARCH__SAVE_CPU_STATE()
Definition: atmega2560.h:195

Definition at line 235 of file atmega2560.h.

◆ ZRTOS_ARCH__SET_STACK_PTR

#define ZRTOS_ARCH__SET_STACK_PTR (   ptr)    (SP = (uint16_t)(ptr))

Definition at line 32 of file atmega2560.h.

Typedef Documentation

◆ zrtos_arch_gpio_pin_t

Definition at line 21 of file atmega2560.h.

◆ zrtos_arch_gpio_value_analog_t

Definition at line 22 of file atmega2560.h.

◆ zrtos_arch_stack_signed_t

typedef int8_t zrtos_arch_stack_signed_t

Definition at line 20 of file atmega2560.h.

◆ zrtos_arch_stack_t

Definition at line 19 of file atmega2560.h.

Function Documentation

◆ zrtos_arch__cpu_state_init_a()

zrtos_arch_stack_t* zrtos_arch__cpu_state_init_a ( zrtos_arch_stack_t thiz,
zrtos_arch_callback_t  callback,
void *  args 
)

Definition at line 152 of file atmega2560.h.

157  {
158  zrtos_arch_stack_t *pxTopOfStack = thiz;
159  zrtos_arch_stack_t *pxTopOfStackTmp = pxTopOfStack;
160  uint16_t usAddress = (uint16_t)callback;
161  zrtos_arch_stack_signed_t usValue = 0;
162 
163  pxTopOfStack -= 3;
164 
165  for(;usValue < 32;){
166  /*if(usValue == 0x0A
167  || usValue == 0x1A
168  || usValue == 0x2A){
169  usValue+=6;
170  }*/
171  *pxTopOfStack-- = usValue++;
172  }
173 
174  pxTopOfStackTmp[0] = usAddress & 0x00ff;
175  pxTopOfStackTmp[-1] = (usAddress >> 8) & 0x00ff;
176  pxTopOfStackTmp[-2] = 0;
177  pxTopOfStackTmp[-3] = 0x80;//enable interrupts
178  pxTopOfStackTmp[-4] = 0;
179  usAddress = (uint16_t)args;
180  pxTopOfStackTmp[-27] = usAddress & 0x00ff;
181  pxTopOfStackTmp[-28] = (usAddress >> 8) & 0x00ff;
182 
183  return pxTopOfStack;
184 }
uint8_t zrtos_arch_stack_t
Definition: atmega2560.h:19
int8_t zrtos_arch_stack_signed_t
Definition: atmega2560.h:20

◆ zrtos_arch__cpu_state_init_b()

zrtos_arch_stack_t* zrtos_arch__cpu_state_init_b ( zrtos_arch_stack_t thiz,
zrtos_arch_callback_t  callback,
void *  args 
)

Definition at line 133 of file atmega2560.h.

138  {
139 /*
140  ZRTOS_DEBUG__CODE(
141  static uint8_t pattern = 0xF0;
142  memset(thiz,(int)(pattern++),length);
143  );
144 */
146  thiz
147  ,callback
148  ,args
149  );
150 }
zrtos_arch_stack_t * zrtos_arch__cpu_state_init_helper(zrtos_arch_stack_t *pxTopOfStack, zrtos_arch_callback_t pxCode, void *pvParameters)
Definition: atmega2560.h:51
Here is the call graph for this function:

◆ zrtos_arch__cpu_state_init_helper()

zrtos_arch_stack_t* zrtos_arch__cpu_state_init_helper ( zrtos_arch_stack_t pxTopOfStack,
zrtos_arch_callback_t  pxCode,
void *  pvParameters 
)

Definition at line 51 of file atmega2560.h.

54 {
55 uint16_t usAddress;
56 
57  /* Simulate how the stack would look after a call to vPortYield() generated by
58  * the compiler. */
59 
60  /* The start of the task code will be popped off the stack last, so place
61  * it on first. */
62  usAddress = ( uint16_t ) pxCode;
63  *pxTopOfStack = ( zrtos_arch_stack_t ) ( usAddress & ( uint16_t ) 0x00ff );
64  pxTopOfStack--;
65 
66  usAddress >>= 8;
67  *pxTopOfStack = ( zrtos_arch_stack_t ) ( usAddress & ( uint16_t ) 0x00ff );
68  pxTopOfStack--;
69 
70 #if defined(__AVR_3_BYTE_PC__)
71 
72  /* The AVR ATmega2560/ATmega2561 have 256KBytes of program memory and a 17-bit
73  * program counter. When a code address is stored on the stack, it takes 3 bytes
74  * instead of 2 for the other ATmega* chips.
75  *
76  * Store 0 as the top byte since we force all task routines to the bottom 128K
77  * of flash. We do this by using the .lowtext label in the linker script.
78  *
79  * In order to do this properly, we would need to get a full 3-byte pointer to
80  * pxCode. That requires a change to GCC. Not likely to happen any time soon.
81  */
82  *pxTopOfStack = 0;
83  pxTopOfStack--;
84 #endif
85 
86  /* Next simulate the stack as if after a call to portSAVE_CONTEXT().
87  * portSAVE_CONTEXT places the flags on the stack immediately after r0
88  * to ensure the interrupts get disabled as soon as possible, and so ensuring
89  * the stack use is minimal should a context switch interrupt occur. */
90  *pxTopOfStack = ( zrtos_arch_stack_t ) 0x00; /* R0 */
91  pxTopOfStack--;
92  *pxTopOfStack = 0x80;//enable interrupts
93  pxTopOfStack--;
94 
95 #if defined(__AVR_3_BYTE_PC__)
96 
97  /* If we have an ATmega256x, we are also saving the EIND register.
98  * We should default to 0.
99  */
100  *pxTopOfStack = ( zrtos_arch_stack_t ) 0x00; /* EIND */
101  pxTopOfStack--;
102 #endif
103 
104 #if defined(__AVR_HAVE_RAMPZ__)
105 
106  /* We are saving the RAMPZ register.
107  * We should default to 0.
108  */
109  *pxTopOfStack = ( zrtos_arch_stack_t ) 0x00; /* RAMPZ */
110  pxTopOfStack--;
111 #endif
112 
113  /* Now the remaining registers. The compiler expects R1 to be 0. */
114  *pxTopOfStack = ( zrtos_arch_stack_t ) 0x00; /* R1 */
115 
116  /* Leave R2 - R23 untouched */
117  pxTopOfStack -= 23;
118 
119  /* Place the parameter on the stack in the expected location. */
120  usAddress = ( uint16_t ) pvParameters;
121  *pxTopOfStack = ( zrtos_arch_stack_t ) ( usAddress & ( uint16_t ) 0x00ff );
122  pxTopOfStack--;
123 
124  usAddress >>= 8;
125  *pxTopOfStack = ( zrtos_arch_stack_t ) ( usAddress & ( uint16_t ) 0x00ff );
126 
127  /* Leave register R26 - R31 untouched */
128  pxTopOfStack -= 7;
129 
130  return pxTopOfStack;
131 }
uint8_t zrtos_arch_stack_t
Definition: atmega2560.h:19
Here is the caller graph for this function:

◆ zrtos_arch__delay_microseconds()

void zrtos_arch__delay_microseconds ( uint16_t  us)

Definition at line 296 of file atmega2560.h.

296  {
297  _delay_loop_2((ZRTOS_ARCH__CPU_CLOCK_HZ/4000000) * us);
298 }
#define ZRTOS_ARCH__CPU_CLOCK_HZ
Definition: atmega2560.h:26
Here is the caller graph for this function:

◆ zrtos_arch__delay_milliseconds()

void zrtos_arch__delay_milliseconds ( uint16_t  ms)

Definition at line 300 of file atmega2560.h.

300  {
301  while(ms--){
303  }
304 }
void zrtos_arch__delay_microseconds(uint16_t us)
Definition: atmega2560.h:296
Here is the call graph for this function:
Here is the caller graph for this function: