Skip to main content

Debug

Bool data type in AVRGCC, the AVRStudio IDE detects bool as a keyword but throws a compile error.
bool exists in the current ANSI C - C99, but not in C89/90.
In C99 the native type is actually called _Bool, while bool is a standard library macro defined in stdbool.h (which expectedly resolves to _Bool). Objects of type _Bool hold either 0 or 1, while true and false are also macros from stdbool.h.
AVR GCC User Defined Data Types
User types
C language allows defining user types. For this typedef keyword is used:
typedef unsigned char byte; //create byte type
typedef unsigned int word; //create word type
In other words defining custom types description structure is used:
typedef standard_type custom_type;
WinAVR compiler has predefined custom types:
typedef signed char int8_t; //located in header file inttypes.h
typedef unsigned char uint8_t; //located in header file inttypes.h
typedef int int16_t; //located in header file inttypes.h
typedef unsigned int uint16_t; //located in header file inttypes.h
typedef long int32_t; //located in header file inttypes.h
typedef unsigned long uint32_t; //located in header file inttypes.h
typedef long long int64_t; //located in header file inttypes.h
typedef unsigned long long uint64_t; //located in header file inttypes.h
typedef struct {int quot; int rem} div_t; //located in header file stdlib.h. It is used for standard function ldiv();


14th April
i was trying to copy some Aurduino libraries to AVRGCC , the functions digitalPinToPort(), digitalPinToPCMSK() are seems usefull but i guess these subroutines should be compile time only it will save both code space, CPU ticks and so the power consumption.
So can be these subroutines can be preprocessor subroutines only. well they have conditional statements in C like #if and #endif

18th April
Interrupt routines in C, there is no standard method defined for interrupts in the C99 standards.
for example PIC compilors use

static void interrupt isr(void)
  {
  if(T0IF)
    {
    Timer 0 interrupt;
    }

  if(TMR1IF)
    {
    Timer 1 interrupt;
    }
  if(CCP2IF)
    {
    Capture interrupt;
    }
  }

and avrgcc

#include <avr/interrupt.h>

ISR(ADC_vect)
{
    // user code here
}

In some circumstances, the compiler-generated prologue and epilogue of the ISR might not be optimal for the job, and a manually defined ISR could be considered particularly to speedup the interrupt handling.This can be done using the ISR_NAKED attribute to the ISR() macro. Note that the compiler does not generate anything as prologue or epilogue, so the final reti() must be provided by the actual implementation. SREG must be manually saved if the ISR code modifies it, and the compiler-implied assumption of __zero_reg__ always being 0 could be wrong (e. g. when interrupting right after of a MUL instruction).


ISR(TIMER1_OVF_vect, ISR_NAKED)
{
  PORTB |= _BV(0);  // results in SBI which does not affect SREG
  reti();
}




References:
IAR 

Comments

Popular posts from this blog

Questions

1. What is a Stub function? Ans : A function without any definition which presents no error when called. 2. Why there are two ld scripts generated by STM32Cube IDE? Ans: The CubeIDE always presents two different LDscripts on for generating the executable for Debugging which goes to RAM another for normal code upload that goes to flash memory. 3. What is Supervisory Mode/ privileged mode ? Ans : When you are using a Kernel then there are two modes user mode and privileged mode. In User mode the applications cant have system calls. 4. What is "make -j6" ? Ans : Make has an argument for number of jobs, so when you add -j6 it will create 6 different compiler instances, so that the systems could use multicore to the fullest.  Linux people generally do add "-j $(nproc)" where nproc is a command line which returns number of processors attached. 5. What is weak attribute ? Ans : Weak attribute used to denote weak symbols which helps linkers to choose one function out of mul...

#@$%

  #include  "msp430x21x2.h"     #define PWM_OUTPUT              0x03 #define DUTY_CYCLE              TA0CCR2 #define MAX_LIMIT               300   /* #define no_of_samples           1 #define duty_cycle_limit        1000 #define temp_sensor             0xA000   #define panel_selection_cutoff  250 */ #define PV_VOLTAGE              INCH_0 #define PV_CURRENT              INCH_1 #define BATT_VOLTAGE            INCH_2 #define BATT_CURRENT            INCH_3   #define UPPER_CRG_LVL           0x0105 // 0x00FF // 0x00F5 //0x023A #define LOWER_CRG_LVL   ...

Preparing for embedded systems interview

  Preparing for a technical interview in embedded systems involves a wide range of topics, as the field encompasses both hardware and software components. Here are some key areas and example questions that you might encounter in such an interview: Basic Concepts and Theory: What is an embedded system? Can you explain the difference between a microprocessor and a microcontroller? Describe the various types of memory in an embedded system. Programming and Software Design: 4. How do you write an interrupt service routine in C? 5. Explain the concept of a real-time operating system (RTOS). How does it differ from a general-purpose operating system? 6. What are the different states of a thread in an RTOS? Hardware and Interfacing : 7. How does SPI communication work? What about I2C communication? 8. Explain the concept of GPIO (General-Purpose Input/Output). How would you use it in an embedded application? 9. What are interrupts, and how are they handled in embedded systems? Low-Level P...