Latest Activity In Study Groups

Join Your Study Groups

VU Past Papers, MCQs and More

We non-commercial site working hard since 2009 to facilitate learning Read More. We can't keep up without your support. Donate.


Please discuss about the assignment 

regard 

thanks

 

Assignment No. 03
Semester: Fall 2016

CS609 – System Programming

 

 

Total Marks: 10

 

Due Date: 23/01/2017

 

Uploading instructions:

 

  • Your assignment must be in .c files name. (Any other formats like scan images, Word, PDF, bmp, Zip, etc will not be accepted).
  • Name your file with your ID (e.g. bc020200786).
  • No assignment will be accepted through email.
  • Lessons 23-30.

 

Rules for Marking:

 

It should be clear that your assignment will not get any credit if:

 

  • The assignment is submitted after due date.
  • The submitted assignment does not open, execute or file is corrupted.
  • Your assignment is copied from internet, handouts or from any other student

      (Strict disciplinary action will be taken in this case).

 

Assignment

 

Question 1                                                                                                                                              (10  Marks)

       

                                                                                                                                                            

Write a C program for setting up a slave DMA channel 1 to transfer 40 bytes by keeping the following points in mind.

 

  • Auto initialization should be off.
  • Channel 1 should be set up for read cycle in single transfer mode.

 

 

 

 

 

NOTE: Do not worry about the output and just concentrate on logic. There should be no error in your program. Do not put any query on MDB about this assignment, if you have any query then email at cs609@vu.edu.pk.

 

 

 

 

 

Deadline: Your assignment must be uploaded/submitted on or before 23rd January 2017.

 

 

Views: 3813

Attachments:

Replies to This Discussion

mujtba kya ye final solution hai?

is ko c language main likhna hai?

just idea

lo g chck it i thnk thk ha ye

Attachments:

Kia ye file thek hai?

no errors hy is maaa too  

CS 609 ASSIGNMENT 3 SOLUTION FALL 2016

unsigned int SPIRxBuffer[15] __attribute__((space(dma)));

void initDMA2()
{
unsigned int i;
for(i=0;i<15;i++)
{
SPIRxBuffer=0xDEED;
}

DMA2CON = 0x0800; // Null-Write, Continuous, Ping-Pong disabled, Post-Inc., Periph-RAM
DMA2CNT = 14; // Transfer 15 words at a time
DMA2REQ = 0x00A; // Select SPI1 as DMA request source

DMA2PAD = (volatile unsigned int) &SPI1BUF;
DMA2STA = __builtin_dmaoffset(SPIRxBuffer);

IFS1bits.DMA2IF = 0; // Clear the interrupt flag
IEC1bits.DMA2IE = 1; // Enable DMA interrupt
IPC6bits.DMA2IP = 6; // set DMA interrupt priority to 6
DMA2CONbits.CHEN = 1; // Enable DMA Channel
// DMA2REQbits.FORCE = 1; // Force First word after Enabling SPI

// Force First word after Enabling SPI
// DMA2REQbits.FORCE=1;
// while(DMA2REQbits.FORCE==1);
}

void configSPI()
{
// Configure SPI1CON register to the following
SPI1CON1bits.CKP=0;
SPI1CON1bits.CKE=1;
SPI1CON1bits.MODE16=1;
SPI1CON1bits.MSTEN=1;
SPI1CON1bits.SPRE=7;
SPI1CON1bits.PPRE=1;
SPI1CON1bits.DISSDO=0;
SPI1CON1bits.DISSCK = 0;


// ? Enable SPI module (SPI1STATbits.SPIEN=?)
SPI1STATbits.SPIEN=1;


// Force First word after Enabling SPI
DMA2REQbits.FORCE=1; 
while(DMA2REQbits.FORCE==1);
}

void __attribute__((__interrupt__, no_auto_psv)) _DMA2Interrupt(void)
{
getResultADS131E04(); // Here is where I read from the SPIRxBuffer, and it´s all ceros
IFS1bits.DMA2IF = 0; // Clear the DMA2 Interrupt Flag
}
HpC.99
// 1. Import "dma.h"
#include <dma.h>

// 2. Create a HardwareSPI object.
HardwareSPI spi(1);

// this function is the one that we are going to call
// when the transmission is complete (we have to check if 
// the transfer was successful or if it generated an error)
void DMAEvent(){

//we get the DMA event
dma_irq_cause event = dma_get_irq_cause(DMA1, DMA_CH3);

switch(event) {
//the event indicates that the transfer was successfully completed
case DMA_TRANSFER_COMPLETE:
//11. Disable DMA when we are done
dma_disable(DMA1,DMA_CH3);
SerialUSB.println("Done transfering");
break;
//the event indicates that there was an error transmitting
case DMA_TRANSFER_ERROR:
//11. Disable DMA when we are done
dma_disable(DMA1,DMA_CH3);
SerialUSB.println("Fail");
break;
}

}

void setup(){

// 3. Init the HardwareSPI object.
spi.begin(SPI_18MHZ, MSBFIRST, 0);

// 4. Initialize DMA.
dma_init(DMA1);

//5. Enable DMA to use SPI communication; both TX (output) and RX (input).
spi_tx_dma_enable(SPI1);
spi_rx_dma_enable(SPI1);

// create an array of bytes we want to send
byte bytesToSend[512];
//fill the array with data (put your own)
for(int i=0; i<512; i++) {
bytesToSend[i] = 0xFF;
}

// we create a buffer for revceiving the responses
byte bytesReceived[512];

// 6. Setup a DMA transfer (for both TX and RX). If we only want
// to read (RX) or write (TX) it is fine to just setup one. In this
// case we want to transfer (write and get a response) so we do both.
// Parameters:
// - DMA
// - DMA channel
// - Memory register for SPI
// - The size of the SPI memory register
// - The buffer we want to copy things to or transmit things from
// - The unit size of that buffer
// - Flags (see the Maple DMA Wiki page for more info in flags)
dma_setup_transfer(DMA1, DMA_CH2, &SPI1->regs->DR, DMA_SIZE_8BITS, 
bytesToSend, DMA_SIZE_8BITS, (DMA_MINC_MODE | DMA_TRNS_CMPLT | DMA_TRNS_ERR));
dma_setup_transfer(DMA1, DMA_CH3, &SPI1->regs->DR, DMA_SIZE_8BITS, 
bytesReceived, DMA_SIZE_8BITS,(DMA_MINC_MODE | DMA_CIRC_MODE | DMA_FROM_MEM));

// 7. Attach an interrupt to the transfer. Note that we need to add
// the interrupt flag in step 6 (DMA_TRNS_CMPLT and DMA_TRNS_ERR). 
// Also, we only attach it for one of the transfers since they are 
// going to finish at the same time because they are in sync.
dma_attach_interrupt(DMA1, DMA_CH2, DMAEvent);

//8. Setup the priority for the DMA transfer.
dma_set_priority(DMA1, DMA_CH2, DMA_PRIORITY_VERY_HIGH);
dma_set_priority(DMA1, DMA_CH3, DMA_PRIORITY_VERY_HIGH);

// 9. Setup the number of bytes that we are going to transfer.
dma_set_num_transfers(DMA1, DMA_CH2, 512);
dma_set_num_transfers(DMA1, DMA_CH3, 512);

// 10. Enable DMA to start transmitting. When the transmission 
// finishes the event will be triggered and we will jump to 
// function DMAEvent.
dma_enable(DMA1, DMA_CH2);
dma_enable(DMA1, DMA_CH3);

}

void loop(){
}
void __attribute__((__interrupt__, no_auto_psv)) _DMA2Interrupt(void)
{
static unsigned int bufferCount = 0; // Keep record of which buffer is being written

ADS131E04_nCS = 1; // set /CS to high
DMA2CONbits.CHEN = 0; // Disable DMA Channel (not sure about it)

if( bufferCount == 0 )
{
//getResultADS131E04_DMA( &SPIRxBufferA[0] );
}
else
{
//getResultADS131E04_DMA( &SPIRxBufferB[0] );
}

bufferCount ^= 1;
IFS1bits.DMA2IF = 0; // Clear the DMA2 Interrupt Flag
}
void __attribute__((__interrupt__, no_auto_psv))_INT1Interrupt(void) // interrupt for ADC Converter Data Ready
{

ADS131E04_nCS = 0; // set /CS to low
DMA2CONbits.CHEN = 1; // Enable DMA Channel
DMA2REQbits.FORCE = 1; // Force First word after Enabling SPI
while(DMA2REQbits.FORCE==1);

IFS1bits.INT1IF = 0;
}

#include
#include
char st[80];
unsigned long int temp;
unsigned int i;
unsigned int count=48;
void main (void)
{
temp=(unsigned long int)_DS;
temp = temp 4L; i = *((unsigned int *)(&temp)); temp = temp>>16L;
outportb (0x81,*((unsigned char *)(&temp)));
outportb(0x06,*(((unsigned char *)(&i))));
outportb(0x06,*(((unsigned char *)(&i))+1));
count--;
outportb(0x07,*((unsigned char *)(&count)));
outportb(0x07,*(((unsigned char*)(&count))+1));
outportb(0x0b,0x0b);
outportb(0x08,0);
outport(0x0a,3);
getch();
}

This program is to transfer 48 byte with channel 3.
Watch lecture no 24 and try to edit this program according to assignment requirements... Just little bit change is required..

koi mukamal solution be send kar do C main

RSS

© 2021   Created by + M.Tariq Malik.   Powered by

Promote Us  |  Report an Issue  |  Privacy Policy  |  Terms of Service