[PDF] Pt - University of Texas at Austin





Previous PDF Next PDF



C Programming and Embedded Systems

Review. • Introduction to C. • Functions and Macros. • Separate Compilation. • Arrays. • Strings. • Pointers. • Structs and Unions 



C Programming and Embedded Systems

Introduction to C. • Functions and Macros. • Separate Compilation. • Arrays. • Strings. • Pointers. • Structs and Unions. • Advanced Pointers 



A TUTORIAL ON POINTERS AND ARRAYS IN C by Ted Jensen

After numerous requests I've finally come out with this PDF version which is identical to that HTML version cited above



C for Embedded Systems

Dec 15 2014 11.7.3 Function pointers as function argument . ... Code 6: example variables.c (code and screen output) . ... a construction manual.



C programming for embedded system applications

ELEC 3040/3050 Embedded Systems Lab (V. P. Nelson) Basic C program structure ... ((GPIO_TypeDef *) GPIOA_BASE) //Pointer to GPIOA register block.



Embedded C Coding Standard

By obtaining Barr Group's copyrighted “Embedded C Coding Standard” (the “Document”) To declare a pointer to a memory-mapped I/O peripheral.



Understanding and Using C Pointers

Media Inc. Understanding and Using C Pointers



EPI: Efficient Pointer Integrity for Securing Embedded Systems

2: A sample C application highlighting how EPI protects function pointers in memory. EETimes Embedded 2019 Embedded Markets Study.pdf.



Field-Sensitive Value Analysis of Embedded C Programs with Union

Jun 16 2006 merical static analyses to C programs containing union types



Function Pointers

Function Pointers. 15-123. Systems Skills in C and Unix Function pointer is “different” from other ... Function pointers can be passed as arguments.



Pt - University of Texas at Austin

Introduction to Embedded Microcomputer Systems Lecture 31 1 Jonathan W Valvano Use of stack for temporary calculations Pointers in C Linked List FIFO Linked structures FSM Trees short n; // value -32768 to +32767 short m; // value -32768 to +32767 short *p; // address 0x0000 to 0xFFFF char c; // value -128 to +127



What is an embedded pointer and what is it used for? - Quora

•Pointers of the same type can be assigned to each other –If not the same type a cast operator must be used –Exception: pointer to void(type void *) •Generic pointer represents any type •No casting needed to convert a pointer to voidpointer •voidpointers cannot be dereferenced 12



Pointers and Memory - Stanford University

Pointers and Memory By Nick ParlanteCopyright ©1998-2000 Nick Parlante Abstract This document explains how pointers and memory work and how to use them—from the basic concepts through all the major programming techniques For each topic there is a combination of discussion sample C code and drawings



C Review and Special Topics for Embedded Programming

Pointers • Every variable has an address in memory and a value • A pointer is a variable that stores an address – The value of a pointer is the location of another variable • The size of a pointer variable is the size of an address 15 – 4 bytes (32 bits) for the MPC5553 • Two operators used with pointers



C Programming and Embedded Systems - Department of Computer

•C allows us to allocate memory in which to store data during program execution •Dynamic memory has two primary applications: Dynamically allocating an array Based on some user input or file data Better than guessing and defining the array size in our code since it can’t be changed Dynamically allocating structs to hold data in



Searches related to pointers in embedded c pdf filetype:pdf

Section 1 Basic Types and Operators C provides a standard minimal set of basic data types Sometimes these are called "primitive" types More complex data structures can be built up from these basic types Integer Types The "integral" types in C form a family of integer types

What are embedded pointers?

    Embedded pointers are pointers that are embedded in data structures such as arrays, structures, and unions. When embedded pointers only write output to a buffer and are null on input, the server application can change their values to non-null.

How to use pointers in C?

    We must understand the use of two operators (& and *) for using pointers in C. The unary operator, &, is used for getting the address of the variable. If you use '&' before a variable name, it returns the address of that variable. For example, &y will return the address of the variable y.

What is a dangling pointer in embedded C?

    22) What is a dangling pointer in embedded C? A dangling pointer is a pointer that points to a memory location that has been already free-ed by the application and is no longer in use. Sometimes, the programmers fail to initialize the pointer with a valid address; these types of initialized pointers are known as dangling pointers.

What are pointers and how do they work?

    Pointers solve two common software problems. First, pointers allow different sections of code to share information easily. You can get the same effect by copying information back and forth, but pointers solve the problem better. Second, pointers enable complex "linked" data structures like linked lists and binary trees.
Introduction to Embedded Microcomputer Systems Lecture 31.1

Jonathan W. Valvano

Use of stack for temporary calculations

Pointers in C

Linked List

FIFO

Linked structures

FSM Trees short n; // value -32768 to +32767 short m; // value -32768 to +32767 short *p; // address 0x0000 to 0xFFFF char c; // value -128 to +127 char d; // value -128 to +127 char *s; // address 0x0000 to 0xFFFF char name[8] = "valvano";

Pointer assignments

p = &n; // p points to n s = &c; // s points to c

Pointer dereferencing

*p = 5000; // n = 5000 *s = 60; // c = 60 m = *p; // m = n (which is 5000) d = *s; // d = c (which is 60)

More pointer assignments

s = name; // s points to name or s = &name[0]; // s points to name

Fixed offset pointer dereferencing

c = *s; // c = 'V' d = s[1]; // d = 'a'

Static Linked list circular output pattern

Structure defines the format of each entry

Putting the const causes it to be stored in ROM

lots of ROM fixed values initialized when code burned into ROM

No const causes it to be stored in RAM

Just some RAM

variable values/pointers initialized at run time each time system is powered up must have an initialization copy in ROM const struct node { unsigned char data; // output value const struct State *next; // links typedef const struct node nodeType; nodeType *Pt;

Linked list definition

nodeType LL[4]={ {5, &LL[1]}, {6, &LL[2]}, {10,&LL[3]}, {9, &LL[0]}};

Pointer initialization

Pt = LL;

or Pt = &LL[0]; Pt56109 Introduction to Embedded Microcomputer Systems Lecture 31.2

Jonathan W. Valvano

Output all four values to port T

void OutputAll(void){ nodeType *p; p = Pt; do{

PTT = p->data; // fetch value from list

p = p->next; while(p != Pt);

Output one value to port T each interrupt

Pointer initialization

Pt = LL;

Execute ISR every 1 ms

void interrupt 8 OC0ISR(void){

PTT = Pt->data; // fetch value from list

Pt = Pt->next;

TC0 = TC0 + 1000; // 1000 means 1ms

TFLG1 = 0x01; // acknowledge

Stepper motor controller

Inputs: Go and Turn

Outputs: two 4-wire bipolar stepper motors

Bipolar stepper motor interface using an L293 driver // Port M bits 1-0 are inputs // =00 Stop // =10 Go (55,66,AA,99) // =01 RTurn(55,69,AA,96) // =11 LTurn(55,96,AA,69) // Port T bits 7-0 are outputs to steppers S55 $55 01S66 $66 01SAA $AA 01S99 $9901 00 0000 00 S69 $69S96 $9611 00 00 01 01

101010

10 1010

111111

1111
const struct State { unsigned char out; // command const struct State *next[4];}; typedef const struct State StateType;

StateType *Pt;

#define S55 &fsm[0] #define S66 &fsm[1] #define SAA &fsm[2] #define S99 &fsm[3] #define S69 &fsm[4] #define S96 &fsm[5]

6 8 1 2

PM1 PM0 P T 7 P T6 P T 5 P T 4 +5 10k G o

T u r n +5

10k

1 , 2 E N

3 , 4 E N

1 A 2 A 3 A 4 A +5 +51
9 2 7 1 0 1 5 + 5 1 6

4 5 1 2 1 3

+ 1 2 8 +12 +12 +12 +12 3 6 11 14 1 Y 2 Y 3 Y 4 Y

L 2 9 3 1

N4003

1 , 2 E N

3 , 4 E N

1 A 2 A 3 A 4 A +5 +5 1 9 2 7 1 0 1 5 + 5 1 6

4 5 1 2 1 3

+ 1 2 8 +12 +12 +12 +12 3 6 11 14 1 Y 2 Y 3 Y 4 Y

L 2 9 3 1

N4003 P T 3 P T 2 P T 1 P T 0 Introduction to Embedded Microcomputer Systems Lecture 31.3

Jonathan W. Valvano

StateType fsm[6]={

{0x55,{S55,S69,S66,S96}}, // S55 {0x66,{S66,SAA,SAA,S55}}, // S66 {0xAA,{SAA,S99,S99,S69}}, // SAA {0x99,{S99,SAA,S55,SAA}}, // S99 {0x69,{S69,SAA,S55,S55}}, // S69 {0x96,{S96,S55,SAA,SAA}}}; // S96 This stepper motor FSM has two input signals four outputs. void main(void){ unsigned char Input;

Timer_Init();

DDRT = 0x0ff;

DDRM = 0;

Pt = S55; // initial state

while(1){ // never quit

PTT = Pt->out; // stepper drivers

Timer_Wait(2000); // 0.25ms wait

Input = PTM&0x03;

Pt = Pt->next[Input];

Rewrite this to run in background

10.7. Multiple Access Circular Queues

source sink producer MACQ consumer put read used for data flow problems source to sink digital filters and digital controllers fixed length order preserving

MACQ is always full

source process (producer) places information into the MACQ oldest data is discarded when new data is entered sink process (consumer) can read any data

MACQ is not changed by the read operation.

v[0] v[1] v[2] v[3]

MACQ after

v[0] v[1] v[2] v[3]

MACQ before

lostnew Figure 10.7. A multiple access circular queue stores the most recent set of measurements.

Perform a 60Hz notch filter on a measured signal.

v[0] v[1] v[2] and v[3] are the most recent data sampled at 360 Hz. Introduction to Embedded Microcomputer Systems Lecture 31.4

Jonathan W. Valvano

gain

60Hz001

120Hz
frequency180Hz filtered output = 2

3][vv[0]

unsigned char v[4]; unsigned char samp(void){ v[3] = v[2]; v[2] = v[1]; v[1] = v[0]; v[0] = Ad_In(2); return (v[0]+v[3])/2; } org $0800 v rmb 4 org $F000 samp movb v+2,v+3 movb v+1,v+2 movb v,v+1 ldaa #2 jsr AD_In staa v adda v+3 9-bit rora (v[0]+v[3])/2 rts

10.9. Trees

graphacyclic graphtree Figure 10.11. Graphs and trees have nodes and are linked with pointers. Root

Lists with

0,1,2,... linksArbitary Tree

info

Binary Tree

Root

Lists with exactly 2 links

nullnullinfo info info nullinfo nullnullinfo nullinfo info info infoinfoinfo

Figure 10.12. A tree can be constructed with only down arrows, and there is a unique path to each node.

Introduction to Embedded Microcomputer Systems Lecture 31.5

Jonathan W. Valvano

Root

Lists with exactly 2 links

nullnullS FV nullT nullnullA null

Figure 10.13. A binary tree is constructed so that earlier elements are to the left and later ones to the right.

Value equ 0 name of the node

Data equ 1 data for this node

Left equ 2 pointer to son

Right equ 4 pointer to son

ROOT fdb WS Pointer to top

NULL equ 0 undefined address

WS fcb 'S',1 name,data

fdb WF Left son fdb WV Right son

WV fcb 'V',2 name,data

fdb WT WT is a left son fdb NULL no right son

WT fcb 'T',3 name,data

fdb NULL no children fdb NULL no right son

WF fcb 'F',4 name,data

fdb WA WA is a left son fdb NULL no right son

WA fcb 'A',5 name,data

fdb NULL no children fdb NULL #define NULL 0 const struct Node{ unsigned char Value; unsigned char Data; const struct Node *Left; const struct Node *Right;}; typedef const struct Node NodeType; typedef NodeType * NodePtr; #define Root WS #define WS &Tree[0] #define WV &Tree[1] #define WT &Tree[2] #define WF &Tree[3] #define WA &Tree[4]

NodeType Tree[5]={

{ 'S',1, WF, WV}, { 'V',2, WT, NULL}, { 'T',3, NULL, NULL}, { 'F',4, WA, NULL}, { 'A',5, NULL, NULL}}; Program 10.20. Definition of a simple binary tree. *Inputs: Reg A = look up letter *Outputs: Reg A=0 if not found, * =data if found

Look ldx Root current word

loop cpx #NULL beq fail cmpa Value,x Match beq found Skip if found blo golft ldx Right,x letter>value bra loop golft ldx Left,x letterNodePtr pt = Root; /* top */ while(pt!=NULL){ // done if null if(pt->Value == letter){ return(pt->Data); /* good */ if(pt->Value < letter){ pt = pt->Right; else{ pt = pt->Left; return NULL; /* not in tree */

Program 10.21. Binary tree search functions.

Introduction to Embedded Microcomputer Systems Lecture 31.6

Jonathan W. Valvano

In order to add and remove nodes at run time

tree must be defined in RAM. first search for the word (the search should fail), change the null pointer to point to the new list. * Inputs : Reg Y => new word to be added * new word is already in memory formatted * fcb 'J',6 * fdb NULL * fdb NULL NEW ldaa 0,Y Reg A is the name of the new word bsr LOOK tsta bne ok skip if already defined sty 0,X Update link

OK rts

Program 10.22. Program to add a node to a binary tree. Figure 10.14 shows the binary tree as the nodes J, U, G are added to the dictionary. null FV T A null S null nullnull null null FV T A null S nullnull null nullJ null

Initial TreeAdd J

null FV T A null S null null nullJ null Add U nullU null null FV T A null S null null nullJ Add G nullU null nullG null Figure 10.14. Nodes are added to a binary tree such that the alphabetical order is maintained. The search time for a binary tree increases as the log

2 of the size of the dictionary.

Expression evaluation

Polish notation is a prefix notation used in logic and arithmetic operations. The Polish logician Jan ukasiewicz

invented this notation around 1920 in order to simplify sentential logic. The following expression: * 2 3 evaluates to 6. This more complex expression: * + 1 2 + 3 4 can sometimes be written as (* (+ 1 2) (+ 3 4)) and evaluates to 21. Lisp s-expressions employ Polish notation.

Reverse Polish notation (RPN) is a postfix notation, invented by Australian philosopher and computer scientist

Charles Hamblin in the mid-1950s. Edsger Dijkstra invented the "shunting yard" algorithm, which converts from

infix notation to RPN.

Reverse Polish Notation

Introduction to Embedded Microcomputer Systems Lecture 31.7

Jonathan W. Valvano

numbers are pushed on the stack, values of the variables are pushed on the stack, unary function: input popped and result pushed, binary function: both inputs popped and result pushed.

Regular expression Reverse Polish Notation

3*M+N 3 M * N +

~(M|(N&P)) N P & M | ~

M*(5+P)-N/10 M 5 P + * N 10 / -

w-x+y+z-4 w x - y + z + 4 -

Table 8.4. Examples of Reverse Polish Notation.

P=(M+2)*(5+P)+3*N M 2 + 5 P + * 3 N * +

org $0800 dataStack rmb 10

P rmb 1

M rmb 1

N rmb 1

org $4000 calc ldy #dataStack+10 movb M,1,-y movb #2,1,-y jsr Add movb #5,1,-y movb P,1,-y jsr Add jsr Mult movb #3,1,-y movb N,1,-y jsr Mult jsr Add movb 1,y+,P rtsquotesdbs_dbs22.pdfusesText_28
[PDF] points d'inflexion anglais

[PDF] points of the treaty of versailles

[PDF] pokemon ruby guide book

[PDF] pokemon ruby guide book pdf

[PDF] poland schengen visa appointment dublin

[PDF] pole barn kits

[PDF] pole barn plans

[PDF] pole barn prices

[PDF] police and private security partnerships

[PDF] police api

[PDF] police application form examples

[PDF] police application process

[PDF] police authority and power

[PDF] police body search procedures

[PDF] police cars automatically scan license plates