Last active
January 18, 2025 11:56
-
-
Save Irdroid/ff4fd9c7e01d908ca2e7da097394a437 to your computer and use it in GitHub Desktop.
Buffer Aliasing and splitting in C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
#include <stdio.h> | |
#define MAX_PACKET_SIZE 64 | |
// The main buffer we want to split alias | |
uint8_t EP2_buffer[128]; | |
//Creating aliases for the main buffer split into two, each 64 bytes | |
uint8_t * cdc_In_Buffer = (uint8_t *) EP2_buffer; | |
uint8_t * cdc_Out_Buffer = (uint8_t *) EP2_buffer+MAX_PACKET_SIZE; | |
int main(void){ | |
// Put some sample data | |
EP2_buffer[0] = 0; | |
EP2_buffer[63] = 1; | |
EP2_buffer[64] = 2; | |
EP2_buffer[127] = 3; | |
// Check if data is in its expected place | |
printf("Buffer A0 %x\n", cdc_In_Buffer[0]); | |
printf("Buffer A3 %x\n", cdc_In_Buffer[63]); | |
printf("Buffer B0 %x\n", cdc_Out_Buffer[0]); | |
printf("Buffer B63 %x\n", cdc_Out_Buffer[63]); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment