ATmel studio, ASF compare, HAL vs HPL

There are few people talk about the structure of the atmel studio code set.

I look through the library and the document and give the following result.

http://www.microchip.com/avr-support/advanced-software-framework-(asf)
https://www.microchip.com/mplab/avr-support/advanced-software-framework

Click to access 50002633A.pdf

Advanced Software Framework(ASF) is the framwork used by Mircochip for Atmel product

ASF4 must be used in conjunction with Atmel START, which replaces the ASF Wizard of ASF3.

After configuring in the Atmel START, you can see a list of library inside the folder.

列出磁碟區 Windows 的資料夾 PATH
磁碟區序號為 EE0C-64C1
C:.
├─.atmel-start-backup
├─.atmelstart
├─Config
├─Debug
│ ├─Config
│ ├─Device_Startup
│ ├─examples
│ ├─hal
│ │ ├─include
│ │ ├─src
│ │ └─utils
│ │ ├─include
│ │ └─src
│ ├─hpl
│ │ ├─adc
│ │ ├─core
│ │ ├─dmac
│ │ ├─gclk
│ │ ├─mclk
│ │ ├─osc32kctrl
│ │ ├─oscctrl
│ │ ├─pm
│ │ ├─port
│ │ ├─rtc
│ │ ├─sercom
│ │ ├─systick
│ │ ├─tc
│ │ └─wdt
│ └─hri
├─Device_Startup
├─examples
├─hal
│ ├─include
│ ├─src
│ └─utils
│ ├─include
│ └─src
├─hpl
│ ├─adc
│ ├─core
│ ├─dmac
│ ├─gclk
│ ├─mclk
│ ├─osc32kctrl
│ ├─oscctrl
│ ├─pm
│ ├─port
│ ├─rtc
│ ├─sercom
│ ├─systick
│ ├─tc
│ └─wdt
└─hri

atmel_start_pins.h –> let you find the name of the pin and use it in the program –> \param[in] pin The pin number for device, (const uint8_t pin)

(if middleware is used, it will be the toppest model)
Three main word appear:
• Hardware Abstraction Layer – HAL
Naming convention: HAL functions start with usecase_, for example: adc_dma_driver

• Hardware Proxy Layer – HPL
Naming convention: HPL functions start with _usecase_, for example: _usart_async_init()

• Hardware Register Interface – HRI
accessing the register.

PS, in the utils, it has list, marco, ringbuffer for you to use

Sizeof() vs Strlen()

Sizeof()

#include<stdio.h>
int main()
{
    printf("%d\n",sizeof(char)); // output 1
    printf("%d\n",sizeof(int));  // output 4
    printf("%d\n",sizeof(float));// output 4
    printf("%d", sizeof(double));// output 8
    return 0;

Sizeof will return the size of the variable

#include<stdio.h>
int main()
{
   int arr[] = {1, 2, 3, 4, 7, 98, 0, 12, 35, 99, 14};
   printf("Number of elements :%d", sizeof(arr)/sizeof(arr[0]));
   return 0;
Number of elements :11

This is useful for getting the number of the elements of an array.

allocate memory dynamically – To allocate block of memory dynamically.

int *ptr = malloc(10*sizeof(int));

strlen()

size_t strlen(const char *str)

not include \0

//========compare

Since strlen() not inlclude \0

// C program to demonstrate difference 
// between strlen() and sizeof()
#include<stdio.h>
#include<string.h>
 
int main()
{
    char str[] = "November";
    printf("Length of String is %d\n", strlen(str));  //8
    printf("Size of String is %d\n", sizeof(str));    //9
}
#include <iostream>
#include <string.h>
using namespace std;
 
int main()
{
        char a[] = {"Geeks for"};
        char b[] = {'G','e','e','k','s',' ','f','o','r'}; //9 char total
        cout << "sizeof(a) = " << sizeof(a);
        cout << "\nstrlen(a) = "<< strlen(a);
        cout<<  "\nsizeof(b) = " << sizeof(b);
        cout<<  "\nstrlen(b) = " << strlen(b);
         
        return 0;
}

sizeof(a): 10 //include the NULL at the end

strlen(a): 9 // not include the NULL

sizeof(b): 9 // total 9 char ma

strlen(b):11 // abnormal

ref:

https://www.geeksforgeeks.org/sizeof-operator-c/

https://www.tutorialspoint.com/c_standard_library/c_function_strlen.htm

https://www.geeksforgeeks.org/difference-strlen-sizeof-string-c-reviewed/

memset()

void *memset(void *str, int c, size_t n)

memset use set the value be c at pointer str n times and return pointer str

str is a void pointer, so that you can pass in any type.

#include 
#include 

int main ()
{
   char str[50];

   strcpy(str,"Hello World");
   puts(str);

   memset(str,'$',2);
   puts(str);
   
   return(0);
}

Hello World
$$llo World

 

memset(str, 0, sizeof(str)); //Empty str

Data Type Transistion

char *  itoa ( int value, char * str, int base );

itoa() is not officially in compiler, some have that

You can make it official like that:

#inlcude  –> itoa

#include –> sprinf

  • sprintf(str,”%d”,value) converts to decimal base.
  • sprintf(str,”%x”,value) converts to hexadecimal base.
  • sprintf(str,”%o”,value) converts to octal base.
Example 

sprintf(disData,"%d %d %d %s %s %s %s %s %s %c",sound[0],sound[1],sound[2],ppm[0],ppm[1],ppm[2],c_pmDen,c_hum,c_temp,c_alarm);
Serial.println(disData);

//Turn all the data to disData as String!!

ref

http://www.cplusplus.com/reference/cstdio/