Newbie looking for advice on odd behavior with pointer.
Posted by
basilean on January 9, 2016
Hello community,
First, I want to thank you for this great proyect, I found it specially good to learning c, embebed and OS in just one shoot. I started coding this week, I’m not sure if my approach is the right one but besides that when I’m trying to move it forward I’m finding an error that is driving me nuts.
I’m on linux, using avr-gcc 4.8.1, an arduino duemillenova (at328p) and heap1, tacking serial example as starting point.
Going to code itself, it is working fine as expected, when I un-coment that two lines at “MESSAGE[]”, I compile and load program as before, just that task “Pwm1” stop works while “Pwm2” still does fine. I can check Pwm1 switches and runs (printing that commented chars by uart) but it does’t set pins.
I would appreciate any advice regarding this issue and whatever other you can share about my code, I’m self learning so any insight would be gladly welcome.
Thank you.
Andres.-
~~~~
include “FreeRTOS.h”
include “task.h”
include “uart/uart.h”
static const char *MESSAGE[] =
{
“CMD not found.”,
// “PWM Not Found.”,
// “PWM Updated.”
};
typedef union {
uint32t u32;
uint8t u8[4];
} msg_t;
typedef struct {
uint8t com;
uint8t bit;
volatile uint8t *port;
volatile uint8t *reg;
volatile uint8_t *ocr;
uint8_t vol;
} pwmio_t;
typedef struct {
TaskHandlet h;
volatile uint8t *tccra;
uint8_t tcaset;
volatile uint8_t *tccrb;
uint8_t tcbset;
pwmio_t pin[2];
} pwm_t;
typedef pwmt *ppwmt;
typedef struct {
pwmt pwm[4];
} fumenbott;
static fumenbot_t fumenbot = {
{
{
NULL, &TCCR0A, ((1 << WGM01) | (1 << WGM00)), &TCCR0B, (1 << CS01),
{
{COM0A1, PORTD5, &PORTD, &DDRD, &OCR0A, 255},
{COM0B1, PORTD6, &PORTD, &DDRD, &OCR0B, 255}
}
},
{
NULL, &TCCR2A, ((1 << WGM21) | (1 << WGM20)), &TCCR2B, (1 << CS21),
{
{COM2A1, PORTB3, &PORTB, &DDRB, &OCR2A, 255},
{COM2B1, PORTD3, &PORTD, &DDRD, &OCR2B, 255}
}
}
}
};
static uint8t FUMENBOTPWM = 2;
void vUart(void *pvParameters);
static TaskHandle_t xUart0 = NULL;
void vPwm(void *pvParameters);
void vApplicationStackOverflowHook(TaskHandlet xTask, signed char *pcTaskName);
void vApplicationStackOverflowHook(TaskHandlet xTask, signed char *pcTaskName) {
uart0_puts((const char *)pcTaskName);
}
char *fumenbot_handler(char *in);
char *fumenbot_handler(char *in)
{
char **out;
char a = in[0];
msg_t pkt;
pkt.u8[0] = in[1] – ‘0’;
pkt.u8[1] = in[2] – ‘0’;
pkt.u8[2] = in[3] – ‘0’;
pkt.u8[3] = in[4] – ‘0’;
if (a == ‘p’) {
if (pkt.u8[0] >= FUMENBOT_PWM) {
out = (char **)MESSAGE[1];
}
else {
xTaskNotify(fumenbot.pwm[pkt.u8[0]].h, pkt.u32, eSetValueWithOverwrite);
out = (char **)MESSAGE[2];
}
}
else {
out = (char **)MESSAGE[0];
}
return (char *)out;
}
define UARTBAUDRATE 19200
char uart0buffer[16];
uint8t uart0bufferidx = 0;
void vUart(void pvParameters) {
uart0_puts(“Fumenbot v0.7nr”);
for(;;) {
if(uart0_available()) {
char c = uart0_getc();
if(c == ‘r’) {
uart0_puts(“nr”);
uart0_puts(fumenbot_handler((char)uart0buffer));
uart0bufferidx = 0;
uint8t i;
for(i=0; i<16; i++) {
uart0buffer[i] = ‘