AnsweredAssumed Answered

Demonstrating "call-back concept" in CCES

Question asked by MikeSmithCanada on Oct 28, 2013
Latest reply on Nov 18, 2013 by MikeP

Hi

 

I am trying to demonstrate the concept of a call-back function in C++ in CCES

 

I am seitting up the interrupt as a void func(void)

and can get the pointer code working

void (*p2Function) void =  &IamISR;

 

I can set up a pointer to the IVTMR address in EVB

if I use volatile int ( syntax -- but then I have to cast the function pointer to an int

 

I can't persuade the pIVTMR address to point to a void function pointer.  Any idea of the correct syntax?

 

Question 2 -- Does CCES support some form of Ssync( ) function without me having to switch into assembly code to do it

 

Thanks

Mike

#include <blackfin.h>

#include <stdio.h>

#define SSYNC() asm("ssync;")     // Is there not a CCES-defined  C++ call that does this?

 

volatile unsigned int countISR = 0;

 

// Will discuss in class why most CallBack are of the form void CallBack(void *)

void CallBack(void) {

    countISR++;

    SSYNC();

}

 

#pragma interrupt;

void IamISR(void) {

    *pTCNTL &= 0x7;          // The idea is show impact of using pragma inline

    SSYNC();

    CallBack( );

}

 

int main(void)

{

    *pTCNTL = 0;

    *pTCOUNT = 0x400000;

    *pTPERIOD = 0x400000;

    *pTSCALE = 0;

    SSYNC();

 

    void (*pt2Function)(void) = NULL;   // Declaring a function pointer

    pt2Function = &IamISR;               // And pointing to ISR

 

// Since CCES does not have the equivalent of register_handler

//    and I wanted to expose what is happening inside a ISR handler

//    with Callback function, I had to define the equivalent

 

// However, I wanted pIVTMR to be defined to point to a void (*pt2Function)(void)

// but I could not find the correct syntax to define a void * pointer to access MMR

// and use the same pointer to point to void (*pt2Function)(void)

 

    volatile int *pIVTMR =  (volatile int *) ( 0xFFE02018);

    *pIVTMR = (int) pt2Function;

 

    countISR = 0;

 

    *pIMASK |= 0x40;

    *pTCNTL = 7;

    SSYNC();

 

    printf("Starting\n");

    while (countISR< 8) /* Do nothing */ ;

 

    printf("Done\n");

    *pTCNTL = 0;

    SSYNC();

 

    return 0;

}

Outcomes