Lesson 03: PSoC Creator System Reference Guild - Data Types and APIs

PSoC Creator providers some useful APIs that can be used in your code.

  • Standard C data types (implicit sizes)
    Type Size
    Range Description Precision
    (Decimal place)
    printf() identifier
    char 1

    unsigned: 0 ... 255
    signed: -128 ... 127

    Character   %c
    short 2 unsigned: 0 ... 65535
    signed:-32,768 ... 32767
    Standard type specifying 2-byte integers   %i
    int 4 unsigned: 0 ... 4,294,967,295
    signed:-2,147,483,648 ... 2,147,483,647
    Integer number   %i
    long 4 unsigned: 0 ... 4,294,967,295
    signed:-2,147,483,648 ... 2,147,483,647
    float 4 1.175e-38 ... 3.40e+38 Signal presision floating point number 6 %f
    double 8 2.3E-308 ... 1.7E+308 Double presision floating point number 15 %f
    long double 8 2.3E-308 ... 1.7E+308     %f
    enum 1
    1 byte if enum < 256
    2 bytes if enum > 256  0 ... 65535
    Used to define a list of aliases that represent integers    
  • Cypress-defined data types
    Type Description
    char8 8-bit (signed or unsigned, depending on the compiler selection for char)
    uint8 8-bit unsigned integer
    uint16 16-bit unsigned integer
    uint32 32-bit unsigned integer
    int8 8-bit signed integer
    int16 16-bit signed integer
    int32 32-bit signed integer
  • Types available through <stdint.h>
    Type Description
    uint8_t 8-bit unsigned integer
    uint16_t 16-bit unsigned integer
    uint32_t 32-bit unsigned integer
    uint64_t 64-bit unsigned integer
    int8_t 8-bit signed integer
    int16_t 16-bit signed integer
    int32_t 32-bit signed integer
    int64_t 64-bit signed integer
  • Delay Functions
    Function Prototype Arguments Description
    void CyDelay(uint32 milliseconds) uint32 milliseconds
    Number of milliseconds to delay
    Delay by the specified number of milliseconds. Ex. To delay 2.5 second → CyDelay(2500);
    void CyDelayUs(uint32 microseconds) uint32 microseconds
    Number of microseconds to delay
    Delay by the specified number of microseconds. Ex. To delay 500 microsecond → CyDelayUs(500);
    void CyDelayFreq(uint32 freq) uint32 freq
    Bus clock frequency in Hz;
    0: Use default value
    Nonzero: Set freq value
    Sets the Bus Clock frequency used to calculate the number of cycles needed to implement a delay with CyDelay or CyDelayUs functions.
    By default, the frequency used is based on the value determined by PSoC Creator at build time.
    void CyDelayCycles(uint32 cycles) uint32 cycles
    Number of cycles to delay
    Delay by the specified number of cycles using a software delay loop
  • Macro statements
    CyGlobalIntEnable Enables interrupts using the global interrupt mask
    CyGlobalIntDisable Disable interrupts using the global interrupt mask

 Here, lists some useful defines:

/* ========================================
 * All Rights Reserved
 * WHICH IS THE PROPERTY OF your company.
 * ========================================
#ifndef MY_DEFINE_H
#define MY_DEFINE_H

#include  <stdint.h>
#include  <stdbool.h>
#include  <stdlib.h>
#include  <string.h>
#include  <math.h>

#define  HIGH           0x1
#define  LOW            0x0

#define  INPUT          0x0
#define  OUTPUT         0x1

#define  PI             3.1415926535897932384626433832795
#define  HALF_PI        1.5707963267948966192313216916398
#define  TWO_PI         6.283185307179586476925286766559
#define  DEG_TO_RAD     0.017453292519943295769236907684886
#define  RAD_TO_DEG     57.295779513082320876798154814105

#define  MIN(a,b)       ((a)<(b)?(a):(b))
#define  MAX(a,b)       ((a)>(b)?(a):(b))
#define  ABS(x)         ((x)>0?(x):-(x))
#define  CONSTRAIN(amt,low,high)  ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
#define  ROUND(x)       ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
#define  RADIANS(deg)   ((deg)*DEG_TO_RAD)
#define  DEGREES(rad)   ((rad)*RAD_TO_DEG)
#define  SQ(x)          ((x)*(x))

#define  LOWBYTE(w)     ((uint8_t) ((w) & 0xff))
#define  HIGHBYTE(w)    ((uint8_t) ((w) >> 8))

#define  BITREAD(value, bit)             (((value) >> (bit)) & 0x01)
#define  BITSET(value, bit)              ((value) |= (1UL << (bit)))
#define  BITCLEAR(value, bit)            ((value) &= ~(1UL << (bit)))
#define  BITWRITE(value, bit, bitvalue)  (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
#define  BIT(b)                          (1UL << (b))

typedef  unsigned  int  word;
typedef  uint8_t        byte;